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

Fix bug when the client sends multiple contentChanges at once #1131

Merged
merged 2 commits into from
Dec 22, 2023

Conversation

peret
Copy link
Contributor

@peret peret commented Dec 15, 2023

On a textDocument/didChange notification, if the contentChanges contain multiple entries, each of them needs to be handled as if all previous changes were already applied. When we don't, the calculation of the change's byte offsets will be wrong, which can lead to a syntax tree that produces parsing errors where the actual file does not have any issues.
To solve this, we now apply the text of each change record to the full file text and use the result when applying the next change of the contentChanges array.

I think this will fix #878 (see issue comments for details).

@peret
Copy link
Contributor Author

peret commented Dec 15, 2023

I am not sure whether this would have any noticeable performance impact, especially since most editors will send this notification on every keystroke?
Since only events with more than one contentChanges entry are of interest here, it would be pretty easy to add a check and only call applyChangeToDocument() when needed.

@razzeee razzeee requested a review from jmbockhorst December 17, 2023 12:53
peret and others added 2 commits December 22, 2023 18:33
…multiple content changes at once.

On a textDocument/didChange notification, if the contentChanges contain
multiple entries, each of them needs to be handled as if all previous
changes were already applied. When we don't, the calculation of the
change's byte offsets will be wrong, which can lead to a syntax tree
that produces parsing errors where the actual file does not have any
issues.
To solve this, we now apply the text of each change record to the full
file text and use the result when applying the next change of the
contentChanges array.
Also, only update the document text with each change when it's required,
i.e. when there's more than one contentChange.
@razzeee razzeee force-pushed the fix-multiple-content-changes branch from 4d4b69a to e9da3a2 Compare December 22, 2023 17:33
@razzeee razzeee merged commit a0f07be into elm-tooling:main Dec 22, 2023
@tankorsmash
Copy link

Necro'ing the thread to say thank you for this patch! I updated from 2.7.1 to 2.8.0 and the LSP doesn't seem to be getting it wrong anymore. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yet More Erratic / Broken Behaviour
3 participants