Skip to content
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

robustly handle invalid LSP ranges #6512

Merged
merged 1 commit into from Apr 3, 2023

Conversation

pascalkuthe
Copy link
Member

Fix crashes with the TS language server reported on matrix

The Problem is that the way helix deals with invalid LSP ranges is different from other editors right now. Helix currently panics if the start of a LSP range is after the end of the range. The standard doesn't actually state that this is forbidden. VSCode simply sets start=end in that case and there seem to be a few servers relying on this sadly. I matched that behavior but logged an error to make sure this is not missed when tracking down issues. Alternatively we could discard such ranges. We definitely shouldn't panic tough.

Similarly, we now allow ranges with line numbers past the end (simply treated as EOF). VSCode behaves the same and so does neovim. I copied their comment here:

If it extends past the end, truncate it to the end. This is because the
way the LSP describes the range including the last newline is by
specifying a line number after what we would call the last line.

@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much A-language-server Area: Language server client labels Mar 31, 2023
@pascalkuthe pascalkuthe added the S-waiting-on-review Status: Awaiting review from a maintainer. label Mar 31, 2023
Comment on lines +132 to +136
// If it extends past the end, truncate it to the end. This is because the
// way the LSP describes the range including the last newline is by
// specifying a line number after what we would call the last line.
log::warn!("LSP position {pos:?} out of range assuming EOF");
return Some(doc.len_chars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is #6022, right? And this change brings us in line with VSCode's handling of this edge-case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly vscode behaves the same and the comment is from neovim so they also behave the same

the-mikedavis
the-mikedavis previously approved these changes Mar 31, 2023
@archseer archseer added this to the 23.03.1 milestone Apr 1, 2023
offset_encoding: OffsetEncoding,
) -> Option<Range> {
// This is sort of an edgecase. It's not clear from the spec how to deal with
// ranges where end < start. They don't make much sense but vscode simply caps start to end
// and because it's not specified quite a few LS rely on this as a result (for example the TS server)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(╯°□°)╯︵ ┻━┻

@archseer archseer merged commit 1073dd6 into helix-editor:master Apr 3, 2023
6 checks passed
@pascalkuthe pascalkuthe deleted the robust_lsp_range branch April 3, 2023 02:54
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants