mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
Format files with stylua
This commit is contained in:
parent
89f4097711
commit
ba8b030aaf
13 changed files with 350 additions and 356 deletions
12
README.md
12
README.md
|
@ -84,7 +84,7 @@ vim.g.aerial = {
|
|||
-- auto - aerial window will stay open as long as there is a visible
|
||||
-- buffer to attach to
|
||||
-- global - same as 'persist', and will always show symbols for the current buffer
|
||||
close_behavior = 'auto',
|
||||
close_behavior = "auto",
|
||||
|
||||
-- Set to false to remove the default keybindings for the aerial buffer
|
||||
default_bindings = true,
|
||||
|
@ -93,7 +93,7 @@ vim.g.aerial = {
|
|||
-- Determines the default direction to open the aerial window. The 'prefer'
|
||||
-- options will open the window in the other direction *if* there is a
|
||||
-- different buffer in the way of the preferred direction
|
||||
default_direction = 'prefer_right',
|
||||
default_direction = "prefer_right",
|
||||
|
||||
-- Set to true to only open aerial at the far right/left of the editor
|
||||
-- Default behavior opens aerial relative to current window
|
||||
|
@ -105,7 +105,7 @@ vim.g.aerial = {
|
|||
|
||||
-- Enum: split_width, full_width, last, none
|
||||
-- Determines line highlighting mode when multiple buffers are visible
|
||||
highlight_mode = 'split_width',
|
||||
highlight_mode = "split_width",
|
||||
|
||||
-- When jumping to a symbol, highlight the line for this many ms
|
||||
-- Set to 0 or false to disable
|
||||
|
@ -119,7 +119,7 @@ vim.g.aerial = {
|
|||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- 'auto' will manage folds if your previous foldmethod was 'manual'
|
||||
manage_folds = 'auto',
|
||||
manage_folds = "auto",
|
||||
|
||||
-- The maximum width of the aerial window
|
||||
max_width = 40,
|
||||
|
@ -129,7 +129,7 @@ vim.g.aerial = {
|
|||
min_width = 10,
|
||||
|
||||
-- Set default symbol icons to use Nerd Font icons (see https://www.nerdfonts.com/)
|
||||
nerd_font = 'auto',
|
||||
nerd_font = "auto",
|
||||
|
||||
-- Whether to open aerial automatically when entering a buffer.
|
||||
-- Can also be specified per-filetype as a map (see below)
|
||||
|
@ -143,7 +143,7 @@ vim.g.aerial = {
|
|||
open_automatic_min_symbols = 0,
|
||||
|
||||
-- Run this command after jumping to a symbol (false will disable)
|
||||
post_jump_cmd = 'normal! zz',
|
||||
post_jump_cmd = "normal! zz",
|
||||
|
||||
-- Set to false to not update the symbols when there are LSP errors
|
||||
update_when_errors = true,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
local callbacks = require 'aerial.callbacks'
|
||||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local fold = require 'aerial.fold'
|
||||
local nav = require 'aerial.navigation'
|
||||
local render = require 'aerial.render'
|
||||
local tree = require 'aerial.tree'
|
||||
local util = require 'aerial.util'
|
||||
local window = require 'aerial.window'
|
||||
local callbacks = require("aerial.callbacks")
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local fold = require("aerial.fold")
|
||||
local nav = require("aerial.navigation")
|
||||
local render = require("aerial.render")
|
||||
local tree = require("aerial.tree")
|
||||
local util = require("aerial.util")
|
||||
local window = require("aerial.window")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -20,12 +20,12 @@ end
|
|||
|
||||
M.open = function(focus, direction)
|
||||
-- We get empty strings from the vim command
|
||||
if focus == '' then
|
||||
if focus == "" then
|
||||
focus = true
|
||||
elseif focus == '!' then
|
||||
elseif focus == "!" then
|
||||
focus = false
|
||||
end
|
||||
if direction == '' then
|
||||
if direction == "" then
|
||||
direction = nil
|
||||
end
|
||||
window.open(focus, direction)
|
||||
|
@ -37,12 +37,12 @@ end
|
|||
|
||||
M.toggle = function(focus, direction)
|
||||
-- We get empty strings from the vim command
|
||||
if focus == '' then
|
||||
if focus == "" then
|
||||
focus = true
|
||||
elseif focus == '!' then
|
||||
elseif focus == "!" then
|
||||
focus = false
|
||||
end
|
||||
if direction == '' then
|
||||
if direction == "" then
|
||||
direction = nil
|
||||
end
|
||||
return window.toggle(focus, direction)
|
||||
|
@ -66,7 +66,7 @@ local function add_handler(preserve_callback)
|
|||
return
|
||||
end
|
||||
has_hook = true
|
||||
local old_callback = vim.lsp.handlers['textDocument/documentSymbol']
|
||||
local old_callback = vim.lsp.handlers["textDocument/documentSymbol"]
|
||||
local new_callback = callbacks.symbol_callback
|
||||
if preserve_callback then
|
||||
new_callback = function(...)
|
||||
|
@ -74,12 +74,12 @@ local function add_handler(preserve_callback)
|
|||
old_callback(...)
|
||||
end
|
||||
end
|
||||
vim.lsp.handlers['textDocument/documentSymbol'] = new_callback
|
||||
vim.lsp.handlers["textDocument/documentSymbol"] = new_callback
|
||||
end
|
||||
|
||||
M.on_attach = function(client, opts)
|
||||
opts = opts or {}
|
||||
if not client.supports_method('textDocument/documentSymbol') then
|
||||
if not client.supports_method("textDocument/documentSymbol") then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -87,28 +87,28 @@ M.on_attach = function(client, opts)
|
|||
|
||||
if config.link_folds_to_tree then
|
||||
local function map(key, cmd)
|
||||
vim.api.nvim_buf_set_keymap(0, 'n', key, cmd, {silent=true, noremap=true})
|
||||
vim.api.nvim_buf_set_keymap(0, "n", key, cmd, { silent = true, noremap = true })
|
||||
end
|
||||
|
||||
map('za', [[<cmd>AerialTreeToggle<CR>]])
|
||||
map('zA', [[<cmd>AerialTreeToggle!<CR>]])
|
||||
map('zo', [[<cmd>AerialTreeOpen<CR>]])
|
||||
map('zO', [[<cmd>AerialTreeOpen!<CR>]])
|
||||
map('zc', [[<cmd>AerialTreeClose<CR>]])
|
||||
map('zC', [[<cmd>AerialTreeClose!<CR>]])
|
||||
map('zM', [[<cmd>AerialTreeCloseAll<CR>]])
|
||||
map('zR', [[<cmd>AerialTreeOpenAll<CR>]])
|
||||
map('zx', [[<cmd>AerialTreeSyncFolds<CR>]])
|
||||
map('zX', [[<cmd>AerialTreeSyncFolds<CR>]])
|
||||
map("za", [[<cmd>AerialTreeToggle<CR>]])
|
||||
map("zA", [[<cmd>AerialTreeToggle!<CR>]])
|
||||
map("zo", [[<cmd>AerialTreeOpen<CR>]])
|
||||
map("zO", [[<cmd>AerialTreeOpen!<CR>]])
|
||||
map("zc", [[<cmd>AerialTreeClose<CR>]])
|
||||
map("zC", [[<cmd>AerialTreeClose!<CR>]])
|
||||
map("zM", [[<cmd>AerialTreeCloseAll<CR>]])
|
||||
map("zR", [[<cmd>AerialTreeOpenAll<CR>]])
|
||||
map("zx", [[<cmd>AerialTreeSyncFolds<CR>]])
|
||||
map("zX", [[<cmd>AerialTreeSyncFolds<CR>]])
|
||||
end
|
||||
|
||||
|
||||
local autocmd = [[augroup aerial
|
||||
au!
|
||||
au BufEnter * lua require'aerial.autocommands'.on_enter_buffer()
|
||||
]]
|
||||
if config.diagnostics_trigger_update then
|
||||
autocmd = autocmd .. [[
|
||||
autocmd = autocmd
|
||||
.. [[
|
||||
au User LspDiagnosticsChanged lua require'aerial.autocommands'.on_diagnostics_changed()
|
||||
]]
|
||||
end
|
||||
|
@ -118,7 +118,9 @@ M.on_attach = function(client, opts)
|
|||
vim.cmd(autocmd)
|
||||
|
||||
vim.cmd("autocmd CursorMoved <buffer> lua require'aerial.autocommands'.on_cursor_move()")
|
||||
vim.cmd([[autocmd BufDelete <buffer> call luaeval("require'aerial.autocommands'.on_buf_delete(_A)", expand('<abuf>'))]])
|
||||
vim.cmd(
|
||||
[[autocmd BufDelete <buffer> call luaeval("require'aerial.autocommands'.on_buf_delete(_A)", expand('<abuf>'))]]
|
||||
)
|
||||
if config.open_automatic() then
|
||||
if not config.diagnostics_trigger_update then
|
||||
vim.lsp.buf.document_symbol()
|
||||
|
@ -131,7 +133,7 @@ local function _post_tree_mutate(new_cursor_pos)
|
|||
window.update_all_positions()
|
||||
if util.is_aerial_buffer() then
|
||||
if new_cursor_pos then
|
||||
vim.api.nvim_win_set_cursor(0, {new_cursor_pos, 0})
|
||||
vim.api.nvim_win_set_cursor(0, { new_cursor_pos, 0 })
|
||||
end
|
||||
else
|
||||
window.update_position(0, true)
|
||||
|
@ -164,7 +166,7 @@ M.tree_open_all = function()
|
|||
end
|
||||
|
||||
M.tree_cmd = function(action, opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
index = nil,
|
||||
fold = true,
|
||||
})
|
||||
|
@ -192,12 +194,12 @@ M.sync_folds = function()
|
|||
local mywin = vim.api.nvim_get_current_win()
|
||||
if util.is_aerial_buffer() then
|
||||
local bufnr = util.get_source_buffer()
|
||||
for _,winid in ipairs(util.get_fixed_wins(bufnr)) do
|
||||
for _, winid in ipairs(util.get_fixed_wins(bufnr)) do
|
||||
fold.sync_tree_folds(winid)
|
||||
end
|
||||
else
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
for _,winid in ipairs(util.get_fixed_wins(bufnr)) do
|
||||
for _, winid in ipairs(util.get_fixed_wins(bufnr)) do
|
||||
fold.sync_tree_folds(winid)
|
||||
end
|
||||
end
|
||||
|
@ -207,7 +209,7 @@ end
|
|||
-- @deprecated
|
||||
M.set_open_automatic = function(ft_or_mapping, bool)
|
||||
local opts = vim.g.aerial or {}
|
||||
if type(ft_or_mapping) == 'table' then
|
||||
if type(ft_or_mapping) == "table" then
|
||||
opts.open_automatic = ft_or_mapping
|
||||
else
|
||||
opts.open_automatic[ft_or_mapping] = bool
|
||||
|
@ -225,7 +227,7 @@ end
|
|||
-- @deprecated.
|
||||
M.set_kind_abbr = function(kind_or_mapping, abbr)
|
||||
local opts = vim.g.aerial or {}
|
||||
if type(kind_or_mapping) == 'table' then
|
||||
if type(kind_or_mapping) == "table" then
|
||||
opts.icons = kind_or_mapping
|
||||
else
|
||||
if not opts.icons then
|
||||
|
@ -238,17 +240,17 @@ end
|
|||
|
||||
-- @deprecated. Use select()
|
||||
M.jump_to_loc = function(virt_winnr, split_cmd)
|
||||
nav.select{
|
||||
nav.select({
|
||||
split = virt_winnr > 1 and split_cmd or nil,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- @deprecated. Use select()
|
||||
M.scroll_to_loc = function(virt_winnr, split_cmd)
|
||||
nav.select{
|
||||
nav.select({
|
||||
split = virt_winnr > 1 and split_cmd or nil,
|
||||
jump = false,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- @deprecated. Use next()
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
-- Functions that are called in response to autocommands
|
||||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local fold = require 'aerial.fold'
|
||||
local util = require 'aerial.util'
|
||||
local render = require 'aerial.render'
|
||||
local window = require 'aerial.window'
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local fold = require("aerial.fold")
|
||||
local util = require("aerial.util")
|
||||
local render = require("aerial.render")
|
||||
local window = require("aerial.window")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function is_sticky(behavior)
|
||||
return behavior == 'persist' or behavior == 'global'
|
||||
return behavior == "persist" or behavior == "global"
|
||||
end
|
||||
|
||||
local function close_orphans()
|
||||
local orphans = util.get_aerial_orphans()
|
||||
for _,winid in ipairs(orphans) do
|
||||
for _, winid in ipairs(orphans) do
|
||||
if is_sticky(config.close_behavior) then
|
||||
render.clear_buffer(vim.api.nvim_win_get_buf(winid))
|
||||
else
|
||||
|
@ -31,14 +31,14 @@ M.on_enter_buffer = function()
|
|||
|
||||
-- If the user tried to open a non-aerial buffer inside the aerial window,
|
||||
-- close the window and re-open the buffer.
|
||||
mybuf = vim.api.nvim_get_current_buf()
|
||||
if vim.w.is_aerial_win and not util.is_aerial_buffer(mybuf) then
|
||||
vim.api.nvim_win_close(0, false)
|
||||
vim.api.nvim_set_current_buf(mybuf)
|
||||
end
|
||||
mybuf = vim.api.nvim_get_current_buf()
|
||||
if vim.w.is_aerial_win and not util.is_aerial_buffer(mybuf) then
|
||||
vim.api.nvim_win_close(0, false)
|
||||
vim.api.nvim_set_current_buf(mybuf)
|
||||
end
|
||||
|
||||
if not util.is_aerial_buffer(mybuf) then
|
||||
if config.close_behavior == 'close' then
|
||||
if config.close_behavior == "close" then
|
||||
close_orphans()
|
||||
end
|
||||
|
||||
|
@ -53,9 +53,11 @@ M.on_enter_buffer = function()
|
|||
end
|
||||
|
||||
if util.is_aerial_buffer(mybuf) then
|
||||
if (not is_sticky(config.close_behavior) and util.is_aerial_buffer_orphaned(mybuf))
|
||||
or vim.tbl_count(vim.api.nvim_list_wins()) == 1 then
|
||||
vim.cmd('quit')
|
||||
if
|
||||
(not is_sticky(config.close_behavior) and util.is_aerial_buffer_orphaned(mybuf))
|
||||
or vim.tbl_count(vim.api.nvim_list_wins()) == 1
|
||||
then
|
||||
vim.cmd("quit")
|
||||
else
|
||||
-- Hack to ignore winwidth
|
||||
vim.api.nvim_win_set_width(0, util.get_width())
|
||||
|
@ -68,7 +70,7 @@ M.on_enter_buffer = function()
|
|||
if not vim.tbl_isempty(orphans) then
|
||||
-- open our symbols in that window
|
||||
vim.defer_fn(function()
|
||||
window.open(false, nil, {winid = orphans[1]})
|
||||
window.open(false, nil, { winid = orphans[1] })
|
||||
end, 5)
|
||||
else
|
||||
vim.defer_fn(function()
|
||||
|
@ -86,11 +88,9 @@ M.on_diagnostics_changed = function()
|
|||
if not util.can_show_symbols() then
|
||||
return
|
||||
end
|
||||
local errors = vim.lsp.diagnostic.get_count(0, 'Error')
|
||||
local errors = vim.lsp.diagnostic.get_count(0, "Error")
|
||||
-- if no errors, refresh symbols
|
||||
if config.update_when_errors
|
||||
or errors == 0
|
||||
or not data:has_symbols() then
|
||||
if config.update_when_errors or errors == 0 or not data:has_symbols() then
|
||||
vim.lsp.buf.document_symbol()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local fold = require 'aerial.fold'
|
||||
local loading = require 'aerial.loading'
|
||||
local protocol = require 'vim.lsp.protocol'
|
||||
local render = require 'aerial.render'
|
||||
local util = require 'aerial.util'
|
||||
local window = require 'aerial.window'
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local fold = require("aerial.fold")
|
||||
local loading = require("aerial.loading")
|
||||
local protocol = require("vim.lsp.protocol")
|
||||
local render = require("aerial.render")
|
||||
local util = require("aerial.util")
|
||||
local window = require("aerial.window")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -73,9 +73,11 @@ end
|
|||
|
||||
local results = {}
|
||||
M.symbol_callback = function(_, _, result, _, bufnr)
|
||||
if not result or vim.tbl_isempty(result) then return end
|
||||
if not result or vim.tbl_isempty(result) then
|
||||
return
|
||||
end
|
||||
-- Don't update if there are diagnostics errors (or override by setting)
|
||||
local error_count = vim.lsp.diagnostic.get_count(bufnr, 'Error')
|
||||
local error_count = vim.lsp.diagnostic.get_count(bufnr, "Error")
|
||||
local has_symbols = data:has_symbols(bufnr)
|
||||
if not config.update_when_errors and error_count > 0 and has_symbols then
|
||||
return
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local M = {}
|
||||
local has_devicons = pcall(require, 'nvim-web-devicons')
|
||||
local has_devicons = pcall(require, "nvim-web-devicons")
|
||||
|
||||
-- Copy this to the README after modification
|
||||
local default_options = {
|
||||
|
@ -9,7 +9,7 @@ local default_options = {
|
|||
-- auto - aerial window will stay open as long as there is a visible
|
||||
-- buffer to attach to
|
||||
-- global - same as 'persist', and will always show symbols for the current buffer
|
||||
close_behavior = 'auto',
|
||||
close_behavior = "auto",
|
||||
|
||||
-- Set to false to remove the default keybindings for the aerial buffer
|
||||
default_bindings = true,
|
||||
|
@ -18,7 +18,7 @@ local default_options = {
|
|||
-- Determines the default direction to open the aerial window. The 'prefer'
|
||||
-- options will open the window in the other direction *if* there is a
|
||||
-- different buffer in the way of the preferred direction
|
||||
default_direction = 'prefer_right',
|
||||
default_direction = "prefer_right",
|
||||
|
||||
-- Set to true to only open aerial at the far right/left of the editor
|
||||
-- Default behavior opens aerial relative to current window
|
||||
|
@ -30,7 +30,7 @@ local default_options = {
|
|||
|
||||
-- Enum: split_width, full_width, last, none
|
||||
-- Determines line highlighting mode when multiple buffers are visible
|
||||
highlight_mode = 'split_width',
|
||||
highlight_mode = "split_width",
|
||||
|
||||
-- When jumping to a symbol, highlight the line for this many ms
|
||||
-- Set to 0 or false to disable
|
||||
|
@ -44,7 +44,7 @@ local default_options = {
|
|||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- 'auto' will manage folds if your previous foldmethod was 'manual'
|
||||
manage_folds = 'auto',
|
||||
manage_folds = "auto",
|
||||
|
||||
-- The maximum width of the aerial window
|
||||
max_width = 40,
|
||||
|
@ -54,7 +54,7 @@ local default_options = {
|
|||
min_width = 10,
|
||||
|
||||
-- Set default symbol icons to use Nerd Font icons (see https://www.nerdfonts.com/)
|
||||
nerd_font = 'auto',
|
||||
nerd_font = "auto",
|
||||
|
||||
-- Whether to open aerial automatically when entering a buffer.
|
||||
-- Can also be specified per-filetype as a map (see below)
|
||||
|
@ -68,7 +68,7 @@ local default_options = {
|
|||
open_automatic_min_symbols = 0,
|
||||
|
||||
-- Run this command after jumping to a symbol (false will disable)
|
||||
post_jump_cmd = 'normal! zz',
|
||||
post_jump_cmd = "normal! zz",
|
||||
|
||||
-- Set to false to not update the symbols when there are LSP errors
|
||||
update_when_errors = true,
|
||||
|
@ -96,12 +96,12 @@ local addl_bool_opts = {
|
|||
}
|
||||
|
||||
local function get_option(opt)
|
||||
local ret = vim.g[string.format('aerial_%s', opt)]
|
||||
local ret = vim.g[string.format("aerial_%s", opt)]
|
||||
if ret == nil then
|
||||
ret = (vim.g.aerial or {})[opt]
|
||||
end
|
||||
-- People are used to using 0 for v:false in vimscript
|
||||
if ret == 0 and (type(default_options[opt]) == 'boolean' or addl_bool_opts[opt]) then
|
||||
if ret == 0 and (type(default_options[opt]) == "boolean" or addl_bool_opts[opt]) then
|
||||
ret = false
|
||||
end
|
||||
if ret == nil then
|
||||
|
@ -114,11 +114,11 @@ end
|
|||
setmetatable(M, {
|
||||
__index = function(_, opt)
|
||||
return get_option(opt)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function get_table_default(table, key, default_key, default)
|
||||
if type(table) ~= 'table' then
|
||||
if type(table) ~= "table" then
|
||||
return table
|
||||
end
|
||||
local ret = table[key]
|
||||
|
@ -142,12 +142,13 @@ M.include_kind = function(kind)
|
|||
end
|
||||
|
||||
M.open_automatic = function()
|
||||
local ft = vim.api.nvim_buf_get_option(0, 'filetype')
|
||||
local ret = get_table_opt('open_automatic', ft, '_', false)
|
||||
local ft = vim.api.nvim_buf_get_option(0, "filetype")
|
||||
local ret = get_table_opt("open_automatic", ft, "_", false)
|
||||
-- People are used to using 0 for v:false in vimscript
|
||||
return ret and ret ~= 0
|
||||
end
|
||||
|
||||
-- stylua: ignore
|
||||
local plain_icons = {
|
||||
Array = '[a]';
|
||||
Boolean = '[b]';
|
||||
|
@ -178,6 +179,7 @@ local plain_icons = {
|
|||
Collapsed = '▶';
|
||||
}
|
||||
|
||||
-- stylua: ignore
|
||||
local nerd_icons = {
|
||||
Class = '';
|
||||
Constructor = '';
|
||||
|
@ -203,22 +205,22 @@ M.get_icon = function(kind, collapsed)
|
|||
local icons = _last_icons
|
||||
if vim.fn.localtime() - _last_checked > 5 then
|
||||
local default
|
||||
local nerd_font = get_option('nerd_font')
|
||||
if nerd_font == 'auto' then
|
||||
local nerd_font = get_option("nerd_font")
|
||||
if nerd_font == "auto" then
|
||||
nerd_font = has_devicons
|
||||
end
|
||||
if nerd_font then
|
||||
default = vim.tbl_extend('keep', nerd_icons, plain_icons)
|
||||
default = vim.tbl_extend("keep", nerd_icons, plain_icons)
|
||||
else
|
||||
default = plain_icons
|
||||
end
|
||||
icons = vim.tbl_extend('keep', M.icons or {}, default)
|
||||
icons = vim.tbl_extend("keep", M.icons or {}, default)
|
||||
_last_icons = icons
|
||||
_last_checked = vim.fn.localtime()
|
||||
end
|
||||
|
||||
if collapsed then
|
||||
return get_table_default(icons, kind..'Collapsed', 'Collapsed', kind)
|
||||
return get_table_default(icons, kind .. "Collapsed", "Collapsed", kind)
|
||||
else
|
||||
return get_table_default(icons, kind, nil, kind)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local util = require 'aerial.util'
|
||||
local util = require("aerial.util")
|
||||
|
||||
local BufData = {
|
||||
new = function(t)
|
||||
|
@ -8,7 +8,7 @@ local BufData = {
|
|||
last_position = 1,
|
||||
collapsed = {},
|
||||
}
|
||||
setmetatable(new, {__index = t})
|
||||
setmetatable(new, { __index = t })
|
||||
return new
|
||||
end,
|
||||
|
||||
|
@ -59,7 +59,7 @@ local BufData = {
|
|||
end,
|
||||
|
||||
is_collapsable = function(_, item)
|
||||
return item.level == 0 or (item.children and not vim.tbl_isempty(item.children))
|
||||
return item.level == 0 or (item.children and not vim.tbl_isempty(item.children))
|
||||
end,
|
||||
|
||||
get_root_of = function(_, item)
|
||||
|
@ -77,23 +77,28 @@ local BufData = {
|
|||
end,
|
||||
|
||||
visit = function(self, callback, opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
incl_hidden = false,
|
||||
})
|
||||
local function visit_item(item)
|
||||
local ret = callback(item, self:_get_config(item))
|
||||
if ret then return ret end
|
||||
if item.children
|
||||
and (opts.incl_hidden or not self:is_collapsed(item)) then
|
||||
for _,child in ipairs(item.children) do
|
||||
if ret then
|
||||
return ret
|
||||
end
|
||||
if item.children and (opts.incl_hidden or not self:is_collapsed(item)) then
|
||||
for _, child in ipairs(item.children) do
|
||||
ret = visit_item(child)
|
||||
if ret then return ret end
|
||||
if ret then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for _,item in ipairs(self.items) do
|
||||
for _, item in ipairs(self.items) do
|
||||
local ret = visit_item(item)
|
||||
if ret then return ret end
|
||||
if ret then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
|
@ -111,7 +116,7 @@ local BufData = {
|
|||
local count = 0
|
||||
self:visit(function(_)
|
||||
count = count + 1
|
||||
end, {incl_hidden = incl_hidden})
|
||||
end, { incl_hidden = incl_hidden })
|
||||
return count
|
||||
end,
|
||||
}
|
||||
|
@ -125,7 +130,7 @@ local Data = setmetatable({}, {
|
|||
t[bufnr] = bufdata
|
||||
end
|
||||
return bufdata
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
function Data:has_symbols(bufnr)
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local util = require 'aerial.util'
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local util = require("aerial.util")
|
||||
local M = {}
|
||||
|
||||
M.foldexpr = function(lnum, debug)
|
||||
if util.is_aerial_buffer() then
|
||||
return '0'
|
||||
return "0"
|
||||
end
|
||||
if not data:has_symbols(0) then
|
||||
return '0'
|
||||
return "0"
|
||||
end
|
||||
local bufdata = data[0]
|
||||
local lastItem = {}
|
||||
local foldItem = {level = -1}
|
||||
local foldItem = { level = -1 }
|
||||
bufdata:visit(function(item)
|
||||
lastItem = item
|
||||
if item.lnum > lnum then
|
||||
|
@ -20,12 +20,14 @@ M.foldexpr = function(lnum, debug)
|
|||
elseif bufdata:is_collapsable(item) then
|
||||
foldItem = item
|
||||
end
|
||||
end, {incl_hidden = true})
|
||||
end, {
|
||||
incl_hidden = true,
|
||||
})
|
||||
local levelstr = string.format("%d", foldItem.level + 1)
|
||||
if lnum == foldItem.lnum then
|
||||
levelstr = '>' .. levelstr
|
||||
elseif vim.api.nvim_buf_get_lines(0, lnum-1, lnum, true)[1] == '' then
|
||||
levelstr = '-1'
|
||||
levelstr = ">" .. levelstr
|
||||
elseif vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1] == "" then
|
||||
levelstr = "-1"
|
||||
end
|
||||
|
||||
if debug then
|
||||
|
@ -34,8 +36,8 @@ M.foldexpr = function(lnum, debug)
|
|||
return levelstr
|
||||
end
|
||||
|
||||
local prev_fdm = '_aerial_prev_foldmethod'
|
||||
local prev_fde = '_aerial_prev_foldexpr'
|
||||
local prev_fdm = "_aerial_prev_foldmethod"
|
||||
local prev_fde = "_aerial_prev_foldexpr"
|
||||
M.restore_foldmethod = function()
|
||||
local ok, prev_foldmethod = pcall(vim.api.nvim_win_get_var, 0, prev_fdm)
|
||||
if ok and prev_foldmethod then
|
||||
|
@ -61,17 +63,16 @@ M.maybe_set_foldmethod = function(bufnr)
|
|||
if bufnr then
|
||||
winids = util.get_fixed_wins(bufnr)
|
||||
else
|
||||
winids = {vim.api.nvim_get_current_win()}
|
||||
winids = { vim.api.nvim_get_current_win() }
|
||||
end
|
||||
for _,winid in ipairs(winids) do
|
||||
local fdm = vim.api.nvim_win_get_option(winid, 'foldmethod')
|
||||
local fde = vim.api.nvim_win_get_option(winid, 'foldexpr')
|
||||
if manage_folds == true or manage_folds == 1
|
||||
or (manage_folds == 'auto' and fdm == 'manual') then
|
||||
for _, winid in ipairs(winids) do
|
||||
local fdm = vim.api.nvim_win_get_option(winid, "foldmethod")
|
||||
local fde = vim.api.nvim_win_get_option(winid, "foldexpr")
|
||||
if manage_folds == true or manage_folds == 1 or (manage_folds == "auto" and fdm == "manual") then
|
||||
vim.api.nvim_win_set_var(winid, prev_fdm, fdm)
|
||||
vim.api.nvim_win_set_var(winid, prev_fde, fde)
|
||||
vim.api.nvim_win_set_option(winid, 'foldmethod', 'expr')
|
||||
vim.api.nvim_win_set_option(winid, 'foldexpr', 'aerial#foldexpr()')
|
||||
vim.api.nvim_win_set_option(winid, "foldmethod", "expr")
|
||||
vim.api.nvim_win_set_option(winid, "foldexpr", "aerial#foldexpr()")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -82,16 +83,16 @@ M.sync_tree_folds = function(winid)
|
|||
end
|
||||
util.go_win_no_au(winid)
|
||||
local view = vim.fn.winsaveview()
|
||||
vim.cmd('normal! zxzR')
|
||||
vim.cmd("normal! zxzR")
|
||||
local bufdata = data[0]
|
||||
local items = bufdata:flatten(nil, {incl_hidden = true})
|
||||
local items = bufdata:flatten(nil, { incl_hidden = true })
|
||||
table.sort(items, function(a, b)
|
||||
return a.level > b.level
|
||||
end)
|
||||
for _,item in ipairs(items) do
|
||||
for _, item in ipairs(items) do
|
||||
if bufdata:is_collapsed(item) then
|
||||
vim.api.nvim_win_set_cursor(0, {item.lnum, 0})
|
||||
vim.cmd('normal! zc')
|
||||
vim.api.nvim_win_set_cursor(0, { item.lnum, 0 })
|
||||
vim.cmd("normal! zc")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -107,33 +108,33 @@ local function win_do_action(winid, action, lnum, recurse)
|
|||
return
|
||||
end
|
||||
local view = vim.fn.winsaveview()
|
||||
vim.api.nvim_win_set_cursor(0, {lnum, 0})
|
||||
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
|
||||
local key
|
||||
if action == 'open' then
|
||||
key = 'o'
|
||||
elseif action == 'close' then
|
||||
key = 'c'
|
||||
elseif action == 'toggle' then
|
||||
key = 'a'
|
||||
if action == "open" then
|
||||
key = "o"
|
||||
elseif action == "close" then
|
||||
key = "c"
|
||||
elseif action == "toggle" then
|
||||
key = "a"
|
||||
end
|
||||
if key and recurse then
|
||||
key = string.upper(key)
|
||||
end
|
||||
if key then
|
||||
vim.cmd('normal! z' .. key)
|
||||
vim.cmd("normal! z" .. key)
|
||||
end
|
||||
vim.fn.winrestview(view)
|
||||
end
|
||||
|
||||
M.fold_action = function(action, lnum, opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
recurse = false,
|
||||
})
|
||||
local my_winid = vim.api.nvim_get_current_win()
|
||||
local wins
|
||||
local bufnr, _ = util.get_buffers()
|
||||
wins = util.get_fixed_wins(bufnr)
|
||||
for _,winid in ipairs(wins) do
|
||||
for _, winid in ipairs(wins) do
|
||||
if util.is_managing_folds(winid) then
|
||||
win_do_action(winid, action, lnum, opts.recurse)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local util = require 'aerial.util'
|
||||
local util = require("aerial.util")
|
||||
local M = {}
|
||||
|
||||
local timers = {}
|
||||
|
@ -14,15 +14,19 @@ M.set_loading = function(aer_bufnr, is_loading)
|
|||
timers[aer_bufnr] = vim.loop.new_timer()
|
||||
local i = 0
|
||||
local start = vim.fn.localtime()
|
||||
timers[aer_bufnr]:start(0, 80, vim.schedule_wrap(function()
|
||||
local lines = {M.spinner_frames[i+1] .. ' Loading'}
|
||||
if vim.fn.localtime() - start >= SLOW_TIMEOUT then
|
||||
table.insert(lines, "stuck?")
|
||||
table.insert(lines, ":help aerial-loading")
|
||||
end
|
||||
util.render_centered_text(aer_bufnr, lines)
|
||||
i = (i + 1) % #M.spinner_frames
|
||||
end))
|
||||
timers[aer_bufnr]:start(
|
||||
0,
|
||||
80,
|
||||
vim.schedule_wrap(function()
|
||||
local lines = { M.spinner_frames[i + 1] .. " Loading" }
|
||||
if vim.fn.localtime() - start >= SLOW_TIMEOUT then
|
||||
table.insert(lines, "stuck?")
|
||||
table.insert(lines, ":help aerial-loading")
|
||||
end
|
||||
util.render_centered_text(aer_bufnr, lines)
|
||||
i = (i + 1) % #M.spinner_frames
|
||||
end)
|
||||
)
|
||||
end
|
||||
else
|
||||
if timers[aer_bufnr] then
|
||||
|
@ -42,6 +46,7 @@ end
|
|||
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
-- stylua: ignore
|
||||
M.spinner_frames = {
|
||||
"⢀⠀", "⡀⠀", "⠄⠀", "⢂⠀", "⡂⠀", "⠅⠀", "⢃⠀", "⡃⠀", "⠍⠀",
|
||||
"⢋⠀", "⡋⠀", "⠍⠁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local data = require 'aerial.data'
|
||||
local util = require 'aerial.util'
|
||||
local config = require 'aerial.config'
|
||||
local window = require 'aerial.window'
|
||||
local data = require("aerial.data")
|
||||
local util = require("aerial.util")
|
||||
local config = require("aerial.config")
|
||||
local window = require("aerial.window")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -62,7 +62,7 @@ M.up = function(direction, count)
|
|||
local bufdata = data[bufnr]
|
||||
|
||||
local index = 1
|
||||
-- We're going up and BACKWARDS
|
||||
-- We're going up and BACKWARDS
|
||||
if direction < 0 then
|
||||
local prev_root_index
|
||||
local last_root_index
|
||||
|
@ -86,7 +86,7 @@ M.up = function(direction, count)
|
|||
index = prev_root_index or last_root_index
|
||||
else
|
||||
-- Otherwise, it's a simple tree traversal
|
||||
for _=1,count do
|
||||
for _ = 1, count do
|
||||
if not item.parent then
|
||||
break
|
||||
end
|
||||
|
@ -114,13 +114,13 @@ M.up = function(direction, count)
|
|||
index = 1
|
||||
end
|
||||
end
|
||||
M.select{
|
||||
M.select({
|
||||
index = index,
|
||||
jump = false,
|
||||
winid = winid,
|
||||
}
|
||||
})
|
||||
if util.is_aerial_buffer() then
|
||||
vim.api.nvim_win_set_cursor(0, {index, 0})
|
||||
vim.api.nvim_win_set_cursor(0, { index, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,24 +140,24 @@ M.next = function(step)
|
|||
local count = data[bufnr]:count()
|
||||
-- If we're not *exactly* on a location, make sure we hit the nearest location
|
||||
-- first even if we're currently considered to be "on" it
|
||||
if step < 0 and pos.relative == 'below' then
|
||||
if step < 0 and pos.relative == "below" then
|
||||
step = step + 1
|
||||
elseif step > 0 and pos.relative == 'above' then
|
||||
elseif step > 0 and pos.relative == "above" then
|
||||
step = step - 1
|
||||
end
|
||||
local new_num = ((pos.lnum + step - 1) % count) + 1
|
||||
M.select{
|
||||
M.select({
|
||||
index = new_num,
|
||||
jump = false,
|
||||
winid = winid,
|
||||
}
|
||||
})
|
||||
if util.is_aerial_buffer() then
|
||||
vim.api.nvim_win_set_cursor(0, {new_num, 0})
|
||||
vim.api.nvim_win_set_cursor(0, { new_num, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
M.select = function(opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
index = nil,
|
||||
split = nil,
|
||||
jump = true,
|
||||
|
@ -188,10 +188,10 @@ M.select = function(opts)
|
|||
|
||||
if opts.split then
|
||||
local split = opts.split
|
||||
if split == 'vertical' or split == 'v' then
|
||||
split = 'belowright vsplit'
|
||||
elseif split == 'horizontal' or split == 'h' or split == 's' then
|
||||
split = 'belowright split'
|
||||
if split == "vertical" or split == "v" then
|
||||
split = "belowright vsplit"
|
||||
elseif split == "horizontal" or split == "h" or split == "s" then
|
||||
split = "belowright split"
|
||||
end
|
||||
local my_winid = vim.api.nvim_get_current_win()
|
||||
util.go_win_no_au(winid)
|
||||
|
@ -201,9 +201,9 @@ M.select = function(opts)
|
|||
end
|
||||
local bufnr, _ = util.get_buffers()
|
||||
vim.api.nvim_win_set_buf(winid, bufnr)
|
||||
vim.api.nvim_win_set_cursor(winid, {item.lnum, item.col})
|
||||
vim.api.nvim_win_set_cursor(winid, { item.lnum, item.col })
|
||||
local cmd = config.post_jump_cmd
|
||||
if cmd and cmd ~= '' then
|
||||
if cmd and cmd ~= "" then
|
||||
vim.fn.win_execute(winid, cmd, true)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local loading = require 'aerial.loading'
|
||||
local util = require 'aerial.util'
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local loading = require("aerial.loading")
|
||||
local util = require("aerial.util")
|
||||
local M = {}
|
||||
|
||||
M.clear_buffer = function(bufnr)
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {})
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
end
|
||||
|
||||
-- Update the aerial buffer from cached symbols
|
||||
|
@ -17,7 +17,7 @@ M.update_aerial_buffer = function(buf)
|
|||
return
|
||||
end
|
||||
if not data:has_symbols(bufnr) then
|
||||
local lines = {"No symbols"}
|
||||
local lines = { "No symbols" }
|
||||
if config.filter_kind ~= false then
|
||||
table.insert(lines, ":help filter_kind")
|
||||
end
|
||||
|
@ -30,17 +30,17 @@ M.update_aerial_buffer = function(buf)
|
|||
local highlights = {}
|
||||
data[bufnr]:visit(function(item, conf)
|
||||
local kind = config.get_icon(item.kind, conf.collapsed)
|
||||
local spacing = string.rep(' ', item.level)
|
||||
local spacing = string.rep(" ", item.level)
|
||||
local text = string.format("%s%s %s", spacing, kind, item.name)
|
||||
local strlen = vim.fn.strdisplaywidth(text)
|
||||
table.insert(highlights, {
|
||||
group = 'Aerial' .. item.kind .. 'Icon',
|
||||
group = "Aerial" .. item.kind .. "Icon",
|
||||
row = row,
|
||||
col_start = string.len(spacing),
|
||||
col_end = string.len(spacing) + string.len(kind),
|
||||
})
|
||||
table.insert(highlights, {
|
||||
group = 'Aerial' .. item.kind,
|
||||
group = "Aerial" .. item.kind,
|
||||
row = row,
|
||||
col_start = strlen - string.len(item.name),
|
||||
col_end = strlen,
|
||||
|
@ -54,31 +54,24 @@ M.update_aerial_buffer = function(buf)
|
|||
util.set_width(aer_bufnr, width)
|
||||
|
||||
-- Insert lines into buffer
|
||||
for i,line in ipairs(lines) do
|
||||
for i, line in ipairs(lines) do
|
||||
lines[i] = util.rpad(line, width)
|
||||
end
|
||||
vim.api.nvim_buf_set_option(aer_bufnr, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_option(aer_bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(aer_bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_option(aer_bufnr, 'modifiable', false)
|
||||
vim.api.nvim_buf_set_option(aer_bufnr, "modifiable", false)
|
||||
|
||||
local ns = vim.api.nvim_create_namespace('aerial')
|
||||
local ns = vim.api.nvim_create_namespace("aerial")
|
||||
vim.api.nvim_buf_clear_namespace(aer_bufnr, ns, 0, -1)
|
||||
for _, hl in ipairs(highlights) do
|
||||
vim.api.nvim_buf_add_highlight(
|
||||
aer_bufnr,
|
||||
ns,
|
||||
hl.group,
|
||||
hl.row - 1,
|
||||
hl.col_start,
|
||||
hl.col_end
|
||||
)
|
||||
vim.api.nvim_buf_add_highlight(aer_bufnr, ns, hl.group, hl.row - 1, hl.col_start, hl.col_end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the highlighted lines in the aerial buffer
|
||||
M.update_highlights = function(buf)
|
||||
local hl_mode = config.highlight_mode
|
||||
if not hl_mode or hl_mode == 'none' then
|
||||
if not hl_mode or hl_mode == "none" then
|
||||
return
|
||||
end
|
||||
local bufnr, aer_bufnr = util.get_buffers(buf)
|
||||
|
@ -87,41 +80,29 @@ M.update_highlights = function(buf)
|
|||
end
|
||||
local bufdata = data[bufnr]
|
||||
local winids = util.get_fixed_wins(bufnr)
|
||||
local ns = vim.api.nvim_create_namespace('aerial-line')
|
||||
local ns = vim.api.nvim_create_namespace("aerial-line")
|
||||
vim.api.nvim_buf_clear_namespace(aer_bufnr, ns, 0, -1)
|
||||
if vim.tbl_isempty(winids) then
|
||||
return
|
||||
end
|
||||
local hl_width = math.floor(util.get_width(aer_bufnr) / #winids)
|
||||
|
||||
if hl_mode == 'last' then
|
||||
if hl_mode == "last" then
|
||||
local row = data[bufnr].last_position
|
||||
vim.api.nvim_buf_add_highlight(
|
||||
aer_bufnr,
|
||||
ns,
|
||||
'AerialLine',
|
||||
row - 1,
|
||||
0,
|
||||
-1)
|
||||
vim.api.nvim_buf_add_highlight(aer_bufnr, ns, "AerialLine", row - 1, 0, -1)
|
||||
return
|
||||
end
|
||||
|
||||
local start_hl = 0
|
||||
local end_hl = hl_mode == 'full_width' and -1 or hl_width
|
||||
for i,winid in ipairs(winids) do
|
||||
local end_hl = hl_mode == "full_width" and -1 or hl_width
|
||||
for i, winid in ipairs(winids) do
|
||||
-- To fix rounding errors when #windows doesn't divide evenly into the
|
||||
-- width, make sure the last highlight goes to the end
|
||||
if i == #winids then
|
||||
end_hl = -1
|
||||
end
|
||||
vim.api.nvim_buf_add_highlight(
|
||||
aer_bufnr,
|
||||
ns,
|
||||
'AerialLine',
|
||||
bufdata.positions[winid].lnum - 1,
|
||||
start_hl,
|
||||
end_hl)
|
||||
if hl_mode ~= 'full_width' then
|
||||
vim.api.nvim_buf_add_highlight(aer_bufnr, ns, "AerialLine", bufdata.positions[winid].lnum - 1, start_hl, end_hl)
|
||||
if hl_mode ~= "full_width" then
|
||||
start_hl = end_hl
|
||||
end_hl = end_hl + hl_width
|
||||
end
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
local M = {}
|
||||
|
||||
|
||||
local function _get_target(bufdata, action, item, bubble)
|
||||
if not bubble then
|
||||
return item
|
||||
end
|
||||
while item and
|
||||
(not bufdata:is_collapsable(item)
|
||||
or (action == 'close' and bufdata:is_collapsed(item))) do
|
||||
while item and (not bufdata:is_collapsable(item) or (action == "close" and bufdata:is_collapsed(item))) do
|
||||
item = item.parent
|
||||
end
|
||||
return item
|
||||
|
@ -26,7 +23,7 @@ M.open_all = function(bufdata)
|
|||
end
|
||||
|
||||
M.edit_tree_node = function(bufdata, action, index, opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
bubble = true,
|
||||
recurse = false,
|
||||
})
|
||||
|
@ -36,18 +33,18 @@ M.edit_tree_node = function(bufdata, action, index, opts)
|
|||
return
|
||||
end
|
||||
local is_collapsed = bufdata:is_collapsed(item)
|
||||
if action == 'toggle' then
|
||||
action = is_collapsed and 'open' or 'close'
|
||||
if action == "toggle" then
|
||||
action = is_collapsed and "open" or "close"
|
||||
end
|
||||
if action == 'open' then
|
||||
if action == "open" then
|
||||
did_update = did_update or is_collapsed
|
||||
bufdata:set_collapsed(item, false)
|
||||
if opts.recurse then
|
||||
for _,child in ipairs(item.children) do
|
||||
for _, child in ipairs(item.children) do
|
||||
do_action(child)
|
||||
end
|
||||
end
|
||||
elseif action == 'close' then
|
||||
elseif action == "close" then
|
||||
did_update = did_update or not is_collapsed
|
||||
bufdata:set_collapsed(item, true)
|
||||
if opts.recurse and item.parent then
|
||||
|
@ -64,5 +61,4 @@ M.edit_tree_node = function(bufdata, action, index, opts)
|
|||
return did_update, bufdata:indexof(item)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
local config = require 'aerial.config'
|
||||
local config = require("aerial.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.rpad = function(str, length, padchar)
|
||||
local strlen = vim.fn.strdisplaywidth(str)
|
||||
if strlen < length then
|
||||
return str .. string.rep(padchar or ' ', length - strlen)
|
||||
return str .. string.rep(padchar or " ", length - strlen)
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
M.lpad = function(str, length, padchar)
|
||||
if string.len(str) < length then
|
||||
return string.rep(padchar or ' ', length - string.len(str)) .. str
|
||||
return string.rep(padchar or " ", length - string.len(str)) .. str
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
M.get_width = function(bufnr)
|
||||
local ok, width = pcall(vim.api.nvim_buf_get_var, bufnr or 0, 'aerial_width')
|
||||
local ok, width = pcall(vim.api.nvim_buf_get_var, bufnr or 0, "aerial_width")
|
||||
if ok then
|
||||
return width
|
||||
end
|
||||
|
@ -29,16 +29,16 @@ M.set_width = function(bufnr, width)
|
|||
if M.get_width(bufnr) == width then
|
||||
return
|
||||
end
|
||||
vim.api.nvim_buf_set_var(bufnr, 'aerial_width', width)
|
||||
vim.api.nvim_buf_set_var(bufnr, "aerial_width", width)
|
||||
|
||||
for _,winid in ipairs(vim.fn.win_findbuf(bufnr)) do
|
||||
for _, winid in ipairs(vim.fn.win_findbuf(bufnr)) do
|
||||
vim.api.nvim_win_set_width(winid, width)
|
||||
end
|
||||
end
|
||||
|
||||
M.is_aerial_buffer = function(bufnr)
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr or 0, 'filetype')
|
||||
return ft == 'aerial'
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr or 0, "filetype")
|
||||
return ft == "aerial"
|
||||
end
|
||||
|
||||
M.go_win_no_au = function(winid)
|
||||
|
@ -55,7 +55,7 @@ end
|
|||
|
||||
M.get_aerial_orphans = function()
|
||||
local orphans = {}
|
||||
for _,winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local winbuf = vim.api.nvim_win_get_buf(winid)
|
||||
if M.is_aerial_buffer(winbuf) and M.is_aerial_buffer_orphaned(winbuf) then
|
||||
table.insert(orphans, winid)
|
||||
|
@ -69,10 +69,10 @@ M.is_aerial_buffer_orphaned = function(bufnr)
|
|||
if sourcebuf == -1 then
|
||||
return true
|
||||
end
|
||||
if config.close_behavior == 'global' and not M.is_aerial_buffer() then
|
||||
return sourcebuf ~= vim.api.nvim_get_current_buf();
|
||||
if config.close_behavior == "global" and not M.is_aerial_buffer() then
|
||||
return sourcebuf ~= vim.api.nvim_get_current_buf()
|
||||
end
|
||||
for _,winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if vim.api.nvim_win_get_buf(winid) == sourcebuf then
|
||||
return false
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ M.is_aerial_buffer_orphaned = function(bufnr)
|
|||
end
|
||||
|
||||
M.get_aerial_buffer = function(bufnr)
|
||||
return M.get_buffer_from_var(bufnr or 0, 'aerial_buffer')
|
||||
return M.get_buffer_from_var(bufnr or 0, "aerial_buffer")
|
||||
end
|
||||
|
||||
M.get_buffers = function(bufnr)
|
||||
|
@ -96,7 +96,7 @@ M.get_buffers = function(bufnr)
|
|||
end
|
||||
|
||||
M.get_source_buffer = function(bufnr)
|
||||
return M.get_buffer_from_var(bufnr or 0, 'source_buffer')
|
||||
return M.get_buffer_from_var(bufnr or 0, "source_buffer")
|
||||
end
|
||||
|
||||
M.get_buffer_from_var = function(bufnr, varname)
|
||||
|
@ -108,7 +108,7 @@ M.get_buffer_from_var = function(bufnr, varname)
|
|||
end
|
||||
|
||||
M.flash_highlight = function(bufnr, lnum, durationMs, hl_group)
|
||||
hl_group = hl_group or 'AerialLine'
|
||||
hl_group = hl_group or "AerialLine"
|
||||
if durationMs == true or durationMs == 1 then
|
||||
durationMs = 300
|
||||
end
|
||||
|
@ -120,7 +120,7 @@ M.flash_highlight = function(bufnr, lnum, durationMs, hl_group)
|
|||
end
|
||||
|
||||
M.tbl_indexof = function(tbl, value)
|
||||
for i,v in ipairs(tbl) do
|
||||
for i, v in ipairs(tbl) do
|
||||
if value == v then
|
||||
return i
|
||||
end
|
||||
|
@ -129,9 +129,8 @@ end
|
|||
|
||||
M.get_fixed_wins = function(bufnr)
|
||||
local wins = {}
|
||||
for _,winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if not M.is_floating_win(winid)
|
||||
and (not bufnr or vim.api.nvim_win_get_buf(winid) == bufnr) then
|
||||
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if not M.is_floating_win(winid) and (not bufnr or vim.api.nvim_win_get_buf(winid) == bufnr) then
|
||||
table.insert(wins, winid)
|
||||
end
|
||||
end
|
||||
|
@ -143,15 +142,15 @@ M.is_floating_win = function(winid)
|
|||
end
|
||||
|
||||
M.is_managing_folds = function(winid)
|
||||
return vim.api.nvim_win_get_option(winid or 0, 'foldexpr') == 'aerial#foldexpr()'
|
||||
return vim.api.nvim_win_get_option(winid or 0, "foldexpr") == "aerial#foldexpr()"
|
||||
end
|
||||
|
||||
M.detect_split_direction = function(bufnr)
|
||||
local default = config.default_direction
|
||||
if default == 'left' then
|
||||
return 'left'
|
||||
elseif default == 'right' then
|
||||
return 'right'
|
||||
if default == "left" then
|
||||
return "left"
|
||||
elseif default == "right" then
|
||||
return "right"
|
||||
end
|
||||
local wins = M.get_fixed_wins()
|
||||
local left_available, right_available
|
||||
|
@ -166,57 +165,55 @@ M.detect_split_direction = function(bufnr)
|
|||
right_available = vim.api.nvim_win_get_buf(wins[#wins]) == bufnr
|
||||
end
|
||||
|
||||
if default == 'prefer_left' then
|
||||
if default == "prefer_left" then
|
||||
if left_available then
|
||||
return 'left'
|
||||
return "left"
|
||||
elseif right_available then
|
||||
return 'right'
|
||||
return "right"
|
||||
else
|
||||
return 'left'
|
||||
return "left"
|
||||
end
|
||||
else
|
||||
if right_available then
|
||||
return 'right'
|
||||
return "right"
|
||||
elseif left_available then
|
||||
return 'left'
|
||||
return "left"
|
||||
else
|
||||
return 'right'
|
||||
return "right"
|
||||
end
|
||||
end
|
||||
|
||||
return default
|
||||
end
|
||||
|
||||
M.render_centered_text = function(bufnr, text)
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
end
|
||||
if type(text) == 'string' then
|
||||
text = {text}
|
||||
end
|
||||
local winid = vim.fn.bufwinid(bufnr)
|
||||
local height = 40
|
||||
local width = M.get_width(bufnr)
|
||||
if winid ~= -1 then
|
||||
height = vim.api.nvim_win_get_height(winid)
|
||||
width = vim.api.nvim_win_get_width(winid)
|
||||
end
|
||||
local lines = {}
|
||||
for _=1,(height/2)-(#text/2) do
|
||||
table.insert(lines, '')
|
||||
end
|
||||
for _,line in ipairs(text) do
|
||||
line = string.rep(' ', (width - vim.fn.strdisplaywidth(line)) / 2) .. line
|
||||
table.insert(lines, line)
|
||||
end
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
end
|
||||
if type(text) == "string" then
|
||||
text = { text }
|
||||
end
|
||||
local winid = vim.fn.bufwinid(bufnr)
|
||||
local height = 40
|
||||
local width = M.get_width(bufnr)
|
||||
if winid ~= -1 then
|
||||
height = vim.api.nvim_win_get_height(winid)
|
||||
width = vim.api.nvim_win_get_width(winid)
|
||||
end
|
||||
local lines = {}
|
||||
for _ = 1, (height / 2) - (#text / 2) do
|
||||
table.insert(lines, "")
|
||||
end
|
||||
for _, line in ipairs(text) do
|
||||
line = string.rep(" ", (width - vim.fn.strdisplaywidth(line)) / 2) .. line
|
||||
table.insert(lines, line)
|
||||
end
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
end
|
||||
|
||||
M.can_show_symbols = function(bufnr)
|
||||
for _,client in ipairs(vim.lsp.buf_get_clients(bufnr)) do
|
||||
if client.supports_method('textDocument/documentSymbol') then
|
||||
for _, client in ipairs(vim.lsp.buf_get_clients(bufnr)) do
|
||||
if client.supports_method("textDocument/documentSymbol") then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local config = require 'aerial.config'
|
||||
local data = require 'aerial.data'
|
||||
local loading = require 'aerial.loading'
|
||||
local render = require 'aerial.render'
|
||||
local util = require 'aerial.util'
|
||||
local config = require("aerial.config")
|
||||
local data = require("aerial.data")
|
||||
local loading = require("aerial.loading")
|
||||
local render = require("aerial.render")
|
||||
local util = require("aerial.util")
|
||||
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
|
@ -15,52 +15,56 @@ local function create_aerial_buffer(bufnr)
|
|||
util.go_buf_no_au(aer_bufnr)
|
||||
if config.default_bindings then
|
||||
local map = function(keys, cmd)
|
||||
if type(keys) == 'string' then
|
||||
keys = {keys}
|
||||
if type(keys) == "string" then
|
||||
keys = { keys }
|
||||
end
|
||||
for _,key in ipairs(keys) do
|
||||
api.nvim_buf_set_keymap(aer_bufnr, 'n', key, cmd, {silent = true, noremap = true})
|
||||
for _, key in ipairs(keys) do
|
||||
api.nvim_buf_set_keymap(aer_bufnr, "n", key, cmd, { silent = true, noremap = true })
|
||||
end
|
||||
end
|
||||
map('<CR>', "<cmd>lua require'aerial'.select()<CR>")
|
||||
map('<C-v>', "<cmd>lua require'aerial'.select({split='v'})<CR>")
|
||||
map('<C-s>', "<cmd>lua require'aerial'.select({split='h'})<CR>")
|
||||
map('p', "<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map('<C-j>', "j<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map('<C-k>', "k<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map('}', "<cmd>AerialNext<CR>")
|
||||
map('{', "<cmd>AerialPrev<CR>")
|
||||
map(']]', "<cmd>AerialNextUp<CR>")
|
||||
map('[[', "<cmd>AerialPrevUp<CR>")
|
||||
map('q', "<cmd>AerialClose<CR>")
|
||||
map({'o', 'za'}, "<cmd>AerialTreeToggle<CR>")
|
||||
map({'O', 'zA'}, "<cmd>AerialTreeToggle!<CR>")
|
||||
map({'l', 'zo'}, "<cmd>AerialTreeOpen<CR>")
|
||||
map({'L', 'zO'}, "<cmd>AerialTreeOpen!<CR>")
|
||||
map({'h', 'zc'}, "<cmd>AerialTreeClose<CR>")
|
||||
map({'H', 'zC'}, "<cmd>AerialTreeClose!<CR>")
|
||||
map('zR', "<cmd>AerialTreeOpenAll<CR>")
|
||||
map('zM', "<cmd>AerialTreeCloseAll<CR>")
|
||||
map({'zx', 'zX'}, "<cmd>AerialTreeSyncFolds<CR>")
|
||||
map("<CR>", "<cmd>lua require'aerial'.select()<CR>")
|
||||
map("<C-v>", "<cmd>lua require'aerial'.select({split='v'})<CR>")
|
||||
map("<C-s>", "<cmd>lua require'aerial'.select({split='h'})<CR>")
|
||||
map("p", "<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map("<C-j>", "j<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map("<C-k>", "k<cmd>lua require'aerial'.select({jump=false})<CR>")
|
||||
map("}", "<cmd>AerialNext<CR>")
|
||||
map("{", "<cmd>AerialPrev<CR>")
|
||||
map("]]", "<cmd>AerialNextUp<CR>")
|
||||
map("[[", "<cmd>AerialPrevUp<CR>")
|
||||
map("q", "<cmd>AerialClose<CR>")
|
||||
map({ "o", "za" }, "<cmd>AerialTreeToggle<CR>")
|
||||
map({ "O", "zA" }, "<cmd>AerialTreeToggle!<CR>")
|
||||
map({ "l", "zo" }, "<cmd>AerialTreeOpen<CR>")
|
||||
map({ "L", "zO" }, "<cmd>AerialTreeOpen!<CR>")
|
||||
map({ "h", "zc" }, "<cmd>AerialTreeClose<CR>")
|
||||
map({ "H", "zC" }, "<cmd>AerialTreeClose!<CR>")
|
||||
map("zR", "<cmd>AerialTreeOpenAll<CR>")
|
||||
map("zM", "<cmd>AerialTreeCloseAll<CR>")
|
||||
map({ "zx", "zX" }, "<cmd>AerialTreeSyncFolds<CR>")
|
||||
end
|
||||
-- Set buffer options
|
||||
api.nvim_buf_set_var(bufnr, 'aerial_buffer', aer_bufnr)
|
||||
api.nvim_buf_set_var(aer_bufnr, 'source_buffer', bufnr)
|
||||
api.nvim_buf_set_var(bufnr, "aerial_buffer", aer_bufnr)
|
||||
api.nvim_buf_set_var(aer_bufnr, "source_buffer", bufnr)
|
||||
loading.set_loading(aer_bufnr, not data:has_symbols(bufnr))
|
||||
api.nvim_buf_set_option(aer_bufnr, 'buftype', 'nofile')
|
||||
api.nvim_buf_set_option(aer_bufnr, 'bufhidden', 'wipe')
|
||||
api.nvim_buf_set_option(aer_bufnr, 'buflisted', false)
|
||||
api.nvim_buf_set_option(aer_bufnr, 'swapfile', false)
|
||||
api.nvim_buf_set_option(aer_bufnr, 'modifiable', false)
|
||||
api.nvim_buf_set_option(aer_bufnr, 'filetype', 'aerial')
|
||||
api.nvim_buf_set_option(aer_bufnr, "buftype", "nofile")
|
||||
api.nvim_buf_set_option(aer_bufnr, "bufhidden", "wipe")
|
||||
api.nvim_buf_set_option(aer_bufnr, "buflisted", false)
|
||||
api.nvim_buf_set_option(aer_bufnr, "swapfile", false)
|
||||
api.nvim_buf_set_option(aer_bufnr, "modifiable", false)
|
||||
api.nvim_buf_set_option(aer_bufnr, "filetype", "aerial")
|
||||
render.update_aerial_buffer(bufnr)
|
||||
return aer_bufnr
|
||||
end
|
||||
|
||||
local function create_aerial_window(bufnr, aer_bufnr, direction, existing_win)
|
||||
if direction == '<' then direction = 'left' end
|
||||
if direction == '>' then direction = 'right' end
|
||||
if direction ~= 'left' and direction ~= 'right' then
|
||||
if direction == "<" then
|
||||
direction = "left"
|
||||
end
|
||||
if direction == ">" then
|
||||
direction = "right"
|
||||
end
|
||||
if direction ~= "left" and direction ~= "right" then
|
||||
error("Expected direction to be 'left' or 'right'")
|
||||
return
|
||||
end
|
||||
|
@ -73,7 +77,7 @@ local function create_aerial_window(bufnr, aer_bufnr, direction, existing_win)
|
|||
winids = util.get_fixed_wins(bufnr)
|
||||
end
|
||||
local split_target
|
||||
if direction == 'left' then
|
||||
if direction == "left" then
|
||||
split_target = winids[1]
|
||||
else
|
||||
split_target = winids[#winids]
|
||||
|
@ -81,10 +85,10 @@ local function create_aerial_window(bufnr, aer_bufnr, direction, existing_win)
|
|||
if my_winid ~= split_target then
|
||||
util.go_win_no_au(split_target)
|
||||
end
|
||||
if direction == 'left' then
|
||||
vim.cmd('noau vertical leftabove split')
|
||||
if direction == "left" then
|
||||
vim.cmd("noau vertical leftabove split")
|
||||
else
|
||||
vim.cmd('noau vertical rightbelow split')
|
||||
vim.cmd("noau vertical rightbelow split")
|
||||
end
|
||||
else
|
||||
util.go_win_no_au(existing_win)
|
||||
|
@ -98,13 +102,13 @@ local function create_aerial_window(bufnr, aer_bufnr, direction, existing_win)
|
|||
if not existing_win then
|
||||
api.nvim_win_set_width(0, util.get_width())
|
||||
end
|
||||
api.nvim_win_set_option(0, 'winfixwidth', true)
|
||||
api.nvim_win_set_option(0, 'number', false)
|
||||
api.nvim_win_set_option(0, 'signcolumn', 'no')
|
||||
api.nvim_win_set_option(0, 'foldcolumn', '0')
|
||||
api.nvim_win_set_option(0, 'relativenumber', false)
|
||||
api.nvim_win_set_option(0, 'wrap', false)
|
||||
api.nvim_win_set_var(0, 'is_aerial_win', true)
|
||||
api.nvim_win_set_option(0, "winfixwidth", true)
|
||||
api.nvim_win_set_option(0, "number", false)
|
||||
api.nvim_win_set_option(0, "signcolumn", "no")
|
||||
api.nvim_win_set_option(0, "foldcolumn", "0")
|
||||
api.nvim_win_set_option(0, "relativenumber", false)
|
||||
api.nvim_win_set_option(0, "wrap", false)
|
||||
api.nvim_win_set_var(0, "is_aerial_win", true)
|
||||
local aer_winid = api.nvim_get_current_win()
|
||||
util.go_win_no_au(my_winid)
|
||||
return aer_winid
|
||||
|
@ -122,7 +126,7 @@ end
|
|||
|
||||
M.close = function()
|
||||
if util.is_aerial_buffer() then
|
||||
vim.cmd('close')
|
||||
vim.cmd("close")
|
||||
return
|
||||
end
|
||||
local aer_bufnr = util.get_aerial_buffer()
|
||||
|
@ -147,7 +151,7 @@ M.maybe_open_automatic = function()
|
|||
end
|
||||
|
||||
M.open = function(focus, direction, opts)
|
||||
opts = vim.tbl_extend('keep', opts or {}, {
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
winid = nil,
|
||||
})
|
||||
if not util.can_show_symbols() then
|
||||
|
@ -172,7 +176,7 @@ M.open = function(focus, direction, opts)
|
|||
if focus then
|
||||
api.nvim_set_current_win(aer_winid)
|
||||
end
|
||||
vim.cmd('wincmd =')
|
||||
vim.cmd("wincmd =")
|
||||
end
|
||||
|
||||
M.focus = function()
|
||||
|
@ -187,7 +191,7 @@ end
|
|||
|
||||
M.toggle = function(focus, direction)
|
||||
if util.is_aerial_buffer() then
|
||||
vim.cmd('close')
|
||||
vim.cmd("close")
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -206,7 +210,7 @@ M.get_position_in_win = function(bufnr, winid)
|
|||
local col = cursor[2]
|
||||
local bufdata = data[bufnr]
|
||||
local selected = 0
|
||||
local relative = 'above'
|
||||
local relative = "above"
|
||||
bufdata:visit(function(item)
|
||||
if item.lnum > lnum then
|
||||
return true
|
||||
|
@ -215,19 +219,19 @@ M.get_position_in_win = function(bufnr, winid)
|
|||
return true
|
||||
elseif item.col == col then
|
||||
selected = selected + 1
|
||||
relative = 'exact'
|
||||
relative = "exact"
|
||||
return true
|
||||
else
|
||||
relative = 'below'
|
||||
relative = "below"
|
||||
end
|
||||
else
|
||||
relative = 'below'
|
||||
relative = "below"
|
||||
end
|
||||
selected = selected + 1
|
||||
end)
|
||||
return {
|
||||
lnum = math.max(1, selected),
|
||||
relative = relative
|
||||
relative = relative,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -237,7 +241,7 @@ M.update_all_positions = function(bufnr, update_last)
|
|||
end
|
||||
|
||||
M.update_position = function(winid, update_last)
|
||||
if not config.highlight_mode or config.highlight_mode == 'none' then
|
||||
if not config.highlight_mode or config.highlight_mode == "none" then
|
||||
return
|
||||
end
|
||||
if winid == 0 then
|
||||
|
@ -251,15 +255,14 @@ M.update_position = function(winid, update_last)
|
|||
local winids
|
||||
if not winid or util.is_aerial_buffer(win_bufnr) then
|
||||
winids = util.get_fixed_wins(bufnr)
|
||||
elseif type(winid) == 'table' then
|
||||
elseif type(winid) == "table" then
|
||||
winids = winid
|
||||
else
|
||||
winids = {winid}
|
||||
winids = { winid }
|
||||
end
|
||||
|
||||
|
||||
local bufdata = data[bufnr]
|
||||
for _,target_win in ipairs(winids) do
|
||||
for _, target_win in ipairs(winids) do
|
||||
local pos = M.get_position_in_win(bufnr, target_win)
|
||||
if pos ~= nil then
|
||||
bufdata.positions[target_win] = pos
|
||||
|
@ -273,7 +276,7 @@ M.update_position = function(winid, update_last)
|
|||
if update_last then
|
||||
local aer_winid = fn.bufwinid(aer_bufnr)
|
||||
|
||||
if aer_winid ~= -1 then
|
||||
if aer_winid ~= -1 then
|
||||
local last_position = bufdata.last_position
|
||||
local lines = api.nvim_buf_line_count(aer_bufnr)
|
||||
|
||||
|
@ -281,7 +284,7 @@ M.update_position = function(winid, update_last)
|
|||
-- before the symbols are published, which causes the line number to be
|
||||
-- invalid.
|
||||
if lines >= last_position then
|
||||
api.nvim_win_set_cursor(aer_winid, {bufdata.last_position, 0})
|
||||
api.nvim_win_set_cursor(aer_winid, { bufdata.last_position, 0 })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue