Skip to content

Commit

Permalink
feat: add refetch_symbols API method (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jul 29, 2023
1 parent cd44627 commit 1f15722
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/aerial/backends/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions lua/aerial/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1f15722

Please sign in to comment.