feat(lsp): exact-match support for lualine component (#52)

This commit is contained in:
Steven Arcangeli 2022-02-01 16:43:12 -08:00
parent 8e7911febd
commit f19e7484b4
4 changed files with 27 additions and 3 deletions

View file

@ -9,6 +9,7 @@ ignore = {
"212", -- Unused argument
"631", -- Line is too long
"122", -- Setting a readonly global
"542", -- Empty if branch
}
read_globals = {

View file

@ -30,6 +30,8 @@ local function process_symbols(symbols, bufnr)
parent = parent,
lnum = range.start.line + 1,
col = range.start.character,
end_lnum = range["end"].line + 1,
end_col = range["end"].character,
}
-- Skip this symbol if it's in the same location as the last one.

View file

@ -97,12 +97,18 @@ M.on_attach = function(...)
end
-- Returns a list representing the symbol path to the current location.
-- exact (bool): If true, only return symbols if we are exactly inside the
-- hierarchy. When false, will return the closest symbol.
-- Returns empty list if none found or in an invalid buffer.
-- Items have the following keys:
-- name The name of the symbol
-- kind The SymbolKind of the symbol
-- icon The icon that represents the symbol
M.get_location = function()
M.get_location = function(exact)
-- exact defaults to true
if exact == nil then
exact = true
end
if not data:has_symbols(0) then
return {}
end
@ -113,13 +119,27 @@ M.get_location = function()
return {}
end
local item = bufdata:item(pos.lnum)
local cur = vim.api.nvim_win_get_cursor(0)
local ret = {}
while item do
if exact then
if not item.end_lnum or not item.end_col then
-- end_lnum/end_col isn't supported by all backends yet
elseif
item.lnum > cur[1]
or item.end_lnum < cur[1]
or (item.lnum == cur[1] and item.col > cur[2])
or (item.end_lnum == cur[1] and item.end_col < cur[2])
then
goto continue
end
end
table.insert(ret, 1, {
kind = item.kind,
icon = config.get_icon(item.kind),
name = item.name,
})
::continue::
item = item.parent
end
return ret

View file

@ -47,6 +47,7 @@ local default_options = {
depth = nil,
dense = false,
dense_sep = ".",
exact = true,
}
local function format_status(symbols, depth, separator, icons_enabled)
@ -86,7 +87,7 @@ function M:update_status()
end
function M:get_status_normal()
local symbols = aerial.get_location()
local symbols = aerial.get_location(self.options.exact)
local status = format_status(
symbols,
self.options.depth,
@ -97,7 +98,7 @@ function M:get_status_normal()
end
function M:get_status_dense()
local symbols = aerial.get_location()
local symbols = aerial.get_location(self.options.exact)
local status = format_status(
symbols,
self.options.depth,