diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 3e8bc8b7..eb37acc3 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -129,8 +129,6 @@ return { LazyVim.lsp.setup() LazyVim.lsp.on_dynamic_capability(require("lazyvim.plugins.lsp.keymaps").on_attach) - LazyVim.lsp.words.setup(opts.document_highlight) - -- diagnostics signs if vim.fn.has("nvim-0.10.0") == 0 then if type(opts.diagnostics.signs) ~= "boolean" then diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 2a35dc97..00fa0c64 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -28,14 +28,14 @@ function M.get() { "cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } }, { "cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" }, { "cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" }, - { "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight", - desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight", - desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "", function() LazyVim.lsp.words.jump(vim.v.count1, true) end, has = "documentHighlight", - desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end }, - { "", function() LazyVim.lsp.words.jump(-vim.v.count1, true) end, has = "documentHighlight", - desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end }, + { "]]", function() Snacks.words.jump(vim.v.count1) end, has = "documentHighlight", + desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end }, + { "[[", function() Snacks.words.jump(-vim.v.count1) end, has = "documentHighlight", + desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end }, + { "", function() Snacks.words.jump(vim.v.count1, true) end, has = "documentHighlight", + desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end }, + { "", function() Snacks.words.jump(-vim.v.count1, true) end, has = "documentHighlight", + desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end }, } return M._keys diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index 7efd8622..eb10b02f 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -260,82 +260,6 @@ function M.format(opts) end end ----@alias LspWord {from:{[1]:number, [2]:number}, to:{[1]:number, [2]:number}} 1-0 indexed -M.words = {} -M.words.enabled = false -M.words.ns = vim.api.nvim_create_namespace("vim_lsp_references") - ----@param opts? {enabled?: boolean} -function M.words.setup(opts) - opts = opts or {} - if not opts.enabled then - return - end - M.words.enabled = true - local handler = vim.lsp.handlers["textDocument/documentHighlight"] - vim.lsp.handlers["textDocument/documentHighlight"] = function(err, result, ctx, config) - if not vim.api.nvim_buf_is_loaded(ctx.bufnr) then - return - end - vim.lsp.buf.clear_references() - return handler(err, result, ctx, config) - end - - M.on_supports_method("textDocument/documentHighlight", function(_, buf) - vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI", "CursorMoved", "CursorMovedI" }, { - group = vim.api.nvim_create_augroup("lsp_word_" .. buf, { clear = true }), - buffer = buf, - callback = function(ev) - if not require("lazyvim.plugins.lsp.keymaps").has(buf, "documentHighlight") then - return false - end - - if not ({ M.words.get() })[2] then - if ev.event:find("CursorMoved") then - vim.lsp.buf.clear_references() - elseif not LazyVim.cmp.visible() then - vim.lsp.buf.document_highlight() - end - end - end, - }) - end) -end - ----@return LspWord[] words, number? current -function M.words.get() - local cursor = vim.api.nvim_win_get_cursor(0) - local current, ret = nil, {} ---@type number?, LspWord[] - for _, extmark in ipairs(vim.api.nvim_buf_get_extmarks(0, M.words.ns, 0, -1, { details = true })) do - local w = { - from = { extmark[2] + 1, extmark[3] }, - to = { extmark[4].end_row + 1, extmark[4].end_col }, - } - ret[#ret + 1] = w - if cursor[1] >= w.from[1] and cursor[1] <= w.to[1] and cursor[2] >= w.from[2] and cursor[2] <= w.to[2] then - current = #ret - end - end - return ret, current -end - ----@param count number ----@param cycle? boolean -function M.words.jump(count, cycle) - local words, idx = M.words.get() - if not idx then - return - end - idx = idx + count - if cycle then - idx = (idx - 1) % #words + 1 - end - local target = words[idx] - if target then - vim.api.nvim_win_set_cursor(0, target.from) - end -end - M.action = setmetatable({}, { __index = function(_, action) return function()