Skip to content

Commit

Permalink
Merge pull request #30 from jonathan-elize/feat/allow-target-symbols-…
Browse files Browse the repository at this point in the history
…to-be-configurable

Allow target symbols for code lens to be configurable

---

LGTM, thanks!
  • Loading branch information
VidocqH authored Nov 14, 2023
2 parents 34b6aa1 + 45eea9f commit 579c1aa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ require'lsp-lens'.setup({})
Below is the default config

```lua
local SymbolKind = vim.lsp.protocol.SymbolKind

require'lsp-lens'.setup({
enable = true,
include_declaration = false, -- Reference include declaration
Expand All @@ -43,6 +45,10 @@ require'lsp-lens'.setup({
ignore_filetype = {
"prisma",
},
-- Target Symbol Kinds to show lens information
target_symbol_kinds = { SymbolKind.Function, SymbolKind.Method, SymbolKind.Interface },
-- Symbol Kinds that may have target symbol kinds as children
wrapper_symbol_kinds = { SymbolKind.Class, SymbolKind.Struct },
})
```

Expand Down
5 changes: 5 additions & 0 deletions doc/lsp-lens-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CONFIGS *lsp-lens-docs-lsp-lens.nvim-configs*
Below is the default config

>lua
local SymbolKind = vim.lsp.protocol.SymbolKind
require'lsp-lens'.setup({
enable = true,
include_declaration = false, -- Reference include declaration
Expand All @@ -63,6 +64,10 @@ Below is the default config
ignore_filetype = {
"prisma",
},
-- Target Symbol Kinds to show lens information
target_symbol_kinds = { SymbolKind.Function, SymbolKind.Method, SymbolKind.Interface },
-- Symbol Kinds that may have target symbol kinds as children
wrapper_symbol_kinds = { SymbolKind.Class, SymbolKind.Struct },
})
<

Expand Down
6 changes: 6 additions & 0 deletions lua/lsp-lens/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local M = {}

local SymbolKind = vim.lsp.protocol.SymbolKind

local defaults = {
enable = true,
include_declaration = false, -- Reference include declaration
Expand All @@ -25,6 +27,10 @@ local defaults = {
ignore_filetype = {
"prisma",
},
-- Target Symbol Kinds to show lens information
target_symbol_kinds = { SymbolKind.Function, SymbolKind.Method, SymbolKind.Interface },
-- Symbol Kinds that may have target symbol kinds as children
wrapper_symbol_kinds = { SymbolKind.Class, SymbolKind.Struct },
}

M.config = vim.deepcopy(defaults)
Expand Down
15 changes: 4 additions & 11 deletions lua/lsp-lens/lens-util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,10 @@ local function requests_done(finished)
return true
end

-- enum
local SymbolKind = {
Class = 5,
Methods = 6,
Interface = 11,
Function = 12,
Struct = 23,
}

local function get_functions(result)
local ret = {}
for _, v in pairs(result or {}) do
if v.kind == SymbolKind.Function or v.kind == SymbolKind.Methods or v.kind == SymbolKind.Interface then
if vim.tbl_contains(config.config.target_symbol_kinds, v.kind) then
if v.range and v.range.start then
table.insert(ret, {
name = v.name,
Expand All @@ -57,7 +48,9 @@ local function get_functions(result)
selectionRangeEnd = v.selectionRange["end"],
})
end
elseif v.kind == SymbolKind.Class or v.kind == SymbolKind.Struct then
end

if vim.tbl_contains(config.config.wrapper_symbol_kinds, v.kind) then
ret = utils:merge_table(ret, get_functions(v.children)) -- Recursively find methods
end
end
Expand Down

0 comments on commit 579c1aa

Please # to comment.