From 25b761d47cfa246d1ea4126747cbe30553edf065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Wed, 22 Nov 2023 13:02:36 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20config(nvim):=20trying=20a?= =?UTF-8?q?nother=20lens=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/nvim/lua/plugins/extras/lsp/lens.lua | 87 ++++++++++++++++---- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/.config/nvim/lua/plugins/extras/lsp/lens.lua b/.config/nvim/lua/plugins/extras/lsp/lens.lua index dd4c5126..77562a3f 100644 --- a/.config/nvim/lua/plugins/extras/lsp/lens.lua +++ b/.config/nvim/lua/plugins/extras/lsp/lens.lua @@ -1,19 +1,78 @@ +local function h(name) + return vim.api.nvim_get_hl(0, { name = name }) +end + +-- hl-groups can have any name +vim.api.nvim_set_hl(0, "SymbolUsageRounding", { fg = h("CursorLine").bg, italic = true }) +vim.api.nvim_set_hl(0, "SymbolUsageContent", { bg = h("CursorLine").bg, fg = h("Comment").fg, italic = true }) +vim.api.nvim_set_hl(0, "SymbolUsageRef", { fg = h("Function").fg, bg = h("CursorLine").bg, italic = true }) +vim.api.nvim_set_hl(0, "SymbolUsageDef", { fg = h("Type").fg, bg = h("CursorLine").bg, italic = true }) +vim.api.nvim_set_hl(0, "SymbolUsageImpl", { fg = h("@keyword").fg, bg = h("CursorLine").bg, italic = true }) + +local function text_format(symbol) + local res = {} + + local round_start = { "", "SymbolUsageRounding" } + local round_end = { "", "SymbolUsageRounding" } + + if symbol.references then + local usage = symbol.references <= 1 and "usage" or "usages" + local num = symbol.references == 0 and "no" or symbol.references + table.insert(res, round_start) + table.insert(res, { "󰌹 ", "SymbolUsageRef" }) + table.insert(res, { ("%s %s"):format(num, usage), "SymbolUsageContent" }) + table.insert(res, round_end) + end + + if symbol.definition then + if #res > 0 then + table.insert(res, { " ", "NonText" }) + end + table.insert(res, round_start) + table.insert(res, { "󰳽 ", "SymbolUsageDef" }) + table.insert(res, { symbol.definition .. " defs", "SymbolUsageContent" }) + table.insert(res, round_end) + end + + if symbol.implementation then + if #res > 0 then + table.insert(res, { " ", "NonText" }) + end + table.insert(res, round_start) + table.insert(res, { "󰡱 ", "SymbolUsageImpl" }) + table.insert(res, { symbol.implementation .. " impls", "SymbolUsageContent" }) + table.insert(res, round_end) + end + + return res +end + return { - "VidocqH/lsp-lens.nvim", - event = "BufReadPost", - opts = { - sections = { - definition = false, - references = function(count) - return " Ref: " .. count - end, - implements = function(count) - return "󱁤 Imp: " .. count - end, - git_authors = false, + { + "Wansmer/symbol-usage.nvim", + enabled = false, + event = "BufReadPre", -- need run before LspAttach if you use nvim 0.9. On 0.10 use 'LspAttach' + opts = { + text_format = text_format, }, }, - keys = { - { "ue", "LspLensToggle", desc = "Toggle Lsp Lens" }, + { + "VidocqH/lsp-lens.nvim", + event = "LspAttach", + opts = { + sections = { + definition = false, + references = function(count) + return "󰌹 Ref: " .. count + end, + implements = function(count) + return "󰡱 Imp: " .. count + end, + git_authors = false, + }, + }, + keys = { + { "ue", "LspLensToggle", desc = "Toggle Lsp Lens" }, + }, }, }