]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Do not reset cursor after workspaceEdit
authorMagnus Groß <magnus@mggross.com>
Mon, 4 Sep 2023 15:50:12 +0000 (17:50 +0200)
committerMagnus Groß <magnus@mggross.com>
Mon, 4 Sep 2023 15:54:50 +0000 (17:54 +0200)
The workspace edit may add or delete lines, so resetting it to the last
linenumber and column will very likely not match the last logical line
before the workspaceEdit operation.

For example an action might add an auto-import statement at the top of
the file, effectively adding one line in-between. If we now reset the
cursor, we will end up one logical line before the one where we actually
started at.

This behaviour is automatically fixed if we just don't reset the cursor
at all.

autoload/lsp/textedit.vim

index 0ea69fb911db8270ecefa21ec23b3310bd079b68..2fe2ad0208e8a14462d741f953a827d129973e32 100644 (file)
@@ -213,7 +213,6 @@ export def ApplyWorkspaceEdit(workspaceEdit: dict<any>)
     return
   endif
 
-  var save_cursor: list<number> = getcurpos()
   for [uri, changes] in workspaceEdit.changes->items()
     var bnr: number = util.LspUriToBufnr(uri)
     if bnr == 0
@@ -224,8 +223,6 @@ export def ApplyWorkspaceEdit(workspaceEdit: dict<any>)
     # interface TextEdit
     ApplyTextEdits(bnr, changes)
   endfor
-  # Restore the cursor to the location before the edit
-  save_cursor->setpos('.')
 enddef
 
 # vim: tabstop=8 shiftwidth=2 softtabstop=2