-
Notifications
You must be signed in to change notification settings - Fork 137
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
Document synchronization between client and server goes awry #283
Comments
I can't reproduce it in VSCode but it creates just one edit when adding newline so it might not be triggering the bug:
|
The issue is that the server calculates So here: terraform-ls/langserver/handlers/did_change.go Lines 43 to 50 in 588f9d5
instead of calculating the changes before calling fs.ChangeDocument , it needs to do that as it modifies the document since changes reported by LSP are based on previous change.
|
Hi @rchl FWIW the terraform-ls/internal/lsp/file_change.go Lines 32 to 42 in 588f9d5
After all the terraform-ls/internal/filesystem/filesystem.go Lines 85 to 90 in 588f9d5
I don't understand how this could contribute to a bug you're describing, but I do believe that there may be a bug. I'm going to try to reproduce this by replaying the attached log in an integration test. |
I should note though that I only tried reproducing it with Sublime Text LSP |
The "LSP" to "HCL" conversion of the changes needs to be done on top of the previous document state. So when we have the document in state A and receive two changes that change the document from A->B and B->C, the first change needs to be "calculated" (or resolved) on state A and the second change needs to be resolved on state B. Currently, both are resolved on state A. There is ST4 available in beta testing which I'm using on a daily basis and the LSP version available for it much further in development - LSP for ST3 is in maintenance mode. I believe LSP for ST3 doesn't support incremental changes so it likely avoids this issue. |
Maybe I didn't explain it very well (apologies), but what I meant to say above is that the whole If there is any bug with calculation of changes, then that would be in the filesystem as that's where we're applying changes.
I see, that's a very good point - Thank you! I will try to obtain ST4. 👍 |
This is the invite to the Discord server where you'll find it in You can also hop into BTW. ST4 is still in kinda closed beta so it requires an ST3 license. |
You are likely right here. I've assumed that the type conversion transforms line/character into a byte offset but it doesn't do that. |
Just reproduced this in Sublime Text 4. |
You were absolutely right here, it actually does and it does look like the root cause of this bug, I must have overlooked this. I'm working on a fix which will probably move the conversion outside of |
Fix is queued for review in #304 which also has two tests attached with the data from this issue. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Editing document produces random diagnostics errors related to missing commas and such.
Server Version
Terraform Version
Client Version
Terraform Configuration Files
---
Log Output
https://gist.github.com/rchl/3fc2bbaa175a9ecbafd7d3b111d87217
Expected Behavior
No spurious errors should be reported.
Actual Behavior
Random errors are reported on editing files.
Steps to Reproduce
[|
This is the relevant part where with
didChange
notification:a) add new-line
b) add indent:
I think maybe the server doesn't correctly apply the first notification that has multiple edits.
The text was updated successfully, but these errors were encountered: