From 7a96d46c76a373cba8d7837a5a516198f5253913 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Mon, 1 Jul 2024 12:26:03 -0500 Subject: [PATCH] feat(nvim): install `symbol-usage.nvim` --- .../nvim/lua/plugins/configs/symbol-usage.lua | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 users/price/dots/.config/nvim/lua/plugins/configs/symbol-usage.lua diff --git a/users/price/dots/.config/nvim/lua/plugins/configs/symbol-usage.lua b/users/price/dots/.config/nvim/lua/plugins/configs/symbol-usage.lua new file mode 100644 index 00000000..abb3f414 --- /dev/null +++ b/users/price/dots/.config/nvim/lua/plugins/configs/symbol-usage.lua @@ -0,0 +1,75 @@ +return { + { + "Wansmer/symbol-usage.nvim", + event = "LspAttach", + config = function() + 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 }) + vim.api.nvim_set_hl(0, "SymbolUsageContent", { bg = h("CursorLine").bg, fg = h("Comment").fg }) + vim.api.nvim_set_hl(0, "SymbolUsageRef", { fg = h("Function").fg, bg = h("CursorLine").bg }) + vim.api.nvim_set_hl(0, "SymbolUsageDef", { fg = h("Type").fg, bg = h("CursorLine").bg }) + vim.api.nvim_set_hl(0, "SymbolUsageImpl", { fg = h("@keyword").fg, bg = h("CursorLine").bg }) + + local function text_format(symbol) + local res = {} + + local round_start = { "", "SymbolUsageRounding" } + local round_end = { "", "SymbolUsageRounding" } + + -- Indicator that shows if there are any other symbols in the same line + local stacked_functions_content = symbol.stacked_count > 0 and ("+%s"):format(symbol.stacked_count) + or "" + + 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 + + if stacked_functions_content ~= "" then + if #res > 0 then + table.insert(res, { " ", "NonText" }) + end + table.insert(res, round_start) + table.insert(res, { " ", "SymbolUsageImpl" }) + table.insert(res, { stacked_functions_content, "SymbolUsageContent" }) + table.insert(res, round_end) + end + + return res + end + + require("symbol-usage").setup({ + text_format = text_format, + vt_position = "end_of_line", + }) + end, + }, +}