Skip to content

LSP integration: inconsistent handling of goto-definition for selected text #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DavidGoldman opened this issue Mar 16, 2020 · 18 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@DavidGoldman
Copy link

  • VSCode Version: 1.43.0
  • OS Version: macOS Catalina 1.15.3

Triggering goto-definition on selected (e.g. to copy) text depends upon how the text itself was selected.

This is because the goto definition request uses a different text position depending upon the end point of the selection. For a fix, I think it should always use the beginning of the selection as judged by earlier file offset.

Steps to Reproduce:

  1. Use any LSP that's available within VSCode. For my example, I'll be using https://github.com/apple/sourcekit-lsp on itself
  2. I'll be using the text here:

extension BuildServerBuildSystem: BuildSystem {

Examples:

  1. extension BuildServerBuildSystem: BuildSystem {
    --------------------- ^
    ----------- double click to select
    Goto-definition doesn't work (VSCode appears to send the position at char :)

  2. extension BuildServerBuildSystem: BuildSystem {
    ------------ ^------------------------^
    ------------start------------------- end
    Goto-definition doesn't work (VSCode appears to send the position at char :)

  3. extension BuildServerBuildSystem: BuildSystem {
    ------------ ^------------------------^
    ------------end------------------- start
    Goto-definition does work (VSCode appears to send the position at char )

For these cases VSCode should also send the position at char before the selection

@DavidGoldman
Copy link
Author

From Selection this might to be due to getPosition() returning the ending column + line.

There's also SingleCursorState which references cursor information but I'm not sure how that is used

@dbaeumer
Copy link
Member

Actually this needs to be addressed in the LSP libs since LSP doesn't have the concept of a selection direction.

@dbaeumer dbaeumer transferred this issue from microsoft/vscode Mar 18, 2020
@dbaeumer dbaeumer added the bug Issue identified by VS Code Team member as probable bug label Mar 18, 2020
@dbaeumer dbaeumer added this to the 3.16 milestone Mar 18, 2020
@DavidGoldman
Copy link
Author

In the meantime a potential fix would be to use the initial position, but long term that makes sense

@dbaeumer
Copy link
Member

I looked at the VS Code API again and it looks like VS Code only passes a position.

@jrieken can you comment on what the expected behavior here should be in terms of selection and goto definition. Thanks!

@jrieken
Copy link
Member

jrieken commented Mar 19, 2020

Every selection has an active position (can be the start or end of the selection) which is the position of the cursor. For all language features we use that, not the selection

@dbaeumer
Copy link
Member

Looks like there is nothing LSP can do about it.

@DavidGoldman in which language are you seeing this?

@dbaeumer dbaeumer added info-needed Issue requires more information from poster and removed bug Issue identified by VS Code Team member as probable bug labels Mar 20, 2020
@dbaeumer dbaeumer removed this from the 3.16 milestone Mar 20, 2020
@DavidGoldman
Copy link
Author

I was seeing this with Swift (SourceKit-LSP) but it should be reproducible in other LSPs as well. I recommend a fix of using the start of the selection to make this more consistent, especially since when double clicking to select it will default to the error case (see my example in the first post)

@DavidGoldman
Copy link
Author

DavidGoldman commented Mar 20, 2020

e.g. have VSCode pass the position of the start of the selection instead of the active position

I can re-open this against VSCode if you want.

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 20, 2020

Looks like there is nothing LSP can do about it.

It feels to me like the protocol should state whether the start or the end of the selection should be sent. I do however agree with @DavidGoldman that the decision should be to send the start of the selection.

@dbaeumer
Copy link
Member

I actually disagree. The position that should be used is the one where the cursor blinks. Otherwise it is IMO confusion for the user.

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 23, 2020

I actually disagree. The position that should be used is the one where the cursor blinks. Otherwise it is IMO confusion for the user.

OK. This should be documented in the protocol then.

@DavidGoldman
Copy link
Author

I actually disagree. The position that should be used is the one where the cursor blinks. Otherwise it is IMO confusion for the user.

I disagree, most people who are selecting text to copy don't care about the cursor position - they care about the selection itself unless they're actually trying to edit it. I didn't even notice it exists until you mentioned it. They care about the symbol selected, for which the start position is a better fit. FWIW, I've filed this bug because:

  1. Users did not find this intuitive - they filed a bug internally because it did not operate as expected
  2. Xcode does not have this issue - it appears to send the start position

@dbaeumer
Copy link
Member

At the end this is not a protocol issue. It is a client / editor decision. If for consistency an editor decides to honor the direction of a selection it is free to do so. If XCode decides to operate differently it is fine as well. I am against specing this in the protocol and forcing every client to implement the same behavior. What if an editor has a LSP server powering a language feature and for another feature not. How should a client behave in that case.

@DavidGoldman
Copy link
Author

At the end this is not a protocol issue. It is a client / editor decision. If for consistency an editor decides to honor the direction of a selection it is free to do so. If XCode decides to operate differently it is fine as well. I am against specing this in the protocol and forcing every client to implement the same behavior. What if an editor has a LSP server powering a language feature and for another feature not. How should a client behave in that case.

Doesn't the selection need to be in the protocol? Otherwise how can you expect the editor to tell the difference between a selection vs. the user manually trigger requests at that cursor position (you can't). Such that if you were designing an LSP for a specific editor, it might not work properly with another editor due to differences in how the editor handles selection.

At the very least the LSP documentation should include this behavior: selection may occur in different ways and the LSP should receive the active cursor position of the selection or it's intentionally left unspecified.

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 26, 2020

At the very least the LSP documentation should include this behavior: selection may occur in different ways and the LSP should receive the active cursor position of the selection or it's intentionally left unspecified.

Agreed. The protocol should be clear that the position is not standardized and that servers should account for this if possible.

@dbaeumer
Copy link
Member

The protocol should be clear that the position is not standardized and that servers should account for this if possible.

IMO this is not correct. A position is standardized and the server shouldn't account for. It can't in the current design of the protocol.

If we want to give servers a choice I agree that we need to change the API from position to selection. But I am not sure if this is worth it.

I do agree that the documentation should mention that the editor / library converts a selection to a position and that the decision is made by the editor / library.

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 27, 2020

The protocol should be clear that the position is not standardized and that servers should account for this if possible.

IMO this is not correct. A position is standardized and the server shouldn't account for. It can't in the current design of the protocol.

If we want to give servers a choice I agree that we need to change the API from position to selection. But I am not sure if this is worth it.

I do agree that the documentation should mention that the editor / library converts a selection to a position and that the decision is made by the editor / library.

I think we are ultimately saying the same thing so I'll wait for the changes to be written into the microsoft/language-server-protocol repository before commenting further.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 8, 2020

Added this to the spec:

It is up to the client to decide how a selection is converted into a position when issuing a request for a text document. The client can for example honor or ignore the selection direction to make LSP request consistent with features implemented internally.

I think we need a different item if we want to support selections instead of positions.

@dbaeumer dbaeumer closed this as completed Oct 8, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants