Skip to content

Conversation

@pusewicz
Copy link
Contributor

@pusewicz pusewicz commented Feb 7, 2025

This adds support for incremental changes that are sent to the LSP server.

@pusewicz
Copy link
Contributor Author

@yegappan Please let me know what you think!

@yegappan
Copy link
Owner

Thanks for the contribution.

Did you run any tests to make sure that the correct contents are passed to the language server? One of the problems that I ran into earlier when trying to implement this functionality was that under some conditions incorrect contents were passed to the language server. After this, the language server will go out of sync with the buffer content in Vim. Did you try making modifications to a somewhat large buffer and exercise some of the LSP functionality on the modified content?

@pusewicz
Copy link
Contributor Author

@yegappan I keep using this branch locally on a daily basis, on large code bases, and it seems to be working fine. I do have extra logging added that I sometimes turn on and I spit out the lines that change to try to verify that this is correct. I looked at NeoVim's implementation and it seems similar, but yeah, I'm not sure what's the best way to verify the correctness. How about we move forward with this and fix as we go? Also, I'm not sure what's the issue with the tests and why are they so slow, even without the change.

@DanielViberg
Copy link
Contributor

DanielViberg commented Feb 22, 2025

I looked in to this a while ago, see #550

The issue I found was that some servers were more and some less ok with the diff in state of the vim buffer and the server cache.

But the root cause as stated is that the diffs, at times, from vim is not how the server wants it represented.

My best try was to enable only line based diffs, but even this seemed to fail at times.

@DanielViberg
Copy link
Contributor

Hello, I can provide a solution for how this can work: https://github.com/DanielViberg/lsp/blob/3bcea47377598e5bba9b5d47da34296dba5c9f3e/lib/Features/DocumentSync.vim#L79C1-L122C7

In the provided solution, a cached buffer state is saved after each change and compared with actual file state and a diff is created and the diff hunks are used to provide line based ranges for file updates. This solutions seems to be reliable.

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.

3 participants