aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--init.lua10
-rw-r--r--lspc.lua3
3 files changed, 13 insertions, 1 deletions
diff --git a/README.md b/README.md
index 69feba9..105bd41 100644
--- a/README.md
+++ b/README.md
@@ -137,6 +137,7 @@ Available options are:
* `ls_map` - a table mapping `vis` syntax names to language server configurations
* `highlight_diagnostics = 'line'` - highlight the `range` or `line`number of available diagnostics
* `diagnostic_style = 'back:#e3514f'` - style used to highlight diagnostics
+* `workspace_edit_remember_cursor = true` - restore the primary cursor position after a workspaceEdit
#### Configure your own Language Server
diff --git a/init.lua b/init.lua
index a97db10..54ea67a 100644
--- a/init.lua
+++ b/init.lua
@@ -548,7 +548,7 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit)
end
end
- -- It is not open currently -> open it
+ -- The file is not currently opened -> open it
local opened
if not win_with_file then
vis_open_file(path, 'o')
@@ -556,10 +556,18 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit)
opened = true
end
+ -- Remember the current primary cursor position
+ local old_pos = win_with_file.selection.pos
+
for _, edit in ipairs(edits) do
vis_apply_textEdit(win_with_file, win_with_file.file, edit)
end
+ -- Restore the remembered primary cursor position
+ if lspc.workspace_edit_remember_cursor then
+ win_with_file.selection.pos = old_pos
+ end
+
-- save changes and close the opened window
if opened then
vis:command('wq')
diff --git a/lspc.lua b/lspc.lua
index fad0fa7..5bd3c46 100644
--- a/lspc.lua
+++ b/lspc.lua
@@ -39,6 +39,9 @@ local lspc = {
-- 60% solarized red
diagnostic_style = 'back:#e3514f',
+ -- restore the position of the primary curser after applying a workspace edit
+ workspace_edit_remember_cursor = true,
+
-- message level to show in the UI when receiving messages from the server
-- Error = 1, Warning = 2, Info = 3, Log = 4
message_level = 3,