From 33c9dc37bd354391579f669a142699801b13d571 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Magnus=20Gro=C3=9F?= <magnus@mggross.com>
Date: Mon, 4 Sep 2023 17:50:12 +0200
Subject: [PATCH] Do not reset cursor after workspaceEdit

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 | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim
index 0ea69fb..2fe2ad0 100644
--- a/autoload/lsp/textedit.vim
+++ b/autoload/lsp/textedit.vim
@@ -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
-- 
2.51.0