outline: Add option to disable highlight on hover
Can be taxing on older cpus
This commit is contained in:
@@ -21,8 +21,10 @@ end
|
|||||||
local function setup_autocmd()
|
local function setup_autocmd()
|
||||||
vim.cmd(
|
vim.cmd(
|
||||||
"autocmd InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
"autocmd InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
||||||
vim.cmd(
|
if D.opts.highlight_hovered_item then
|
||||||
"autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()")
|
vim.cmd(
|
||||||
|
"autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getParams()
|
local function getParams()
|
||||||
@@ -113,7 +115,6 @@ local function make_linear(outline_items)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function get_lines(outline_items, bufnr, winnr, lines)
|
local function get_lines(outline_items, bufnr, winnr, lines)
|
||||||
lines = lines or {}
|
lines = lines or {}
|
||||||
for _, value in ipairs(outline_items) do
|
for _, value in ipairs(outline_items) do
|
||||||
@@ -193,7 +194,8 @@ function D._highlight_current_item()
|
|||||||
|
|
||||||
local nodes = {}
|
local nodes = {}
|
||||||
for index, value in ipairs(D.state.linear_outline_items) do
|
for index, value in ipairs(D.state.linear_outline_items) do
|
||||||
if value.line == hovered_line or (hovered_line > value.range_start and hovered_line < value.range_end) then
|
if value.line == hovered_line or
|
||||||
|
(hovered_line > value.range_start and hovered_line < value.range_end) then
|
||||||
value.line_in_outline = index
|
value.line_in_outline = index
|
||||||
table.insert(nodes, value)
|
table.insert(nodes, value)
|
||||||
end
|
end
|
||||||
@@ -217,40 +219,36 @@ local function setup_keymaps(bufnr)
|
|||||||
":lua require('symbols-outline')._goto_location()<Cr>",
|
":lua require('symbols-outline')._goto_location()<Cr>",
|
||||||
{})
|
{})
|
||||||
-- close outline when escape is pressed
|
-- close outline when escape is pressed
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Esc>",
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Esc>", ":bw!<Cr>", {})
|
||||||
":bw!<Cr>",
|
|
||||||
{})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------
|
----------------------------
|
||||||
-- WINDOW AND BUFFER STUFF
|
-- WINDOW AND BUFFER STUFF
|
||||||
----------------------------
|
----------------------------
|
||||||
local function setup_buffer()
|
local function setup_buffer()
|
||||||
D.state.outline_buf = vim.api.nvim_create_buf(false, true)
|
D.state.outline_buf = vim.api.nvim_create_buf(false, true)
|
||||||
vim.api.nvim_buf_attach(D.state.outline_buf, false,
|
vim.api.nvim_buf_attach(D.state.outline_buf, false,
|
||||||
{on_detach = function(_, _) wipe_state() end})
|
{on_detach = function(_, _) wipe_state() end})
|
||||||
vim.api.nvim_buf_set_option(D.state.outline_buf, "bufhidden", "delete")
|
vim.api.nvim_buf_set_option(D.state.outline_buf, "bufhidden", "delete")
|
||||||
|
|
||||||
local current_win = vim.api.nvim_get_current_win()
|
local current_win = vim.api.nvim_get_current_win()
|
||||||
local current_win_width = vim.api.nvim_win_get_width(current_win)
|
local current_win_width = vim.api.nvim_win_get_width(current_win)
|
||||||
|
|
||||||
vim.cmd("vsplit")
|
vim.cmd("vsplit")
|
||||||
vim.cmd("vertical resize " .. math.ceil(current_win_width * 0.25))
|
vim.cmd("vertical resize " .. math.ceil(current_win_width * 0.25))
|
||||||
D.state.outline_win = vim.api.nvim_get_current_win()
|
D.state.outline_win = vim.api.nvim_get_current_win()
|
||||||
vim.api.nvim_win_set_buf(D.state.outline_win, D.state.outline_buf)
|
vim.api.nvim_win_set_buf(D.state.outline_win, D.state.outline_buf)
|
||||||
|
|
||||||
setup_keymaps(D.state.outline_buf)
|
setup_keymaps(D.state.outline_buf)
|
||||||
|
|
||||||
vim.api.nvim_win_set_option(D.state.outline_win, "number", false)
|
vim.api.nvim_win_set_option(D.state.outline_win, "number", false)
|
||||||
vim.api.nvim_win_set_option(D.state.outline_win, "relativenumber", false)
|
vim.api.nvim_win_set_option(D.state.outline_win, "relativenumber", false)
|
||||||
vim.api.nvim_buf_set_name(D.state.outline_buf, "OUTLINE")
|
vim.api.nvim_buf_set_name(D.state.outline_buf, "OUTLINE")
|
||||||
vim.api.nvim_buf_set_option(D.state.outline_buf, "modifiable", false)
|
vim.api.nvim_buf_set_option(D.state.outline_buf, "modifiable", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function handler(_, _, result)
|
local function handler(_, _, result)
|
||||||
if result == nil then
|
if result == nil then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
D.state.code_win = vim.api.nvim_get_current_win()
|
D.state.code_win = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
if D.state.outline_buf == nil then
|
if D.state.outline_buf == nil then
|
||||||
@@ -275,9 +273,15 @@ function D.toggle_outline()
|
|||||||
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(), handler)
|
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(), handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
function D.setup()
|
function D.setup(opts)
|
||||||
|
vim.tbl_deep_extend("force", D.opts, opts or {})
|
||||||
|
|
||||||
setup_commands()
|
setup_commands()
|
||||||
setup_autocmd()
|
setup_autocmd()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
D.opts = {
|
||||||
|
highlight_hovered_item = true,
|
||||||
|
}
|
||||||
|
|
||||||
return D
|
return D
|
||||||
|
|||||||
Reference in New Issue
Block a user