feat(api): Get symbol and breadcrumb at location

Currently the implementation is very limited.

Ref: #24

- Outline must be open and have been loaded for it to work (requires
  lazy loading or headless loading of Sidebar)
- Empty string returned if cursor is not in any symbol ('closest' symbol
  not yet supported)
- Line column not used
- Returning concatenated symbol names rather than a list of tables with
  node info (requires a refactor of outline.SymbolNode type)
- Subject to config.symbols.filter and folds (requires finding hover
  list somewhere outside of writer.make_outline)
This commit is contained in:
hedy
2023-11-25 14:48:38 +08:00
parent f586147ee2
commit 6cea72f2b5
7 changed files with 124 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ local Sidebar = {}
---@field view outline.View
---@field items outline.SymbolNode[]
---@field flats outline.FlatSymbolNode[]
---@field hovered outline.FlatSymbolNode[]
---@field original_cursor string
---@field code outline.SidebarCodeState
---@field autocmds { [integer]: integer } winnr to autocmd id
@@ -27,6 +28,7 @@ function Sidebar:new()
code = { buf = 0, win = 0 },
items = {},
flats = {},
hovered = {},
autocmds = {},
original_cursor = vim.o.guicursor,
}, { __index = Sidebar })
@@ -94,7 +96,7 @@ function Sidebar:initial_handler(response, opts)
self.items = items
local current
self.flats, current = writer.make_outline(self.view.bufnr, items, self.code.win)
self.flats, current, self.hovered = writer.make_outline(self.view.bufnr, items, self.code.win)
self:update_cursor_pos(current)
@@ -261,7 +263,7 @@ end
---@param set_cursor_to_node outline.SymbolNode|outline.FlatSymbolNode?
function Sidebar:_update_lines(update_cursor, set_cursor_to_node)
local current
self.flats, current =
self.flats, current, self.hovered =
writer.make_outline(self.view.bufnr, self.items, self.code.win, set_cursor_to_node)
if update_cursor ~= false then
self:update_cursor_pos(current)