TypeFox / yang-lsp

A Language Server for YANG
http://www.yang-central.org
Apache License 2.0
51 stars 13 forks source link

`IValidatorExtension` based `Issue` manifests with wrong context over LSP #244

Open esmasth opened 2 months ago

esmasth commented 2 months ago

Issues created within yang-lsp source have a precise context of start and end within LSP diagnostics, whereas Issues created within extensions only retain context of start but not the end which defaults(?) to [0,0] i.e., Line 1 Col 1, and eventually start and stop are swapped resulting in a misleading context of the issues.

Example extension for trial

package my.pack

import io.typefox.yang.validation.IValidatorExtension
import io.typefox.yang.validation.IssueFactory
import io.typefox.yang.yang.AbstractModule
import io.typefox.yang.yang.YangPackage
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.util.IAcceptor
import org.eclipse.xtext.validation.Issue

class MyExampleValidator implements IValidatorExtension {

    override validate(AbstractModule module, IAcceptor<Issue> issueAcceptor, CancelIndicator cancelIndicator) {
        if (module.getName().equals("foo")) {
            issueAcceptor.accept(IssueFactory.createIssue(module,
                                                          YangPackage.Literals.ABSTRACT_MODULE__NAME,
                                                          "'foo' is a bad name", "bad_name"))
        }
    }

}

Verbose trace excerpt from YANG Language server - foo.log

Manifestation of the issue in VS Code Yangster extension

image image

In the example above precisely foo is expected to be underlined

The editor user experience is degraded to a large extent, specially if an Issue pertaining to a context towards the end of a YANG file which ends up underlining from the start of the file till what is actually the start of the issue context. This further gets complicated when there are multiple issues raised via extensions since a list of issues are presented in the context that precedes the actual errors.

esmasth commented 3 weeks ago

@dhuebner any idea on this issue?

dhuebner commented 3 weeks ago

@esmasth Hard to tell from only seeing the logs, need to investigate and debug.