aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/util.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <506791+stevearc@users.noreply.github.com>2023-08-30 18:34:13 -0700
committerGitHub <noreply@github.com>2023-08-30 18:34:13 -0700
commit92393f02efadfb1d9f97c74c8feb853c1caea9de (patch)
tree980a43e5f6b70c419e089f82074d177aca9da7aa /lua/conform/util.lua
parentc100b8548fd7262a1275bdb867186d0cd94e8b45 (diff)
feat: apply changes as text edits using LSP utils (#18)
* feat: apply changes as text edits using LSP utils This means we can leverage all of the work that was done in the LSP client to preserve marks, cursor position, etc * log: add trace logging to debug performance * feat: use the same diff -> TextEdit technique for bad LSP servers Some LSP servers simply return a single TextEdit that replaces the whole buffer. This is bad for extmarks, cursor, and if the buffer is open in multiple windows the non-active window will jump to the top. We can detect that situation and apply the same vim.diff logic to convert it into more granular TextEdits.
Diffstat (limited to 'lua/conform/util.lua')
-rw-r--r--lua/conform/util.lua30
1 files changed, 0 insertions, 30 deletions
diff --git a/lua/conform/util.lua b/lua/conform/util.lua
index d0856ab..a408675 100644
--- a/lua/conform/util.lua
+++ b/lua/conform/util.lua
@@ -28,36 +28,6 @@ M.root_file = function(files)
end
end
----@param bufnr? integer
----@return fun() Function that restores the window positions
-M.save_win_positions = function(bufnr)
- if bufnr == nil or bufnr == 0 then
- bufnr = vim.api.nvim_get_current_buf()
- end
- local win_positions = {}
- for _, winid in ipairs(vim.api.nvim_list_wins()) do
- if vim.api.nvim_win_get_buf(winid) == bufnr then
- vim.api.nvim_win_call(winid, function()
- local view = vim.fn.winsaveview()
- win_positions[winid] = view
- end)
- end
- end
-
- return function()
- for winid, view in pairs(win_positions) do
- if
- vim.api.nvim_win_is_valid(winid)
- and vim.deep_equal(vim.api.nvim_win_get_cursor(winid), { 1, 0 })
- then
- vim.api.nvim_win_call(winid, function()
- pcall(vim.fn.winrestview, view)
- end)
- end
- end
- end
-end
-
---@param bufnr integer
---@param range conform.Range
---@return integer start_offset