aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/news.txt3
-rw-r--r--runtime/lua/vim/lsp/util.lua22
2 files changed, 25 insertions, 0 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index f8757af2be..e42be43461 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -41,6 +41,9 @@ ADDED FEATURES *news-added*
The following new APIs or features were added.
+• Neovim's LSP client now always saves and restores named buffer marks when
+ applying text edits.
+
• Nvim's LSP client now advertises the general.positionEncodings client
capability to indicate to servers that it supports utf-8, utf-16, and utf-32
encodings. If the server responds with the positionEncoding capability in
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 53f8dba814..ba8c72128e 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -451,6 +451,14 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
}
end)()
+ -- save and restore local marks since they get deleted by nvim_buf_set_lines
+ local marks = {}
+ for _, m in pairs(vim.fn.getmarklist(bufnr or vim.api.nvim_get_current_buf())) do
+ if m.mark:match("^'[a-z]$") then
+ marks[m.mark:sub(2, 2)] = { m.pos[2], m.pos[3] - 1 } -- api-indexed
+ end
+ end
+
-- Apply text edits.
local is_cursor_fixed = false
local has_eol_text_edit = false
@@ -518,6 +526,20 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
local max = api.nvim_buf_line_count(bufnr)
+ -- no need to restore marks that still exist
+ for _, m in pairs(vim.fn.getmarklist(bufnr or vim.api.nvim_get_current_buf())) do
+ marks[m.mark:sub(2, 2)] = nil
+ end
+ -- restore marks
+ for mark, pos in pairs(marks) do
+ if pos then
+ -- make sure we don't go out of bounds
+ pos[1] = math.min(pos[1], max)
+ pos[2] = math.min(pos[2], #(get_line(bufnr, pos[1] - 1) or ''))
+ vim.api.nvim_buf_set_mark(bufnr or 0, mark, pos[1], pos[2], {})
+ end
+ end
+
-- Apply fixed cursor position.
if is_cursor_fixed then
local is_valid_cursor = true