-
Notifications
You must be signed in to change notification settings - Fork 26
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
Bad parsing of DidChangeTextDocumentParams ContentChanges #9
Comments
The current workaround is to have an additional check to see if the range is all zeroes. for _, change := range parameters.ContentChanges {
switch cast := change.(type) {
case protocol.TextDocumentContentChangeEvent:
// https://github.com/tliron/glsp/issues/9
if cast.Range.Start.Line == 0 && cast.Range.Start.Character == 0 && cast.Range.End.Line == 0 && cast.Range.End.Character == 0 {
document.Content = cast.Text
continue
}
// TODO: For now, don't support incremental changes
return fmt.Errorf("incremental changes are not supported")
case protocol.TextDocumentContentChangeEventWhole:
document.Content = cast.Text
}
} |
You are correct in that we can only check for "Range" as the differentiator, because "RangeLength" can be omitted. However, I think there might be a better solution: define the
I did some experimentation and it seems the go/json will leave the pointer as nil if there is no "range" field in the JSON, so we can just check for nil. What do you think? |
That is how the source graph LSP project solves it, which has worked for me before. It’s already documented for the type as well that if range is nil, the update is for the entire document. |
Please let me know if my fix works! |
This works. Thanks for fixing it so fast! Closing. |
In order to parse either a
TextDocumentContentChangeEvent
orTextDocumentContentChangeEventWhole
from theContentChanges
, the code uses the assumption that the marshaling fails if there are missing fields. This is not true.glsp/protocol_3_16/text-document-synchronization.go
Lines 105 to 117 in f4d3bef
Example code where this assumption is shown.
A better approach for detecting would be to first have a common, private, struct much like
TextDocumentContentChangeEvent
, but whereRange
is a pointer. If the pointer is nil after marshaling, then return aTextDocumentContentChangeEventWhole
, else return aTextDcoumentContentChangeEvent
. That mechanism uses the documented behavior for the changes - range is never set for whole updates.The text was updated successfully, but these errors were encountered: