prabirshrestha / vim-lsp

async language server protocol plugin for vim and neovim
MIT License
3.07k stars 303 forks source link

fix(text_edit): discarded change from the initial buffer #1552

Closed tbruyelle closed 1 week ago

tbruyelle commented 3 months ago

When multiple calls to the apply_text_edits() function are made, the changes made to the current buffer are discarded if the following text_edit targets a file that is not in the buffer list.

The problem comes from the _switch function, which executes edit! when it detects that the target is not in the buffer list. If a change has already been made to the current buffer before that, that change is discarded (definition of edit!).

The fix uses of a different logic: if _switch detects that the target is not in the buffer list, it calls badd before switching to the buffer that has just been added. No more edit!, no more discarded changes.

The added test will fail without the patch in the _switch function.

tbruyelle commented 2 months ago

Hey @prabirshrestha, could you please review this PR ? As mentioned in the body, the test can reproduce the bug, so if you want to make sure that this bug exists, just pull and run the test, without the fix. Thanks in advance :pray:

tbruyelle commented 2 months ago

Hey there, any chance to have a review for this PR plz ?

prabirshrestha commented 1 week ago

Merged. Thanks.