-
Notifications
You must be signed in to change notification settings - Fork 859
TextDocumentContentChangeEvent#rangeLength redundant? #9
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
Comments
DidChangeTextDocumentParams could maybe reuse TextEdit |
Agree, but the reason we sent this is to avoid unnecessary work on a server which has a [offset, length] text model instead of a [[startLine, startColumn], [endLine, endColumn]] model. |
Will look if it makes sense to reuse TextEdit |
Okay so I get that it might be convenient to include redundant info. However, the fact that its redundant also makes it a little unclear what the expectations are from client/server point of view. In particular, is it okay for a client to only specify range but not rangeLength (since the info is redundant, if client didn't feel like computing it, the client implementor might assume that this is okay and the server must deal with that). I see two possible interpretations depending on who's point of view we take re 'convenience' here:
My guess is that the intention here is to use the first interpretation (based on what was said earlier, which implies this is for the convenience of server implementation). Whether I'm guessing it right or not... it would be good to make this very clear in the Spec. Alternatively, maybe its just easier / better avoid this complexity in the Spec and just deprecate/remove the redundant |
I understand this to function something like the emacs change hooks which states
So the changes corresponding to adding a line, and then deleting it are
|
According to that observed in vscode. See also microsoft/language-server-protocol#9
And it struck me that one of |
According to that observed in vscode. See also microsoft/language-server-protocol#9
It only seems redundant, because (@alanz so emacs/lsp-mode calculation now is incorrect, it makes deletions at the end of a line produce end position = beginning of the next line, which makes it look like deletion of EOL, i.e line join). So, the properly universal OnChange event should split
Any single one of start/end/rangeLength can be omitted if the other two values are specified, because it can be calculated from them, i.e.
Any two of them could be omitted.
Or they all can be omitted if the whole document is to be replaced. |
PS. That said, this is probably an overgeneralization. I think it would be general enough to always demand presence of |
I agree with the analysis from @albel727, though it took me a while to fully understand the problem with Emacs Change Hooks. Here are some details that I hope someone else will find useful. Consider the case of a single-line deletion. Here are the buffer contents at time 1.
And here are the buffer contents at time 2, after line 1 is deleted. (Note that a newline character is at position 5).
From the Emacs documentation on Change Hooks:
So after the line deletion, our
The desired payload of the TextDocumentContentChangeEvent for this edit looks like this:
As proof, instead of
consider the following, alternate, prior state of the buffer:
Deleting the first 2 lines would produce the same buffer state as before:
And the arguments to our
But the correct payload for the TextDocumentContentChangeEvent corresponding to this change is:
(Note the difference in the Thus, the best we can do using Emacs Text Hooks is to correctly specify the Given a |
I concur, this not at all implied by the current wording. Our language servers handling of change events, for example, totally ignores The emacs situation, gives a strong argument in favor of allowing more flexibility for the client to omit one of the redundant infos if its hard for them to compute it. But that should be made clear in the spec, so server implementors know how to properly deal with that. |
Given the state of emacs, I would like to suggest that we disallow the range end for a delete, as this is not available in emacs, and is redundant for managing the changes. See also emacs-lsp/lsp-mode#114 |
Summary: Per discussion in microsoft/language-server-protocol#9 it is not clear whether this field needs to be implemented by the client or the server, but I came across a server cquery that expects the field (https://git.io/vF7HM). Reviewed By: hansonw Differential Revision: D6375164 fbshipit-source-id: 680e2c80ae7382b70f51669337547cfa4094e6d3
I just want to chime that I, as a LSP client writer, think that this is bonkers also |
I agree that this is confusing and today I would not add If we want to allow |
To get out of this I changed it as follows: /**
* An event describing a change to a text document. If range and rangeLength are omitted
* the new text is considered to be the full content of the document.
*/
export type TextDocumentContentChangeEvent = {
/**
* The range of the document that changed.
*/
range: Range;
/**
* The optional length of the range that got replaced.
*
* @deprecated use range instead.
*/
rangeLength?: number;
/**
* The new text for the provided range.
*/
text: string;
} | {
/**
* The new text of the whole document.
*/
text: string;
} I think that better con ways what we want to do here. |
Closing since in 3.15 the value is deprecated. |
It seems like 'rangeLength' is redundant, as it can be computed from the 'range'. Should be deprecated.
The text was updated successfully, but these errors were encountered: