mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat: add refetch_symbols API method (#280)
This commit is contained in:
parent
cd446279f1
commit
1f15722857
2 changed files with 23 additions and 3 deletions
|
@ -86,13 +86,14 @@ end
|
|||
---@param bufnr? integer
|
||||
---@param backend? aerial.Backend
|
||||
---@param name? string
|
||||
---@return boolean
|
||||
local function attach(bufnr, backend, name)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
local existing_backend_name = M.get_attached_backend(bufnr)
|
||||
if not backend or not name or name == existing_backend_name then
|
||||
return
|
||||
return false
|
||||
end
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
|
@ -129,6 +130,7 @@ local function attach(bufnr, backend, name)
|
|||
if not existing_backend_name and config.on_attach then
|
||||
config.on_attach(bufnr)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---@param bufnr? integer
|
||||
|
@ -231,18 +233,20 @@ end
|
|||
|
||||
---@param bufnr? integer
|
||||
---@param refresh? boolean
|
||||
---@return boolean True if symbols were fetched
|
||||
M.attach = function(bufnr, refresh)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
return false
|
||||
end
|
||||
if refresh then
|
||||
local backend, name = get_best_backend()
|
||||
attach(bufnr, backend, name)
|
||||
return attach(bufnr, backend, name)
|
||||
else
|
||||
M.get(bufnr)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -276,6 +276,22 @@ M.toggle = function(opts)
|
|||
return opened
|
||||
end
|
||||
|
||||
---Refresh the symbols for a buffer
|
||||
---@param bufnr? integer
|
||||
---@note
|
||||
--- Symbols will usually get refreshed automatically when needed. You should only need to
|
||||
--- call this if you change something in the config (e.g. by setting vim.b.aerial_backends)
|
||||
M.refetch_symbols = function(bufnr)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
do_setup()
|
||||
local backends = require("aerial.backends")
|
||||
if not backends.attach(bufnr, true) then
|
||||
backends.get(bufnr).fetch_symbols(bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
---Jump to a specific symbol.
|
||||
---@param opts nil|table
|
||||
--- index nil|integer The symbol to jump to. If nil, will jump to the symbol under the cursor (in the aerial buffer)
|
||||
|
|
Loading…
Reference in a new issue