diff --git a/nvim/init.lua b/nvim/init.lua index cee2f2c..b9e5e04 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -94,6 +94,9 @@ require('lazy').setup({ -- Plugins for color highlight require 'custom.plugins.colorizer', + -- Symbol usage plugin + require 'custom.plugins.symbol_usage', + -- Autoformat markdown tables { 'Kicamon/markdown-table-mode.nvim', diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 3c10049..b4bd4be 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -45,6 +45,7 @@ "rose-pine": { "branch": "main", "commit": "7d1b5c7dcd274921f0f58e90a8bf935f6a95fbf3" }, "rustaceanvim": { "branch": "master", "commit": "2b0f0b7e03751cf8ed123322f9b02d8f73fa9df7" }, "sonokai": { "branch": "master", "commit": "9679341d4141ed81376f2bdf5e69b78dc348d212" }, + "symbol-usage.nvim": { "branch": "main", "commit": "e07c07dfe7504295a369281e95a24e1afa14b243" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, diff --git a/nvim/lua/custom/plugins/symbol_usage.lua b/nvim/lua/custom/plugins/symbol_usage.lua new file mode 100644 index 0000000..e7fd090 --- /dev/null +++ b/nvim/lua/custom/plugins/symbol_usage.lua @@ -0,0 +1,39 @@ +-- Symbol usage plugin + +local SymbolKind = vim.lsp.protocol.SymbolKind + +local function text_format(symbol) + local fragments = {} + + -- Indicator that shows if there are any other symbols in the same line + local stacked_functions = 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(fragments, ('%s %s'):format(num, usage)) + end + + if symbol.definition then + table.insert(fragments, symbol.definition .. ' defs') + end + + if symbol.implementation then + table.insert(fragments, symbol.implementation .. ' impls') + end + + return table.concat(fragments, ', ') .. stacked_functions +end + +return { + { + 'Wansmer/symbol-usage.nvim', + event = 'LspAttach', -- need run before LspAttach if you use nvim 0.9. On 0.10 use 'LspAttach' + config = function() + require('symbol-usage').setup { + text_format = text_format, + kinds = { SymbolKind.Function, SymbolKind.Method, SymbolKind.Class, SymbolKind.Struct, SymbolKind.Variable, SymbolKind.Constant }, + } + end, + }, +}