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

Formatting(in my case via Prettier extension) start duplicate text after approx 4 uses #2196

Closed
pmizio opened this issue Jul 28, 2020 · 2 comments · Fixed by #3233
Closed
Labels
A-language-support Area: Language support, syntax highlighting, language server etc. bug Something isn't working I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor

Comments

@pmizio
Copy link

pmizio commented Jul 28, 2020

Like in topic - gif demonstrating problem:
test

Oni2 lastest build from early access 3ceb0a1
Prettier extension fresh installed via gui version: 5.1.3

@bryphe bryphe added bug Something isn't working A-language-support Area: Language support, syntax highlighting, language server etc. I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor labels Jul 30, 2020
@necabo
Copy link
Contributor

necabo commented Sep 26, 2020

Had the same issue using rust-analyzer so this is probably a general issue. I sadly couldn't figure out how to reproduce it consistently. It seemed to work fine for a long time after a restart before breaking again.

@marcagba
Copy link
Contributor

marcagba commented Nov 8, 2020

I encounter a similar issue. Up until a certain amount of use prettier start to mangle my file: some lines are duplicated and others are removed.

bryphe added a commit that referenced this issue Mar 5, 2021
…its (#3233)

__Issue:__ When running format providers, like `prettier` or `rescript`, after multiple iterations, there could start to be duplicated or corrupted text.

__Defect:__ Some of the edits provided by the format provider, once they round-trip through our vim layer, weren't being applied back correctly in the extension host buffer updates (the `ModelContentChange` that we send to the extension host layer) - this would cause the buffer state to be de-sync'd - meaning that the view of the buffer text was different in the extension host than in the editor. The editor was correct, but the buffer text on the extension host side would have extra lines or extra concatenation, and when the next format was triggered, the formatting edits for the desync'd buffer would be applied, causing the issues in #2196

Currently, the way we send buffer updates is always linewise - and therefore a newline must always be included at the end. In the particular case of a formatting edit consolidating lines (deleting empty spaces), we wouldn't be adding that trailing newline - and this was the root cause of the desync.

While investigating, I found another case with undo - creating multiple lines, and then undoing them, triggers a similar bug.

__Fix:__ Simplify the way we decide to append a newline to correct these issues. Add a test case exercising the undo condition (once we have `$tryApplyEdit`, it'd be great to have that API exercised in a text synchronization case as well).

In addition, add some extra tooling in our `oni-dev-extension` to support troubleshooting these issues - when running with `oni2 -f --silent --debug-exthost` and running the `Developer: Show buffer updates` command, the extension host's view of the buffer will be shown in the console after each update.

__Next steps:__
- There's still a lot of room for improvement in the way we handle buffer updates - streamlining individual edits, and batched related updates into a single update call.

Fixes #2196 and the remainder of #2820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Language support, syntax highlighting, language server etc. bug Something isn't working I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants