Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional symbol kinds for current_function #49

Merged
merged 6 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ call packager#add('nvim-lua/lsp-status.nvim')
The plugin provides several utilities:
```lua
update_current_function() -- Set/reset the b:lsp_current_function variable
-- Shows the current function, method, class, struct, interface, enum, module, or namespace
diagnostics() -- Return a table with all diagnostic counts for the current buffer
messages() -- Return a table listing progress and other status messages for display
register_progress() -- Register the provided handler for progress messages
Expand Down
3 changes: 2 additions & 1 deletion doc/lsp-status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ config({config}) *lsp-status.config()*
accepted as the symbol currently containing the cursor.•
• `current_function`: Boolean, `true` if the current function
wbthomason marked this conversation as resolved.
Show resolved Hide resolved
should be updated and displayed in the default statusline
component.
component. Shows the current function, method, class,
struct, interface, enum, module, or namespace.
• `indicator_errors` : Symbol to place next to the error count
in `status` . Default: '',•
• `indicator_warnings` : Symbol to place next to the warning
Expand Down
14 changes: 13 additions & 1 deletion lua/lsp-status/current_function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ local function init(_, config)
_config = config
end

-- the symbol kinds which are valid scopes
local scope_kinds = {
Class = true,
Function = true,
Method = true,
Struct = true,
Enum = true,
Interface = true,
Namespace = true,
Module = true,
}

-- Find current function context
local function current_function_callback(_, _, result, _, _)
vim.b.lsp_current_function = ''
Expand All @@ -18,7 +30,7 @@ local function current_function_callback(_, _, result, _, _)

local function_symbols = util.filter(util.extract_symbols(result),
function(_, v)
return v.kind == 'Class' or v.kind == 'Function' or v.kind == 'Method'
return scope_kinds[v.kind]
end)

if not function_symbols or #function_symbols == 0 then
Expand Down