Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix server panic when undoing an edit #14010

Merged
merged 3 commits into from
Nov 1, 2024
Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Oct 31, 2024

Summary

Fixes #13674 and possibly astral-sh/ruff-vscode#607

The TextDocument::apply_changes contained some naive logic to reuse the LineIndex if it happened that the content didn't change.
Hower, that logic was incorrect because it compared the new_content with the original document content rather than the content
from the last iteration. This resulted in a stale LineIndex when an edit reverts the content to the original content.

I decided to remove the optimization alltogether because it's too naive to be useful in practice. We could apply a logic similar
to Biome's, we avoid recomputing the LineIndex when the previous edits only changed lines further down in the document. source
However, I don't think that this is a big perf bottlneck. Computing a LineIndex is relatively cheap.

Test Plan

I added a unit test

@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server labels Oct 31, 2024
Copy link
Contributor

github-actions bot commented Oct 31, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for looking into it

@MichaReiser MichaReiser merged commit 20b8a43 into main Nov 1, 2024
20 checks passed
@MichaReiser MichaReiser deleted the micha/fix-server-panic branch November 1, 2024 07:16
TomerBin pushed a commit to TomerBin/ruff that referenced this pull request Nov 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server panics when code contains CJK characters
2 participants