Skip to content

Clarification: diagnostic ranges #257

Open

Description

VSCode supports a few diagnostic ranges that aren't documented in the LSP spec:

  • If a diagnostic's range has start and end position the same, then VSCode will squiggle the word at that position.
  • If a diagnostic's range has end position at character Number.MAX_VALUE, then VSCode will squiggle to the end of the line.

I think the LSP spec should call out these two cases, so that other clients implementing it will be sure to do the same.

Activity

  1. added this to the Next milestone on Jun 15, 2017
  2. dbaeumer commented on Jun 15, 2017

    @dbaeumer
    Member

    Good catch.

  3. rcjsuen commented on May 30, 2018

    @rcjsuen
    Contributor

    Looks like this has caused 535165 in LSP4E.

  4. mickaelistria commented on May 30, 2018

    @mickaelistria

    I don't think it's necessary to specify anything here. It's fine to get each client dealing with it as they prefer, and the best thing when this occur is to report issues to the LS that produce such ranges to get something more explicit.

  5. floitsch commented on May 27, 2019

    @floitsch

    There are at least two clients now that don't deal nicely with these ranges. (intellij and codemirror)

    Some language servers thus don't work nicely for all clients. (Admittedly, these servers don't follow the spec, but it should be reasonable to assume that the server is doing ok, when it works with some clients).

    Would be nice if the spec got updated.

  6. puremourning commented on May 27, 2019

    @puremourning

    What VScode does is irrelevance to the protocol. I think the protocol should stay as is and any server doing any thing else declared nonconformist

  7. Aerijo commented on May 27, 2019

    @Aerijo

    If a diagnostic's range has start and end position the same, then VSCode will squiggle the word at that position.

    I don't like the client interpreting special ranges in general, but this is especially weird. How does the client know the range of a "word"? I know the client might have something like a "word regex" defined, but this is an approximation at best. Isn't the whole point of the language server to understand the language, and handle things like knowing word boundaries, etc.

  8. puremourning commented on May 27, 2019

    @puremourning

    it should be reasonable to assume that the server is doing ok, when it works with some clients

    I don't agree at all. As a client implementer, what choice do I have but to implement the specification. If VSCode is the "de facto" specification, then why have LSP at all? I mean sure, I get that there is a certain bias towards testing with that client for obvious reasons, but I think server authors should implement the specification and lobby for changes to the specification (or the client) where there is a deviation in the client implementation they test with.

  9. kdvolder commented on May 27, 2019

    @kdvolder

    I don't like the client interpreting special ranges in general

    How would you show a range of length 0? If you underline or highlight something that has no length then the underline will have 0 length and that means you cannot see it.

    I don't think the protocol should specify exactly how a client should visualize problem markers. These kinds of visuals depend on the specific client. To me vscode highlighting a word is a reasonable choice on how to visualize a 0 length range. It is better than drawing nothing at all (make it 'invisible'). Other choice could be to try and highlight the character before or after the range instead. Though it may still be hard to see.

    Anyhoo... I think there is nothing wrong with leaving this sort of decision up to the client. I wouldn't mind seeing some words added to the spec to encourage/advise clients should try their best to show markers in some way that the user can actually see them, especial for cases where the range is of length 0.

  10. Aerijo commented on May 27, 2019

    @Aerijo

    How would you show a range of length 0?

    However best works for my client.

    But it seems you agree with me; this should not be specced by the LSP. How a client wants to show the declared lints is irrelevant to the communication between client and server. If the server really did mean the problem was with the nearest word, then it should have returned that range in the first place. Otherwise, it's just a matter of how the client displays zero width lints.

    Sure, the spec should note zero width lints are possible. I also think it should discourage servers from using them unless absolutely necessary though.

  11. kdvolder commented on May 28, 2019

    @kdvolder

    But it seems you agree with me

    Yes, I think so. I didn't think so at first as you seemed to be objecting to vscode deciding to extend the range of a zero-length range to a 'word'. But yes, I agree, this should not be specced. Clients should be free to decide what is the best way to visualize problem markers. And to me this includes choices like what vscode is doing to extend the range of a 0 length range. Other clients should be free to do the same... or not (and then they can find some other way to visualize a 0 length range instead).

  12. ljw1004 commented on Mar 31, 2021

    @ljw1004
    ContributorAuthor

    There's a legitimate scenario of an underlying third-party language service which reports line-numbers but doesn't report column numbers. What should an LSP adapter do for that language service?

    • Rely on undocumented VSCode behavior, specify start-character=0, end-character=Number.MAX_VALUE, and get a whole-line squiggle (desired) in VSCode, and get undefined behavior in other clients?
    • Specify start-character=0, end-character=1, and get an imperceptible squiggle in most clients?
    • Parse the file itself into a line-number map, solely to establish the length of each line, and use this to synthesize a diagnosticRange with the appropriate start and end character?

    I think LSP should be updated to support a whole-line diagnostic without requiring the LSP adapter to explicitly convey the length of the line in characters. It'd be easiest to do this by just enshrining VSCode's behavior "Number.MAX_VALUE" as a documented part of the LSP spec, and asking other clients to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions