Merge pull request #112 from FollieHiyuki/stylua-format
Format with Stylua
This commit is contained in:
@@ -1,31 +1,27 @@
|
||||
local vim = vim
|
||||
|
||||
local parser = require('symbols-outline.parser')
|
||||
local providers = require('symbols-outline.providers.init')
|
||||
local ui = require('symbols-outline.ui')
|
||||
local writer = require('symbols-outline.writer')
|
||||
local config = require('symbols-outline.config')
|
||||
local utils = require('symbols-outline.utils.init')
|
||||
local view = require('symbols-outline.view')
|
||||
local parser = require 'symbols-outline.parser'
|
||||
local providers = require 'symbols-outline.providers.init'
|
||||
local ui = require 'symbols-outline.ui'
|
||||
local writer = require 'symbols-outline.writer'
|
||||
local config = require 'symbols-outline.config'
|
||||
local utils = require 'symbols-outline.utils.init'
|
||||
local view = require 'symbols-outline.view'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function setup_global_autocmd()
|
||||
if config.options.highlight_hovered_item then
|
||||
vim.cmd(
|
||||
"au CursorHold * :lua require('symbols-outline')._highlight_current_item()")
|
||||
vim.cmd "au CursorHold * :lua require('symbols-outline')._highlight_current_item()"
|
||||
end
|
||||
end
|
||||
|
||||
local function setup_buffer_autocmd()
|
||||
if config.options.auto_preview then
|
||||
vim.cmd(
|
||||
"au CursorHold <buffer> lua require'symbols-outline.preview'.show()")
|
||||
vim.cmd "au CursorHold <buffer> lua require'symbols-outline.preview'.show()"
|
||||
else
|
||||
vim.cmd(
|
||||
"au CursorMoved <buffer> lua require'symbols-outline.preview'.close()")
|
||||
vim.cmd "au CursorMoved <buffer> lua require'symbols-outline.preview'.close()"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------
|
||||
@@ -36,11 +32,11 @@ M.state = {
|
||||
flattened_outline_items = {},
|
||||
outline_win = nil,
|
||||
outline_buf = nil,
|
||||
code_win = 0
|
||||
code_win = 0,
|
||||
}
|
||||
|
||||
local function wipe_state()
|
||||
M.state = {outline_items = {}, flattened_outline_items = {}, code_win = 0}
|
||||
M.state = { outline_items = {}, flattened_outline_items = {}, code_win = 0 }
|
||||
end
|
||||
|
||||
local function __refresh()
|
||||
@@ -56,8 +52,7 @@ local function __refresh()
|
||||
M.state.outline_items = items
|
||||
M.state.flattened_outline_items = parser.flatten(items)
|
||||
|
||||
writer.parse_and_write(M.state.outline_buf,
|
||||
M.state.flattened_outline_items)
|
||||
writer.parse_and_write(M.state.outline_buf, M.state.flattened_outline_items)
|
||||
end
|
||||
|
||||
providers.request_symbols(refresh_handler)
|
||||
@@ -69,30 +64,34 @@ M._refresh = utils.debounce(__refresh, 100)
|
||||
function M._goto_location(change_focus)
|
||||
local current_line = vim.api.nvim_win_get_cursor(M.state.outline_win)[1]
|
||||
local node = M.state.flattened_outline_items[current_line]
|
||||
vim.api.nvim_win_set_cursor(M.state.code_win,
|
||||
{node.line + 1, node.character})
|
||||
if change_focus then vim.fn.win_gotoid(M.state.code_win) end
|
||||
if config.options.auto_close then M.close_outline() end
|
||||
vim.api.nvim_win_set_cursor(M.state.code_win, { node.line + 1, node.character })
|
||||
if change_focus then
|
||||
vim.fn.win_gotoid(M.state.code_win)
|
||||
end
|
||||
if config.options.auto_close then
|
||||
M.close_outline()
|
||||
end
|
||||
end
|
||||
|
||||
function M._highlight_current_item(winnr)
|
||||
local has_provider = providers.has_provider()
|
||||
|
||||
local is_current_buffer_the_outline =
|
||||
M.state.outline_buf == vim.api.nvim_get_current_buf()
|
||||
local is_current_buffer_the_outline = M.state.outline_buf == vim.api.nvim_get_current_buf()
|
||||
|
||||
local doesnt_have_outline_buf = not M.state.outline_buf
|
||||
|
||||
local should_exit = (not has_provider) or
|
||||
doesnt_have_outline_buf or
|
||||
is_current_buffer_the_outline
|
||||
local should_exit = not has_provider or doesnt_have_outline_buf or is_current_buffer_the_outline
|
||||
|
||||
-- Make a special case if we have a window number
|
||||
-- Because we might use this to manually focus so we dont want to quit this
|
||||
-- function
|
||||
if winnr then should_exit = false end
|
||||
if winnr then
|
||||
should_exit = false
|
||||
end
|
||||
|
||||
if should_exit then return end
|
||||
if should_exit then
|
||||
return
|
||||
end
|
||||
|
||||
local win = winnr or vim.api.nvim_get_current_win()
|
||||
|
||||
@@ -100,8 +99,7 @@ function M._highlight_current_item(winnr)
|
||||
|
||||
local nodes = {}
|
||||
for index, value in ipairs(M.state.flattened_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
|
||||
table.insert(nodes, value)
|
||||
end
|
||||
@@ -110,51 +108,47 @@ function M._highlight_current_item(winnr)
|
||||
-- clear old highlight
|
||||
ui.clear_hover_highlight(M.state.outline_buf)
|
||||
for _, value in ipairs(nodes) do
|
||||
ui.add_hover_highlight(M.state.outline_buf, value.line_in_outline - 1,
|
||||
value.depth * 2)
|
||||
vim.api.nvim_win_set_cursor(M.state.outline_win,
|
||||
{value.line_in_outline, 1})
|
||||
ui.add_hover_highlight(M.state.outline_buf, value.line_in_outline - 1, value.depth * 2)
|
||||
vim.api.nvim_win_set_cursor(M.state.outline_win, { value.line_in_outline, 1 })
|
||||
end
|
||||
end
|
||||
|
||||
local function setup_keymaps(bufnr)
|
||||
local map = function (...)
|
||||
local map = function(...)
|
||||
utils.nmap(bufnr, ...)
|
||||
end
|
||||
-- goto_location of symbol and focus that window
|
||||
map(config.options.keymaps.goto_location,
|
||||
":lua require('symbols-outline')._goto_location(true)<Cr>")
|
||||
map(config.options.keymaps.goto_location, ":lua require('symbols-outline')._goto_location(true)<Cr>")
|
||||
-- goto_location of symbol but stay in outline
|
||||
map(config.options.keymaps.focus_location,
|
||||
":lua require('symbols-outline')._goto_location(false)<Cr>")
|
||||
map(config.options.keymaps.focus_location, ":lua require('symbols-outline')._goto_location(false)<Cr>")
|
||||
-- hover symbol
|
||||
map(config.options.keymaps.hover_symbol,
|
||||
":lua require('symbols-outline.hover').show_hover()<Cr>")
|
||||
map(config.options.keymaps.hover_symbol, ":lua require('symbols-outline.hover').show_hover()<Cr>")
|
||||
-- preview symbol
|
||||
map(config.options.keymaps.toggle_preview,
|
||||
":lua require('symbols-outline.preview').toggle()<Cr>")
|
||||
map(config.options.keymaps.toggle_preview, ":lua require('symbols-outline.preview').toggle()<Cr>")
|
||||
-- rename symbol
|
||||
map(config.options.keymaps.rename_symbol,
|
||||
":lua require('symbols-outline.rename').rename()<Cr>")
|
||||
map(config.options.keymaps.rename_symbol, ":lua require('symbols-outline.rename').rename()<Cr>")
|
||||
-- code actions
|
||||
map(config.options.keymaps.code_actions,
|
||||
":lua require('symbols-outline.code_action').show_code_actions()<Cr>")
|
||||
map(config.options.keymaps.code_actions, ":lua require('symbols-outline.code_action').show_code_actions()<Cr>")
|
||||
-- show help
|
||||
map(config.options.keymaps.show_help,
|
||||
":lua require('symbols-outline.config').show_help()<Cr>")
|
||||
map(config.options.keymaps.show_help, ":lua require('symbols-outline.config').show_help()<Cr>")
|
||||
-- close outline
|
||||
map(config.options.keymaps.close, ":bw!<Cr>")
|
||||
map(config.options.keymaps.close, ':bw!<Cr>')
|
||||
end
|
||||
|
||||
local function handler(response)
|
||||
if response == nil or type(response) ~= 'table' then return end
|
||||
if response == nil or type(response) ~= 'table' then
|
||||
return
|
||||
end
|
||||
|
||||
M.state.code_win = vim.api.nvim_get_current_win()
|
||||
|
||||
M.state.outline_buf, M.state.outline_win = view.setup_view()
|
||||
-- clear state when buffer is closed
|
||||
vim.api.nvim_buf_attach(M.state.outline_buf, false,
|
||||
{on_detach = function(_, _) wipe_state() end})
|
||||
vim.api.nvim_buf_attach(M.state.outline_buf, false, {
|
||||
on_detach = function(_, _)
|
||||
wipe_state()
|
||||
end,
|
||||
})
|
||||
setup_keymaps(M.state.outline_buf)
|
||||
setup_buffer_autocmd()
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
local vim = vim
|
||||
|
||||
local main = require('symbols-outline')
|
||||
local main = require 'symbols-outline'
|
||||
local buf_request = require('symbols-outline.utils.lsp_utils').request
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_action_params(node, winnr)
|
||||
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
||||
local fn = "file://" .. vim.api.nvim_buf_get_name(bufnr)
|
||||
local fn = 'file://' .. vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local pos = {line = node.line, character = node.character}
|
||||
local pos = { line = node.line, character = node.character }
|
||||
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr, node.line)
|
||||
return {
|
||||
textDocument = {uri = fn},
|
||||
range = {start = pos, ["end"] = pos},
|
||||
context = {diagnostics = diagnostics},
|
||||
bufnr = bufnr
|
||||
textDocument = { uri = fn },
|
||||
range = { start = pos, ['end'] = pos },
|
||||
context = { diagnostics = diagnostics },
|
||||
bufnr = bufnr,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -25,8 +25,7 @@ function M.show_code_actions()
|
||||
|
||||
local params = get_action_params(node, main.state.code_win)
|
||||
|
||||
buf_request(params.bufnr, "textDocument/codeAction", params,
|
||||
vim.lsp.handlers["textDocument/codeAction"])
|
||||
buf_request(params.bufnr, 'textDocument/codeAction', params, vim.lsp.handlers['textDocument/codeAction'])
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -16,45 +16,45 @@ M.defaults = {
|
||||
show_symbol_details = true,
|
||||
preview_bg_highlight = 'Pmenu',
|
||||
keymaps = { -- These keymaps can be a string or a table for multiple keys
|
||||
close = {"<Esc>", "q"},
|
||||
goto_location = "<Cr>",
|
||||
focus_location = "o",
|
||||
hover_symbol = "<C-space>",
|
||||
toggle_preview = "K",
|
||||
rename_symbol = "r",
|
||||
code_actions = "a",
|
||||
show_help = "?"
|
||||
close = { '<Esc>', 'q' },
|
||||
goto_location = '<Cr>',
|
||||
focus_location = 'o',
|
||||
hover_symbol = '<C-space>',
|
||||
toggle_preview = 'K',
|
||||
rename_symbol = 'r',
|
||||
code_actions = 'a',
|
||||
show_help = '?',
|
||||
},
|
||||
lsp_blacklist = {},
|
||||
symbol_blacklist = {},
|
||||
symbols = {
|
||||
File = {icon = "", hl = "TSURI"},
|
||||
Module = {icon = "", hl = "TSNamespace"},
|
||||
Namespace = {icon = "", hl = "TSNamespace"},
|
||||
Package = {icon = "", hl = "TSNamespace"},
|
||||
Class = {icon = "𝓒", hl = "TSType"},
|
||||
Method = {icon = "ƒ", hl = "TSMethod"},
|
||||
Property = {icon = "", hl = "TSMethod"},
|
||||
Field = {icon = "", hl = "TSField"},
|
||||
Constructor = {icon = "", hl = "TSConstructor"},
|
||||
Enum = {icon = "ℰ", hl = "TSType"},
|
||||
Interface = {icon = "ﰮ", hl = "TSType"},
|
||||
Function = {icon = "", hl = "TSFunction"},
|
||||
Variable = {icon = "", hl = "TSConstant"},
|
||||
Constant = {icon = "", hl = "TSConstant"},
|
||||
String = {icon = "𝓐", hl = "TSString"},
|
||||
Number = {icon = "#", hl = "TSNumber"},
|
||||
Boolean = {icon = "⊨", hl = "TSBoolean"},
|
||||
Array = {icon = "", hl = "TSConstant"},
|
||||
Object = {icon = "⦿", hl = "TSType"},
|
||||
Key = {icon = "🔐", hl = "TSType"},
|
||||
Null = {icon = "NULL", hl = "TSType"},
|
||||
EnumMember = {icon = "", hl = "TSField"},
|
||||
Struct = {icon = "𝓢", hl = "TSType"},
|
||||
Event = {icon = "🗲", hl = "TSType"},
|
||||
Operator = {icon = "+", hl = "TSOperator"},
|
||||
TypeParameter = {icon = "𝙏", hl = "TSParameter"}
|
||||
}
|
||||
File = { icon = '', hl = 'TSURI' },
|
||||
Module = { icon = '', hl = 'TSNamespace' },
|
||||
Namespace = { icon = '', hl = 'TSNamespace' },
|
||||
Package = { icon = '', hl = 'TSNamespace' },
|
||||
Class = { icon = '𝓒', hl = 'TSType' },
|
||||
Method = { icon = 'ƒ', hl = 'TSMethod' },
|
||||
Property = { icon = '', hl = 'TSMethod' },
|
||||
Field = { icon = '', hl = 'TSField' },
|
||||
Constructor = { icon = '', hl = 'TSConstructor' },
|
||||
Enum = { icon = 'ℰ', hl = 'TSType' },
|
||||
Interface = { icon = 'ﰮ', hl = 'TSType' },
|
||||
Function = { icon = '', hl = 'TSFunction' },
|
||||
Variable = { icon = '', hl = 'TSConstant' },
|
||||
Constant = { icon = '', hl = 'TSConstant' },
|
||||
String = { icon = '𝓐', hl = 'TSString' },
|
||||
Number = { icon = '#', hl = 'TSNumber' },
|
||||
Boolean = { icon = '⊨', hl = 'TSBoolean' },
|
||||
Array = { icon = '', hl = 'TSConstant' },
|
||||
Object = { icon = '⦿', hl = 'TSType' },
|
||||
Key = { icon = '🔐', hl = 'TSType' },
|
||||
Null = { icon = 'NULL', hl = 'TSType' },
|
||||
EnumMember = { icon = '', hl = 'TSField' },
|
||||
Struct = { icon = '𝓢', hl = 'TSType' },
|
||||
Event = { icon = '🗲', hl = 'TSType' },
|
||||
Operator = { icon = '+', hl = 'TSOperator' },
|
||||
TypeParameter = { icon = '𝙏', hl = 'TSParameter' },
|
||||
},
|
||||
}
|
||||
|
||||
M.options = {}
|
||||
@@ -79,40 +79,47 @@ function M.get_window_width()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.get_split_command()
|
||||
if M.options.position == 'left' then
|
||||
return "topleft vs"
|
||||
return 'topleft vs'
|
||||
else
|
||||
return "botright vs"
|
||||
return 'botright vs'
|
||||
end
|
||||
end
|
||||
|
||||
local function has_value(tab, val)
|
||||
for _, value in ipairs(tab) do if value == val then return true end end
|
||||
for _, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function M.is_symbol_blacklisted(kind)
|
||||
if kind == nil then return false end
|
||||
if kind == nil then
|
||||
return false
|
||||
end
|
||||
return has_value(M.options.symbol_blacklist, kind)
|
||||
end
|
||||
|
||||
function M.is_client_blacklisted(client_id)
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then return false end
|
||||
if not client then
|
||||
return false
|
||||
end
|
||||
return has_value(M.options.lsp_blacklist, client.name)
|
||||
end
|
||||
|
||||
function M.show_help()
|
||||
print "Current keymaps:"
|
||||
print 'Current keymaps:'
|
||||
print(vim.inspect(M.options.keymaps))
|
||||
end
|
||||
|
||||
function M.setup(options)
|
||||
vim.g.symbols_outline_loaded = 1
|
||||
M.options = vim.tbl_deep_extend("force", {}, M.defaults, options or {})
|
||||
M.options = vim.tbl_deep_extend('force', {}, M.defaults, options or {})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local vim = vim
|
||||
|
||||
local main = require('symbols-outline')
|
||||
local main = require 'symbols-outline'
|
||||
local util = vim.lsp.util
|
||||
local buf_request = require('symbols-outline.utils.lsp_utils').request
|
||||
|
||||
@@ -11,9 +11,9 @@ local function get_hover_params(node, winnr)
|
||||
local fn = vim.uri_from_bufnr(bufnr)
|
||||
|
||||
return {
|
||||
textDocument = {uri = fn},
|
||||
position = {line = node.line, character = node.character},
|
||||
bufnr = bufnr
|
||||
textDocument = { uri = fn },
|
||||
position = { line = node.line, character = node.character },
|
||||
bufnr = bufnr,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -24,21 +24,18 @@ function M.show_hover()
|
||||
|
||||
local hover_params = get_hover_params(node, main.state.code_win)
|
||||
|
||||
buf_request(hover_params.bufnr, "textDocument/hover", hover_params,
|
||||
function(_, result, _, config)
|
||||
|
||||
buf_request(hover_params.bufnr, 'textDocument/hover', hover_params, function(_, result, _, config)
|
||||
if not (result and result.contents) then
|
||||
-- return { 'No information available' }
|
||||
return
|
||||
end
|
||||
local markdown_lines = util.convert_input_to_markdown_lines(
|
||||
result.contents)
|
||||
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
|
||||
markdown_lines = util.trim_empty_lines(markdown_lines)
|
||||
if vim.tbl_isempty(markdown_lines) then
|
||||
-- return { 'No information available' }
|
||||
return
|
||||
end
|
||||
return util.open_floating_preview(markdown_lines, "markdown", config)
|
||||
return util.open_floating_preview(markdown_lines, 'markdown', config)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ local M = {}
|
||||
---@return table
|
||||
function M.handle_markdown()
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
local level_symbols = {{children = {}}}
|
||||
local level_symbols = { { children = {} } }
|
||||
local max_level = 1
|
||||
local is_inside_code_block = false
|
||||
|
||||
for line, value in ipairs(lines) do
|
||||
if string.find(value, "^```") then
|
||||
if string.find(value, '^```') then
|
||||
is_inside_code_block = not is_inside_code_block
|
||||
end
|
||||
|
||||
header, title = string.match(value, "^(#+)%s+(.*)$")
|
||||
header, title = string.match(value, '^(#+)%s+(.*)$')
|
||||
if header and not is_inside_code_block then
|
||||
depth = #header + 1
|
||||
|
||||
@@ -29,8 +29,8 @@ function M.handle_markdown()
|
||||
|
||||
for i = depth, max_level do
|
||||
if level_symbols[i] ~= nil then
|
||||
level_symbols[i].selectionRange["end"].line = line - 1
|
||||
level_symbols[i].range["end"].line = line - 1
|
||||
level_symbols[i].selectionRange['end'].line = line - 1
|
||||
level_symbols[i].range['end'].line = line - 1
|
||||
level_symbols[i] = nil
|
||||
end
|
||||
end
|
||||
@@ -40,12 +40,12 @@ function M.handle_markdown()
|
||||
kind = 13,
|
||||
name = title,
|
||||
selectionRange = {
|
||||
start = {character = 1, line = line - 1},
|
||||
["end"] = {character = 1, line = line - 1}
|
||||
start = { character = 1, line = line - 1 },
|
||||
['end'] = { character = 1, line = line - 1 },
|
||||
},
|
||||
range = {
|
||||
start = {character = 1, line = line - 1},
|
||||
["end"] = {character = 1, line = line - 1}
|
||||
start = { character = 1, line = line - 1 },
|
||||
['end'] = { character = 1, line = line - 1 },
|
||||
},
|
||||
children = {},
|
||||
}
|
||||
@@ -57,12 +57,12 @@ function M.handle_markdown()
|
||||
|
||||
for i = 2, max_level do
|
||||
if level_symbols[i] ~= nil then
|
||||
level_symbols[i].selectionRange["end"].line = #lines
|
||||
level_symbols[i].range["end"].line = #lines
|
||||
level_symbols[i].selectionRange['end'].line = #lines
|
||||
level_symbols[i].range['end'].line = #lines
|
||||
end
|
||||
end
|
||||
|
||||
return {[1000000]={result=level_symbols[1].children}}
|
||||
return { [1000000] = { result = level_symbols[1].children } }
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
local symbols = require('symbols-outline.symbols')
|
||||
local ui = require('symbols-outline.ui')
|
||||
local config = require('symbols-outline.config')
|
||||
local symbols = require 'symbols-outline.symbols'
|
||||
local ui = require 'symbols-outline.ui'
|
||||
local config = require 'symbols-outline.config'
|
||||
|
||||
local M = {}
|
||||
|
||||
-- copies an array and returns it because lua usually does references
|
||||
local function array_copy(t)
|
||||
local ret = {}
|
||||
for _, value in ipairs(t) do table.insert(ret, value) end
|
||||
for _, value in ipairs(t) do
|
||||
table.insert(ret, value)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
@@ -46,7 +48,9 @@ local function parse_result(result, depth, hierarchy)
|
||||
end
|
||||
|
||||
local range = value.range
|
||||
if value.range == nil then range = value.location.range end
|
||||
if value.range == nil then
|
||||
range = value.location.range
|
||||
end
|
||||
|
||||
table.insert(ret, {
|
||||
deprecated = value.deprecated,
|
||||
@@ -57,12 +61,12 @@ local function parse_result(result, depth, hierarchy)
|
||||
line = selectionRange.start.line,
|
||||
character = selectionRange.start.character,
|
||||
range_start = range.start.line,
|
||||
range_end = range["end"].line,
|
||||
range_end = range['end'].line,
|
||||
children = children,
|
||||
depth = level,
|
||||
isLast = isLast,
|
||||
hierarchy = hir
|
||||
});
|
||||
hierarchy = hir,
|
||||
})
|
||||
end
|
||||
end
|
||||
return ret
|
||||
@@ -90,11 +94,17 @@ local function sort_result(result)
|
||||
local b_start = get_range_start(b)
|
||||
|
||||
-- if they both are equal, a should be before b
|
||||
if a_start == nil and b_start == nil then return false end
|
||||
if a_start == nil and b_start == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
-- those with no start go first
|
||||
if a_start == nil then return true end
|
||||
if b_start == nil then return false end
|
||||
if a_start == nil then
|
||||
return true
|
||||
end
|
||||
if b_start == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
-- first try to sort by line. If lines are equal, sort by character instead
|
||||
if a_start.line ~= b_start.line then
|
||||
@@ -123,7 +133,9 @@ function M.parse(response)
|
||||
local result = client_response['result']
|
||||
if result == nil or type(result) ~= 'table' then goto continue end
|
||||
|
||||
for _, value in pairs(result) do table.insert(all_results, value) end
|
||||
for _, value in pairs(result) do
|
||||
table.insert(all_results, value)
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
@@ -148,14 +160,18 @@ function M.flatten(outline_items)
|
||||
end
|
||||
|
||||
local function table_to_str(t)
|
||||
local ret = ""
|
||||
for _, value in ipairs(t) do ret = ret .. tostring(value) end
|
||||
local ret = ''
|
||||
for _, value in ipairs(t) do
|
||||
ret = ret .. tostring(value)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local function str_to_table(str)
|
||||
local t = {}
|
||||
for i = 1, #str do t[i] = str:sub(i, i) end
|
||||
for i = 1, #str do
|
||||
t[i] = str:sub(i, i)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
@@ -163,14 +179,14 @@ function M.get_lines(flattened_outline_items)
|
||||
local lines = {}
|
||||
local hl_info = {}
|
||||
for _, value in ipairs(flattened_outline_items) do
|
||||
local line = str_to_table(string.rep(" ", value.depth))
|
||||
local line = str_to_table(string.rep(' ', value.depth))
|
||||
|
||||
if config.options.show_guides then
|
||||
-- makes the guides
|
||||
for index, _ in ipairs(line) do
|
||||
-- all items start with a space (or two)
|
||||
if index == 1 then
|
||||
line[index] = " "
|
||||
line[index] = ' '
|
||||
-- if index is last, add a bottom marker if current item is last,
|
||||
-- else add a middle marker
|
||||
elseif index == #line then
|
||||
@@ -192,16 +208,15 @@ function M.get_lines(flattened_outline_items)
|
||||
-- Add 1 space between the guides
|
||||
for _, v in ipairs(line) do
|
||||
table.insert(final_prefix, v)
|
||||
table.insert(final_prefix, " ")
|
||||
table.insert(final_prefix, ' ')
|
||||
end
|
||||
|
||||
local string_prefix = table_to_str(final_prefix)
|
||||
local hl_start = #string_prefix
|
||||
local hl_end = #string_prefix + #value.icon
|
||||
table.insert(lines, string_prefix .. value.icon .. " " ..
|
||||
value.name)
|
||||
table.insert(lines, string_prefix .. value.icon .. ' ' .. value.name)
|
||||
hl_type = config.options.symbols[symbols.kinds[value.kind]].hl
|
||||
table.insert(hl_info, {hl_start, hl_end, hl_type})
|
||||
table.insert(hl_info, { hl_start, hl_end, hl_type })
|
||||
end
|
||||
return lines, hl_info
|
||||
end
|
||||
@@ -209,7 +224,7 @@ end
|
||||
function M.get_details(flattened_outline_items)
|
||||
local lines = {}
|
||||
for _, value in ipairs(flattened_outline_items) do
|
||||
table.insert(lines, value.detail or "")
|
||||
table.insert(lines, value.detail or '')
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local vim = vim
|
||||
local main = require("symbols-outline")
|
||||
local config = require("symbols-outline.config")
|
||||
local buf_request = require("symbols-outline.utils.lsp_utils").request
|
||||
local main = require 'symbols-outline'
|
||||
local config = require 'symbols-outline.config'
|
||||
local buf_request = require('symbols-outline.utils.lsp_utils').request
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -36,7 +36,7 @@ local function get_offset()
|
||||
width = width + 4
|
||||
end
|
||||
|
||||
if config.options.position == "right" then
|
||||
if config.options.position == 'right' then
|
||||
width = 0 - width
|
||||
else
|
||||
width = vim.api.nvim_win_get_width(outline_winnr) + 1
|
||||
@@ -72,10 +72,10 @@ end
|
||||
|
||||
local function setup_preview_buf()
|
||||
local code_buf = vim.api.nvim_win_get_buf(main.state.code_win)
|
||||
local ft = vim.api.nvim_buf_get_option(code_buf, "filetype")
|
||||
local ft = vim.api.nvim_buf_get_option(code_buf, 'filetype')
|
||||
|
||||
local function treesitter_attach()
|
||||
local ts_highlight = require("nvim-treesitter.highlight")
|
||||
local ts_highlight = require 'nvim-treesitter.highlight'
|
||||
|
||||
ts_highlight.attach(state.preview_buf, ft)
|
||||
end
|
||||
@@ -83,9 +83,9 @@ local function setup_preview_buf()
|
||||
-- user might not have tree sitter installed
|
||||
pcall(treesitter_attach)
|
||||
|
||||
vim.api.nvim_buf_set_option(state.preview_buf, "syntax", ft)
|
||||
vim.api.nvim_buf_set_option(state.preview_buf, "bufhidden", "delete")
|
||||
vim.api.nvim_win_set_option(state.preview_win, "cursorline", true)
|
||||
vim.api.nvim_buf_set_option(state.preview_buf, 'syntax', ft)
|
||||
vim.api.nvim_buf_set_option(state.preview_buf, 'bufhidden', 'delete')
|
||||
vim.api.nvim_win_set_option(state.preview_win, 'cursorline', true)
|
||||
update_preview(code_buf)
|
||||
end
|
||||
|
||||
@@ -123,7 +123,7 @@ local function update_hover()
|
||||
end
|
||||
markdown_lines = vim.lsp.util.trim_empty_lines(markdown_lines)
|
||||
if vim.tbl_isempty(markdown_lines) then
|
||||
markdown_lines = { "###No info available!" }
|
||||
markdown_lines = { '###No info available!' }
|
||||
end
|
||||
|
||||
markdown_lines = vim.lsp.util.stylize_markdown(state.hover_buf, markdown_lines, {})
|
||||
@@ -139,18 +139,18 @@ local function setup_hover_buf()
|
||||
return
|
||||
end
|
||||
local code_buf = vim.api.nvim_win_get_buf(main.state.code_win)
|
||||
local ft = vim.api.nvim_buf_get_option(code_buf, "filetype")
|
||||
vim.api.nvim_buf_set_option(state.hover_buf, "syntax", ft)
|
||||
vim.api.nvim_buf_set_option(state.hover_buf, "bufhidden", "delete")
|
||||
vim.api.nvim_win_set_option(state.hover_win, "wrap", true)
|
||||
vim.api.nvim_win_set_option(state.hover_win, "cursorline", false)
|
||||
local ft = vim.api.nvim_buf_get_option(code_buf, 'filetype')
|
||||
vim.api.nvim_buf_set_option(state.hover_buf, 'syntax', ft)
|
||||
vim.api.nvim_buf_set_option(state.hover_buf, 'bufhidden', 'delete')
|
||||
vim.api.nvim_win_set_option(state.hover_win, 'wrap', true)
|
||||
vim.api.nvim_win_set_option(state.hover_win, 'cursorline', false)
|
||||
update_hover()
|
||||
end
|
||||
|
||||
local function set_bg_hl()
|
||||
local winhi = "Normal:" .. config.options.preview_bg_highlight
|
||||
vim.api.nvim_win_set_option(state.preview_win, "winhighlight", winhi)
|
||||
vim.api.nvim_win_set_option(state.hover_win, "winhighlight", winhi)
|
||||
local winhi = 'Normal:' .. config.options.preview_bg_highlight
|
||||
vim.api.nvim_win_set_option(state.preview_win, 'winhighlight', winhi)
|
||||
vim.api.nvim_win_set_option(state.hover_win, 'winhighlight', winhi)
|
||||
end
|
||||
|
||||
local function show_preview()
|
||||
@@ -164,7 +164,7 @@ local function show_preview()
|
||||
})
|
||||
local offsets = get_offset()
|
||||
state.preview_win = vim.api.nvim_open_win(state.preview_buf, false, {
|
||||
relative = "win",
|
||||
relative = 'win',
|
||||
width = 50,
|
||||
height = get_height(),
|
||||
bufpos = { 0, 0 },
|
||||
@@ -190,7 +190,7 @@ local function show_hover()
|
||||
local offsets = get_offset()
|
||||
local height = get_height()
|
||||
state.hover_win = vim.api.nvim_open_win(state.hover_buf, false, {
|
||||
relative = "win",
|
||||
relative = 'win',
|
||||
width = 50,
|
||||
height = height,
|
||||
bufpos = { 0, 0 },
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
local M = {}
|
||||
|
||||
function M.should_use_provider(_)
|
||||
local not_coc_installed = vim.fn.exists("*CocActionAsync") == 0
|
||||
local not_coc_installed = vim.fn.exists '*CocActionAsync' == 0
|
||||
local not_coc_service_initialized = vim.g.coc_service_initialized == 0
|
||||
|
||||
if not_coc_installed or not_coc_service_initialized then
|
||||
return
|
||||
end
|
||||
|
||||
local coc_attached = vim.fn.call("CocAction", { "ensureDocument" })
|
||||
local has_symbols = vim.fn.call("CocHasProvider", { "documentSymbol" })
|
||||
local coc_attached = vim.fn.call('CocAction', { 'ensureDocument' })
|
||||
local has_symbols = vim.fn.call('CocHasProvider', { 'documentSymbol' })
|
||||
|
||||
return coc_attached and has_symbols
|
||||
end
|
||||
|
||||
function M.hover_info(_, _, on_info)
|
||||
on_info(nil, { contents = { kind = "markdown", contents = { "No extra information availaible!" } } })
|
||||
on_info(nil, { contents = { kind = 'markdown', contents = { 'No extra information availaible!' } } })
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
vim.fn.call("CocActionAsync", {
|
||||
"documentSymbols",
|
||||
vim.fn.call('CocActionAsync', {
|
||||
'documentSymbols',
|
||||
function(_, symbols)
|
||||
on_symbols({ [1000000] = { result = symbols } })
|
||||
on_symbols { [1000000] = { result = symbols } }
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
local providers = {
|
||||
"symbols-outline/providers/nvim-lsp",
|
||||
"symbols-outline/providers/coc",
|
||||
"symbols-outline/providers/markdown",
|
||||
'symbols-outline/providers/nvim-lsp',
|
||||
'symbols-outline/providers/coc',
|
||||
'symbols-outline/providers/markdown',
|
||||
}
|
||||
|
||||
_G._symbols_outline_current_provider = nil
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
local md_parser = require("symbols-outline.markdown")
|
||||
local md_parser = require 'symbols-outline.markdown'
|
||||
|
||||
local M = {}
|
||||
|
||||
-- probably change this
|
||||
function M.should_use_provider(bufnr)
|
||||
return string.match(vim.api.nvim_buf_get_option(bufnr, "ft"), "markdown")
|
||||
return string.match(vim.api.nvim_buf_get_option(bufnr, 'ft'), 'markdown')
|
||||
end
|
||||
|
||||
function M.hover_info(_, _, on_info)
|
||||
on_info(nil, { contents = { kind = "markdown", contents = { "No extra information availaible!" } } })
|
||||
on_info(nil, { contents = { kind = 'markdown', contents = { 'No extra information availaible!' } } })
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local config = require("symbols-outline.config")
|
||||
local config = require 'symbols-outline.config'
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -23,10 +23,10 @@ function M.hover_info(bufnr, params, on_info)
|
||||
end
|
||||
|
||||
if not used_client then
|
||||
on_info(nil, { contents = { kind = "markdown", content = { "No extra information availaible!" } } })
|
||||
on_info(nil, { contents = { kind = 'markdown', content = { 'No extra information availaible!' } } })
|
||||
end
|
||||
|
||||
used_client.request("textDocument/hover", params, on_info, bufnr)
|
||||
used_client.request('textDocument/hover', params, on_info, bufnr)
|
||||
end
|
||||
|
||||
-- probably change this
|
||||
@@ -51,7 +51,7 @@ end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(), on_symbols)
|
||||
vim.lsp.buf_request_all(0, 'textDocument/documentSymbol', getParams(), on_symbols)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
local vim = vim
|
||||
|
||||
local main = require('symbols-outline')
|
||||
local main = require 'symbols-outline'
|
||||
local buf_request = require('symbols-outline.utils.lsp_utils').request
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_rename_params(node, winnr)
|
||||
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
||||
local fn = "file://" .. vim.api.nvim_buf_get_name(bufnr)
|
||||
local fn = 'file://' .. vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
return {
|
||||
textDocument = {uri = fn},
|
||||
position = {line = node.line, character = node.character},
|
||||
bufnr = bufnr
|
||||
textDocument = { uri = fn },
|
||||
position = { line = node.line, character = node.character },
|
||||
bufnr = bufnr,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -22,13 +22,14 @@ function M.rename()
|
||||
|
||||
local params = get_rename_params(node, main.state.code_win)
|
||||
|
||||
local new_name = vim.fn.input("New Name: ", node.name)
|
||||
if not new_name or new_name == "" or new_name == node.name then return end
|
||||
local new_name = vim.fn.input('New Name: ', node.name)
|
||||
if not new_name or new_name == '' or new_name == node.name then
|
||||
return
|
||||
end
|
||||
|
||||
params.newName = new_name
|
||||
|
||||
buf_request(params.bufnr, "textDocument/rename", params,
|
||||
function(_, result)
|
||||
buf_request(params.bufnr, 'textDocument/rename', params, function(_, result)
|
||||
if result ~= nil then
|
||||
vim.lsp.util.apply_workspace_edit(result)
|
||||
end
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
local config = require('symbols-outline.config')
|
||||
local config = require 'symbols-outline.config'
|
||||
|
||||
local M = {}
|
||||
|
||||
M.kinds = {
|
||||
"File", "Module", "Namespace", "Package", "Class", "Method", "Property",
|
||||
"Field", "Constructor", "Enum", "Interface", "Function", "Variable",
|
||||
"Constant", "String", "Number", "Boolean", "Array", "Object", "Key", "Null",
|
||||
"EnumMember", "Struct", "Event", "Operator", "TypeParameter"
|
||||
'File',
|
||||
'Module',
|
||||
'Namespace',
|
||||
'Package',
|
||||
'Class',
|
||||
'Method',
|
||||
'Property',
|
||||
'Field',
|
||||
'Constructor',
|
||||
'Enum',
|
||||
'Interface',
|
||||
'Function',
|
||||
'Variable',
|
||||
'Constant',
|
||||
'String',
|
||||
'Number',
|
||||
'Boolean',
|
||||
'Array',
|
||||
'Object',
|
||||
'Key',
|
||||
'Null',
|
||||
'EnumMember',
|
||||
'Struct',
|
||||
'Event',
|
||||
'Operator',
|
||||
'TypeParameter',
|
||||
}
|
||||
|
||||
function M.icon_from_kind(kind)
|
||||
@@ -17,7 +39,9 @@ function M.icon_from_kind(kind)
|
||||
end
|
||||
|
||||
-- If the kind is higher than the available ones then default to 'Object'
|
||||
if kind > #M.kinds then kind = 19 end
|
||||
if kind > #M.kinds then
|
||||
kind = 19
|
||||
end
|
||||
return symbols[M.kinds[kind]].icon
|
||||
end
|
||||
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
local vim = vim
|
||||
local config = require('symbols-outline.config')
|
||||
local config = require 'symbols-outline.config'
|
||||
local symbol_kinds = require('symbols-outline.symbols').kinds
|
||||
local M = {}
|
||||
|
||||
M.markers = {
|
||||
bottom = "└",
|
||||
middle = "├",
|
||||
vertical = "│",
|
||||
horizontal = "─"
|
||||
bottom = '└',
|
||||
middle = '├',
|
||||
vertical = '│',
|
||||
horizontal = '─',
|
||||
}
|
||||
|
||||
M.hovered_hl_ns = vim.api.nvim_create_namespace("hovered_item")
|
||||
M.hovered_hl_ns = vim.api.nvim_create_namespace 'hovered_item'
|
||||
|
||||
function M.clear_hover_highlight(bufnr)
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, M.hovered_hl_ns, 0, -1)
|
||||
end
|
||||
|
||||
function M.add_hover_highlight(bufnr, line, col_start)
|
||||
vim.api.nvim_buf_add_highlight(bufnr, M.hovered_hl_ns, "FocusedSymbol",
|
||||
line, col_start, -1)
|
||||
vim.api.nvim_buf_add_highlight(bufnr, M.hovered_hl_ns, 'FocusedSymbol', line, col_start, -1)
|
||||
end
|
||||
|
||||
local function highlight_text(name, text, hl_group)
|
||||
vim.cmd(string.format("syn match %s /%s/", name, text))
|
||||
vim.cmd(string.format("hi def link %s %s", name, hl_group))
|
||||
vim.cmd(string.format('syn match %s /%s/', name, text))
|
||||
vim.cmd(string.format('hi def link %s %s', name, hl_group))
|
||||
end
|
||||
|
||||
function M.setup_highlights()
|
||||
-- Setup the FocusedSymbol highlight group if it hasn't been done already by
|
||||
-- a theme or manually set
|
||||
if vim.fn.hlexists('FocusedSymbol') == 0 then
|
||||
if vim.fn.hlexists 'FocusedSymbol' == 0 then
|
||||
vim.cmd 'hi FocusedSymbol term=italic,bold cterm=italic ctermbg=yellow ctermfg=darkblue gui=bold,italic guibg=yellow guifg=darkblue'
|
||||
end
|
||||
|
||||
@@ -37,21 +36,19 @@ function M.setup_highlights()
|
||||
-- notably making them italic, which messes up the outline connector. Fix
|
||||
-- this by copying the foreground color from the comment hl into a new
|
||||
-- highlight.
|
||||
local comment_fg_gui = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID('Comment')), 'fg', 'gui')
|
||||
local comment_fg_gui = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID 'Comment'), 'fg', 'gui')
|
||||
|
||||
if vim.fn.hlexists('SymbolsOutlineConnector') == 0 then
|
||||
if vim.fn.hlexists 'SymbolsOutlineConnector' == 0 then
|
||||
vim.cmd(string.format('hi SymbolsOutlineConnector guifg=%s', comment_fg_gui))
|
||||
end
|
||||
|
||||
local symbols = config.options.symbols
|
||||
|
||||
-- markers
|
||||
highlight_text("marker_middle", M.markers.middle, "SymbolsOutlineConnector")
|
||||
highlight_text("marker_vertical", M.markers.vertical,
|
||||
"SymbolsOutlineConnector")
|
||||
highlight_text("markers_horizontal", M.markers.horizontal,
|
||||
"SymbolsOutlineConnector")
|
||||
highlight_text("markers_bottom", M.markers.bottom, "SymbolsOutlineConnector")
|
||||
highlight_text('marker_middle', M.markers.middle, 'SymbolsOutlineConnector')
|
||||
highlight_text('marker_vertical', M.markers.vertical, 'SymbolsOutlineConnector')
|
||||
highlight_text('markers_horizontal', M.markers.horizontal, 'SymbolsOutlineConnector')
|
||||
highlight_text('markers_bottom', M.markers.bottom, 'SymbolsOutlineConnector')
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -4,11 +4,12 @@ local M = {}
|
||||
---@param keys table|string
|
||||
---@param action string
|
||||
function M.nmap(bufnr, keys, action)
|
||||
if type(keys) == 'string' then keys = {keys} end
|
||||
if type(keys) == 'string' then
|
||||
keys = { keys }
|
||||
end
|
||||
|
||||
for _, value in ipairs(keys) do
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", value, action,
|
||||
{silent = true, noremap = true})
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', value, action, { silent = true, noremap = true })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,13 +19,17 @@ end
|
||||
function M.debounce(f, delay)
|
||||
local timer = vim.loop.new_timer()
|
||||
|
||||
return function (...)
|
||||
return function(...)
|
||||
local args = { ... }
|
||||
|
||||
timer:start(delay, 0, vim.schedule_wrap(function ()
|
||||
timer:start(
|
||||
delay,
|
||||
0,
|
||||
vim.schedule_wrap(function()
|
||||
timer:stop()
|
||||
f(unpack(args))
|
||||
end))
|
||||
end)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ local M = {}
|
||||
local function mk_handler(fn)
|
||||
return function(...)
|
||||
local config_or_client_id = select(4, ...)
|
||||
local is_new = type(config_or_client_id) ~= "number"
|
||||
local is_new = type(config_or_client_id) ~= 'number'
|
||||
if is_new then
|
||||
fn(...)
|
||||
else
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local config = require('symbols-outline.config')
|
||||
local config = require 'symbols-outline.config'
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -10,31 +10,31 @@ function M.setup_view()
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
-- delete buffer when window is closed / buffer is hidden
|
||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "delete")
|
||||
vim.api.nvim_buf_set_option(bufnr, 'bufhidden', 'delete')
|
||||
-- create a split
|
||||
vim.cmd(config.get_split_command())
|
||||
-- resize to a % of the current window size
|
||||
vim.cmd("vertical resize " .. config.get_window_width())
|
||||
vim.cmd('vertical resize ' .. config.get_window_width())
|
||||
|
||||
-- get current (outline) window and attach our buffer to it
|
||||
local winnr = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_buf(winnr, bufnr)
|
||||
|
||||
-- window stuff
|
||||
vim.api.nvim_win_set_option(winnr, "number", false)
|
||||
vim.api.nvim_win_set_option(winnr, "relativenumber", false)
|
||||
vim.api.nvim_win_set_option(winnr, "winfixwidth", true)
|
||||
vim.api.nvim_win_set_option(winnr, 'number', false)
|
||||
vim.api.nvim_win_set_option(winnr, 'relativenumber', false)
|
||||
vim.api.nvim_win_set_option(winnr, 'winfixwidth', true)
|
||||
-- buffer stuff
|
||||
vim.api.nvim_buf_set_name(bufnr, "OUTLINE")
|
||||
vim.api.nvim_buf_set_option(bufnr, "filetype", "Outline")
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.api.nvim_buf_set_name(bufnr, 'OUTLINE')
|
||||
vim.api.nvim_buf_set_option(bufnr, 'filetype', 'Outline')
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
||||
|
||||
if config.options.show_numbers or config.options.show_relative_numbers then
|
||||
vim.api.nvim_win_set_option(winnr, "nu", true)
|
||||
vim.api.nvim_win_set_option(winnr, 'nu', true)
|
||||
end
|
||||
|
||||
if config.options.show_relative_numbers then
|
||||
vim.api.nvim_win_set_option(winnr, "rnu", true)
|
||||
vim.api.nvim_win_set_option(winnr, 'rnu', true)
|
||||
end
|
||||
|
||||
return bufnr, winnr
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
local vim = vim
|
||||
|
||||
local parser = require('symbols-outline.parser')
|
||||
local config = require('symbols-outline.config')
|
||||
local parser = require 'symbols-outline.parser'
|
||||
local config = require 'symbols-outline.config'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function is_buffer_outline(bufnr)
|
||||
local isValid = vim.api.nvim_buf_is_valid(bufnr)
|
||||
local name = vim.api.nvim_buf_get_name(bufnr)
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
return string.match(name, "OUTLINE") ~= nil and ft == "Outline" and isValid
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
|
||||
return string.match(name, 'OUTLINE') ~= nil and ft == 'Outline' and isValid
|
||||
end
|
||||
|
||||
local hlns = vim.api.nvim_create_namespace("symbols-outline-icon-highlight")
|
||||
local hlns = vim.api.nvim_create_namespace 'symbols-outline-icon-highlight'
|
||||
|
||||
function M.write_outline(bufnr, lines)
|
||||
if not is_buffer_outline(bufnr) then return end
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
if not is_buffer_outline(bufnr) then
|
||||
return
|
||||
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)
|
||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
||||
end
|
||||
|
||||
function M.add_highlights(bufnr, hl_info)
|
||||
@@ -28,17 +30,21 @@ function M.add_highlights(bufnr, hl_info)
|
||||
end
|
||||
end
|
||||
|
||||
local ns = vim.api.nvim_create_namespace("symbols-outline-virt-text")
|
||||
local ns = vim.api.nvim_create_namespace 'symbols-outline-virt-text'
|
||||
|
||||
function M.write_details(bufnr, lines)
|
||||
if not is_buffer_outline(bufnr) then return end
|
||||
if not config.options.show_symbol_details then return end
|
||||
if not is_buffer_outline(bufnr) then
|
||||
return
|
||||
end
|
||||
if not config.options.show_symbol_details then
|
||||
return
|
||||
end
|
||||
|
||||
for index, value in ipairs(lines) do
|
||||
vim.api.nvim_buf_set_extmark(bufnr, ns, index - 1, -1, {
|
||||
virt_text = {{value, "Comment"}},
|
||||
virt_text_pos = "eol",
|
||||
hl_mode = "combine"
|
||||
virt_text = { { value, 'Comment' } },
|
||||
virt_text_pos = 'eol',
|
||||
hl_mode = 'combine',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
6
stylua.toml
Normal file
6
stylua.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
column_width = 120
|
||||
line_endings = 'Unix'
|
||||
indent_type = 'Spaces'
|
||||
indent_width = 2
|
||||
quote_style = 'AutoPreferSingle'
|
||||
call_parentheses = 'None'
|
||||
Reference in New Issue
Block a user