go-language-server / protocol

Package protocol implements Language Server Protocol specification in Go
https://pkg.go.dev/go.lsp.dev/protocol
BSD 3-Clause "New" or "Revised" License
97 stars 15 forks source link

Problem with Range in TextDocumentContentChangeEvent #29

Open slzatz opened 3 years ago

slzatz commented 3 years ago

When generating a textDocument/didChange notification from a client you run into the following problem if you want to indicate that the content you are sending to the server is the entire document.

As you note in the comments: "If range and rangeLength are omitted the new text is considered to be the full content of the document."

However, you can't omit range in straightforward way unless you make it a pointer and add "omitempty"

So the TextDocumentContentChangeEvent type's Range field (in text.go) would become:

Range *Range `json:"range,omitempty"`

With that change providing no Range produces the correct json (no Range information at all) whereas without the change you get a Range type struct with start and end type structs containing line and character fields set to zero and that is not interpreted by gopls (I haven't checked other lsps) as having omitted the range.

zchee commented 2 years ago

@slzatz sorry for the delay. will looking it.

create-issue-branch[bot] commented 2 years ago

Branch issue-29-Problem_with_Range_in_TextDocumentContentChangeEvent created!

nichtverstehen commented 2 years ago

I stumbled upon this too. Are pull requests welcome for this issue? Is it important to maintain API backward compatibility here?