chore(fmt): stylua

This commit is contained in:
hedy
2023-11-24 15:04:28 +08:00
parent ebf90dc9ee
commit 23958f8731
4 changed files with 25 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
local Sidebar = require('outline.sidebar')
local cfg = require('outline.config') local cfg = require('outline.config')
local providers = require('outline.providers.init') local providers = require('outline.providers.init')
local Sidebar = require('outline.sidebar')
local ui = require('outline.ui') local ui = require('outline.ui')
local utils = require('outline.utils.init') local utils = require('outline.utils.init')
@@ -15,7 +15,9 @@ local function setup_global_autocmd()
if utils.table_has_content(cfg.o.outline_items.auto_update_events.items) then if utils.table_has_content(cfg.o.outline_items.auto_update_events.items) then
vim.api.nvim_create_autocmd(cfg.o.outline_items.auto_update_events.items, { vim.api.nvim_create_autocmd(cfg.o.outline_items.auto_update_events.items, {
pattern = '*', pattern = '*',
callback = function() M._sidebar_do('_refresh') end, callback = function()
M._sidebar_do('_refresh')
end,
}) })
end end
vim.api.nvim_create_autocmd('WinEnter', { vim.api.nvim_create_autocmd('WinEnter', {

View File

@@ -19,8 +19,7 @@ local function has_code_win(winnr)
return false return false
end end
winnr = winnr or outline.current.code.win winnr = winnr or outline.current.code.win
return vim.api.nvim_win_is_valid(winnr) return vim.api.nvim_win_is_valid(winnr) and vim.api.nvim_buf_is_valid(outline.current.code.buf)
and vim.api.nvim_buf_is_valid(outline.current.code.buf)
end end
M.has_code_win = has_code_win M.has_code_win = has_code_win

View File

@@ -176,11 +176,15 @@ function Sidebar:setup_buffer_autocmd()
self:update_cursor_style() self:update_cursor_style()
vim.api.nvim_create_autocmd('BufEnter', { vim.api.nvim_create_autocmd('BufEnter', {
buffer = 0, buffer = 0,
callback = function() self:update_cursor_style() end, callback = function()
self:update_cursor_style()
end,
}) })
vim.api.nvim_create_autocmd('BufLeave', { vim.api.nvim_create_autocmd('BufLeave', {
buffer = 0, buffer = 0,
callback = function() self:reset_cursor_style() end, callback = function()
self:reset_cursor_style()
end,
}) })
end end
end end
@@ -190,10 +194,7 @@ function Sidebar:setup_attached_buffer_autocmd()
local code_win, code_buf = self.code.win, self.code.buf local code_win, code_buf = self.code.win, self.code.buf
local events = cfg.o.outline_items.auto_update_events local events = cfg.o.outline_items.auto_update_events
if if cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then
cfg.o.outline_items.highlight_hovered_item
or cfg.o.symbol_folding.auto_unfold_hover
then
if self.autocmds[code_win] then if self.autocmds[code_win] then
vim.api.nvim_del_autocmd(self.autocmds[code_win]) vim.api.nvim_del_autocmd(self.autocmds[code_win])
self.autocmds[code_win] = nil self.autocmds[code_win] = nil
@@ -260,12 +261,8 @@ end
---@param set_cursor_to_node outline.SymbolNode|outline.FlatSymbolNode? ---@param set_cursor_to_node outline.SymbolNode|outline.FlatSymbolNode?
function Sidebar:_update_lines(update_cursor, set_cursor_to_node) function Sidebar:_update_lines(update_cursor, set_cursor_to_node)
local current local current
self.flats, current = writer.make_outline( self.flats, current =
self.view.bufnr, writer.make_outline(self.view.bufnr, self.items, self.code.win, set_cursor_to_node)
self.items,
self.code.win,
set_cursor_to_node
)
if update_cursor ~= false then if update_cursor ~= false then
self:update_cursor_pos(current) self:update_cursor_pos(current)
end end
@@ -309,12 +306,16 @@ end
function Sidebar:__refresh() function Sidebar:__refresh()
local focused_outline = self.view.bufnr == vim.api.nvim_get_current_buf() local focused_outline = self.view.bufnr == vim.api.nvim_get_current_buf()
if self.view:is_open() and not focused_outline then if self.view:is_open() and not focused_outline then
providers.request_symbols(function(res) self:refresh_handler(res) end) providers.request_symbols(function(res)
self:refresh_handler(res)
end)
end end
end end
function Sidebar:_refresh() function Sidebar:_refresh()
(utils.debounce(function() self:__refresh() end, 100))() (utils.debounce(function()
self:__refresh()
end, 100))()
end end
---@return outline.FlatSymbolNode ---@return outline.FlatSymbolNode
@@ -398,11 +399,7 @@ function Sidebar:_set_folded(folded, move_cursor, node_index)
local parent_node = self.flats[node.parent.line_in_outline] local parent_node = self.flats[node.parent.line_in_outline]
if parent_node then if parent_node then
self:_set_folded( self:_set_folded(folded, not parent_node.folded and folded, parent_node.line_in_outline)
folded,
not parent_node.folded and folded,
parent_node.line_in_outline
)
end end
end end
end end
@@ -492,10 +489,9 @@ function Sidebar:open(opts)
end end
if not self.view:is_open() then if not self.view:is_open() then
local found = providers.request_symbols( local found = providers.request_symbols(function(...)
function(...) self:initial_handler(...) end, self:initial_handler(...)
opts end, opts)
)
if not found then if not found then
utils.echo('No providers found for current buffer') utils.echo('No providers found for current buffer')
end end

View File

@@ -48,7 +48,7 @@ function View:setup_view(split_command)
vim.api.nvim_win_set_option(self.winnr, 'showbreak', ' ') -- only has effect when wrap=true. vim.api.nvim_win_set_option(self.winnr, 'showbreak', ' ') -- only has effect when wrap=true.
-- buffer stuff -- buffer stuff
local tab = vim.api.nvim_get_current_tabpage() local tab = vim.api.nvim_get_current_tabpage()
vim.api.nvim_buf_set_name(self.bufnr, 'OUTLINE_'..tostring(tab)) vim.api.nvim_buf_set_name(self.bufnr, 'OUTLINE_' .. tostring(tab))
vim.api.nvim_buf_set_option(self.bufnr, 'filetype', 'Outline') vim.api.nvim_buf_set_option(self.bufnr, 'filetype', 'Outline')
vim.api.nvim_buf_set_option(self.bufnr, 'modifiable', false) vim.api.nvim_buf_set_option(self.bufnr, 'modifiable', false)