Skip to content

Commit 7c376c3

Browse files
authored
Add additional symbol kinds for current_function (#49)
* Add more symbol kinds to current_function There's little reason not to want to display enums, structs, and interfaces. They tend to be top-level in languages which define them, so they aren't competing with anything, like some of the smaller symbol kinds are. The updated formatting of the conditions is to keep the line length low. * Add `module` and `namespace` kinds These are also generally top-level, and (based on admittedly limited testing) don't interfere with other kinds. * Mention included function kinds in docs This will help people set `kind_labels` by giving them an exhaustive list of kinds they need to set labels for. * Extract valid kinds to a module-level array As suggested by the initial PR review, this significantly improves readability and maintainability. * Fix invalid table syntax Not sure why I thought table keys could be strings. * Correctly check `v.kind` (Why you don't commit to a PR branch even for minor things.)
1 parent fc07882 commit 7c376c3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ call packager#add('nvim-lua/lsp-status.nvim')
5252
The plugin provides several utilities:
5353
```lua
5454
update_current_function() -- Set/reset the b:lsp_current_function variable
55+
-- Shows the current function, method, class, struct, interface, enum, module, or namespace
5556
diagnostics() -- Return a table with all diagnostic counts for the current buffer
5657
messages() -- Return a table listing progress and other status messages for display
5758
register_progress() -- Register the provided handler for progress messages

doc/lsp-status.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ config({config}) *lsp-status.config()*
103103
accepted as the symbol currently containing the cursor.•
104104
`current_function`: Boolean, `true` if the current function
105105
should be updated and displayed in the default statusline
106-
component.
106+
component. Shows the current function, method, class,
107+
struct, interface, enum, module, or namespace.
107108
`indicator_errors` : Symbol to place next to the error count
108109
in `status` . Default: '',•
109110
`indicator_warnings` : Symbol to place next to the warning

lua/lsp-status/current_function.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ local function init(_, config)
99
_config = config
1010
end
1111

12+
-- the symbol kinds which are valid scopes
13+
local scope_kinds = {
14+
Class = true,
15+
Function = true,
16+
Method = true,
17+
Struct = true,
18+
Enum = true,
19+
Interface = true,
20+
Namespace = true,
21+
Module = true,
22+
}
23+
1224
-- Find current function context
1325
local function current_function_callback(_, _, result, _, _)
1426
vim.b.lsp_current_function = ''
@@ -18,7 +30,7 @@ local function current_function_callback(_, _, result, _, _)
1830

1931
local function_symbols = util.filter(util.extract_symbols(result),
2032
function(_, v)
21-
return v.kind == 'Class' or v.kind == 'Function' or v.kind == 'Method'
33+
return scope_kinds[v.kind]
2234
end)
2335

2436
if not function_symbols or #function_symbols == 0 then

0 commit comments

Comments
 (0)