-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Gleam LSP fails to format because the end range is out of bounds #6022
Comments
We discussed this on the Matrix chat a little: it's unclear in the LSP spec whether ranges that point outside of the document are allowed, so I'm not sure whether this should be fixed in Helix or in Gleam. To fix it in Helix, |
Gleam does this on purpose: https://github.com/gleam-lang/gleam/blob/94caeb35b284dff0b4b8c3b0b800e3b3021b45a4/compiler-cli/src/lsp.rs#L860 In my opinion this is not really LSP compliant but I guess it doesn't hurt to still accept such positions. It should be quite easy. We should log a warning in that case tough in-case it's a genuine bug |
Actually, instead we should probably just handle the |
Hmm not quite I think the
Hmm not sure I think we should return Line 129 in ce0837d
I guess since other LSP client's don't have problems with such positions other servers might do this for other things than formatting too. |
I patched my helix 22.12 to return |
This isn't spec compliant. Could Gleam fix this upstream instead? |
The spec isn't really clear how out of bounds lines should be handled and this is not an accident by the gleam LSP. They specifically barcode a line range of This shouldn't affect servers that don't sent out of bounds ranges and should meet the expectation of those that do. It's also only a 1 line change so while I would usually not spend effort to work around a misbehaving LS in this case it's probably ok. |
A comment in the vscode language server explicitly mentions this behavior here |
Not that this would be likely to happen, but in theory this would fail on a file with IMO the Gleam LSP needs to only send valid ranges. 😄 |
While in an ideal world server would only follow the standard in practice almost all servers target VSCode and therefore those parts which are underdefined are practically implementation defined by vscode. Especially as the same people that develop VSCode handle the standard that means that "undefined behaviour" like this usually just gets retrospectively definied to whatever VSCode was doing anyway to not break backwards compatability. The point about
(yes it says I think the link @VlkrS provided above is a really strong indication that this is intentional (considering that vscode language server is written by the main author of the spec) and just another detail forgotten in the spec so I think it's a reasonable change |
I clarified with vscode-language-server-node and this behaviour is specific to that particular implementation, however it also does not contradict the specification either. |
If it is not specifically outlined in the spec, it is out of spec by definition. The spec makes no mention of this behavior, Gleam is out of spec here. |
Thanks for digging into this folks! Happy to make the change in Gleam. It would be fab if the spec could be made more clear here, my reading of it was that this was supported (I can see nothing that suggests otherwise) and VSCode's accepting of it solidified that in my mind. |
If someone could give it a test with the nightly build tomorrow that would be fab! Thank you |
Thank you everyone! 💜 |
Summary
The textDocument/formatting response from the gleam LSP sends a line number that is way past the end of the document:
That causes
lsp_pos_to_pos
to returnNone
which causes an early return here:helix/helix-lsp/src/lib.rs
Lines 323 to 327 in ce0837d
making the Transaction a no-op.
Reproduction Steps
I tried this:
hx file.gleam
:format
I expected this to happen: the formatter should turn the 4 column indent into a 2 column indent.
Instead, this happened: no change to the document.
Helix log
~/.cache/helix/helix.log
Platform
Linux
Terminal Emulator
Kitty 0.26.2
Helix Version
78a1e2d
The text was updated successfully, but these errors were encountered: