chore: stylua
This commit is contained in:
@@ -52,7 +52,10 @@ M._refresh = utils.debounce(__refresh, 100)
|
||||
local function goto_location(change_focus)
|
||||
local current_line = vim.api.nvim_win_get_cursor(M.view.winnr)[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 })
|
||||
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
|
||||
@@ -64,11 +67,14 @@ end
|
||||
function M._highlight_current_item(winnr)
|
||||
local has_provider = providers.has_provider()
|
||||
|
||||
local is_current_buffer_the_outline = M.view.bufnr == vim.api.nvim_get_current_buf()
|
||||
local is_current_buffer_the_outline = M.view.bufnr
|
||||
== vim.api.nvim_get_current_buf()
|
||||
|
||||
local doesnt_have_outline_buf = not M.view.bufnr
|
||||
|
||||
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
|
||||
@@ -87,7 +93,10 @@ 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
|
||||
@@ -96,7 +105,11 @@ function M._highlight_current_item(winnr)
|
||||
-- clear old highlight
|
||||
ui.clear_hover_highlight(M.view.bufnr)
|
||||
for _, value in ipairs(nodes) do
|
||||
ui.add_hover_highlight(M.view.bufnr, value.line_in_outline - 1, value.depth * 2)
|
||||
ui.add_hover_highlight(
|
||||
M.view.bufnr,
|
||||
value.line_in_outline - 1,
|
||||
value.depth * 2
|
||||
)
|
||||
vim.api.nvim_win_set_cursor(M.view.winnr, { value.line_in_outline, 1 })
|
||||
end
|
||||
end
|
||||
@@ -114,17 +127,28 @@ local function setup_keymaps(bufnr)
|
||||
goto_location(false)
|
||||
end)
|
||||
-- hover symbol
|
||||
map(config.options.keymaps.hover_symbol, require('symbols-outline.hover').show_hover)
|
||||
map(
|
||||
config.options.keymaps.hover_symbol,
|
||||
require('symbols-outline.hover').show_hover
|
||||
)
|
||||
-- rename symbol
|
||||
map(config.options.keymaps.rename_symbol, require('symbols-outline.rename').rename)
|
||||
map(
|
||||
config.options.keymaps.rename_symbol,
|
||||
require('symbols-outline.rename').rename
|
||||
)
|
||||
-- code actions
|
||||
map(config.options.keymaps.code_actions, require('symbols-outline.code_action').show_code_actions)
|
||||
map(
|
||||
config.options.keymaps.code_actions,
|
||||
require('symbols-outline.code_action').show_code_actions
|
||||
)
|
||||
-- show help
|
||||
map(config.options.keymaps.show_help, require('symbols-outline.config').show_help)
|
||||
map(
|
||||
config.options.keymaps.show_help,
|
||||
require('symbols-outline.config').show_help
|
||||
)
|
||||
-- close outline
|
||||
map(config.options.keymaps.close,
|
||||
function ()
|
||||
M.view:close()
|
||||
map(config.options.keymaps.close, function()
|
||||
M.view:close()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -25,7 +25,12 @@ 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
|
||||
|
||||
@@ -22,19 +22,26 @@ function M.show_hover()
|
||||
|
||||
local hover_params = get_hover_params(node, so.state.code_win)
|
||||
|
||||
buf_request(hover_params.bufnr, 'textDocument/hover', hover_params, function(_, result, _, config)
|
||||
if not (result and result.contents) then
|
||||
-- return { 'No information available' }
|
||||
return
|
||||
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
|
||||
)
|
||||
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)
|
||||
end
|
||||
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)
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -131,7 +131,9 @@ function M.parse(response)
|
||||
end
|
||||
|
||||
local result = client_response['result']
|
||||
if result == nil or type(result) ~= 'table' then goto continue end
|
||||
if result == nil or type(result) ~= 'table' then
|
||||
goto continue
|
||||
end
|
||||
|
||||
for _, value in pairs(result) do
|
||||
table.insert(all_results, value)
|
||||
|
||||
@@ -66,7 +66,10 @@ local function update_preview(code_buf)
|
||||
|
||||
if state.preview_buf ~= nil then
|
||||
vim.api.nvim_buf_set_lines(state.preview_buf, 0, -1, 0, lines)
|
||||
vim.api.nvim_win_set_cursor(state.preview_win, { node.line + 1, node.character })
|
||||
vim.api.nvim_win_set_cursor(
|
||||
state.preview_win,
|
||||
{ node.line + 1, node.character }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,14 +122,20 @@ local function update_hover()
|
||||
end
|
||||
local markdown_lines = {}
|
||||
if result ~= nil then
|
||||
markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
|
||||
markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(
|
||||
result.contents
|
||||
)
|
||||
end
|
||||
markdown_lines = vim.lsp.util.trim_empty_lines(markdown_lines)
|
||||
if vim.tbl_isempty(markdown_lines) then
|
||||
markdown_lines = { '###No info available!' }
|
||||
end
|
||||
|
||||
markdown_lines = vim.lsp.util.stylize_markdown(state.hover_buf, markdown_lines, {})
|
||||
markdown_lines = vim.lsp.util.stylize_markdown(
|
||||
state.hover_buf,
|
||||
markdown_lines,
|
||||
{}
|
||||
)
|
||||
|
||||
if state.hover_buf ~= nil then
|
||||
vim.api.nvim_buf_set_lines(state.hover_buf, 0, -1, 0, markdown_lines)
|
||||
@@ -219,10 +228,14 @@ end
|
||||
|
||||
function M.close()
|
||||
if has_code_win() then
|
||||
if state.preview_win ~= nil and vim.api.nvim_win_is_valid(state.preview_win) then
|
||||
if
|
||||
state.preview_win ~= nil and vim.api.nvim_win_is_valid(state.preview_win)
|
||||
then
|
||||
vim.api.nvim_win_close(state.preview_win, true)
|
||||
end
|
||||
if state.hover_win ~= nil and vim.api.nvim_win_is_valid(state.hover_win) then
|
||||
if
|
||||
state.hover_win ~= nil and vim.api.nvim_win_is_valid(state.hover_win)
|
||||
then
|
||||
vim.api.nvim_win_close(state.hover_win, true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,15 @@ function M.should_use_provider(_)
|
||||
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,24 +1,33 @@
|
||||
local M = {}
|
||||
|
||||
local parsers = require("nvim-treesitter.parsers")
|
||||
local parsers = require 'nvim-treesitter.parsers'
|
||||
|
||||
local SYMBOL_COMPONENT = 27
|
||||
local SYMBOL_FRAGMENT = 28
|
||||
|
||||
function M.should_use_provider(bufnr)
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
|
||||
|
||||
return string.match(ft, 'typescriptreact') or string.match(ft, 'javascriptreact')
|
||||
return string.match(ft, 'typescriptreact')
|
||||
or string.match(ft, 'javascriptreact')
|
||||
end
|
||||
|
||||
function M.hover_info(_, _, on_info)
|
||||
on_info(nil, { contents = { kind = 'nvim-lsp-jsx', contents = { 'No extra information availaible!' } } })
|
||||
on_info(
|
||||
nil,
|
||||
{
|
||||
contents = {
|
||||
kind = 'nvim-lsp-jsx',
|
||||
contents = { 'No extra information availaible!' },
|
||||
},
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local function get_open_tag(node)
|
||||
if node:type() == "jsx_element" then
|
||||
for _, outer in ipairs(node:field("open_tag")) do
|
||||
if outer:type() == "jsx_opening_element" then
|
||||
if node:type() == 'jsx_element' then
|
||||
for _, outer in ipairs(node:field 'open_tag') do
|
||||
if outer:type() == 'jsx_opening_element' then
|
||||
return outer
|
||||
end
|
||||
end
|
||||
@@ -30,14 +39,21 @@ end
|
||||
local function jsx_node_detail(node, buf)
|
||||
node = get_open_tag(node) or node
|
||||
|
||||
local param_nodes = node:field("attribute")
|
||||
if #param_nodes == 0 then return nil end
|
||||
local param_nodes = node:field 'attribute'
|
||||
if #param_nodes == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
local res = '{ ' .. table.concat(vim.tbl_map(function (el)
|
||||
local a, b, c, d = el:range()
|
||||
local text = vim.api.nvim_buf_get_text(buf, a, b, c, d, {})
|
||||
return text[1]
|
||||
end, param_nodes), ' ') .. ' }'
|
||||
local res = '{ '
|
||||
.. table.concat(
|
||||
vim.tbl_map(function(el)
|
||||
local a, b, c, d = el:range()
|
||||
local text = vim.api.nvim_buf_get_text(buf, a, b, c, d, {})
|
||||
return text[1]
|
||||
end, param_nodes),
|
||||
' '
|
||||
)
|
||||
.. ' }'
|
||||
|
||||
return res
|
||||
end
|
||||
@@ -47,7 +63,7 @@ local function jsx_node_tagname(node, buf)
|
||||
|
||||
local identifier = nil
|
||||
|
||||
for _, val in ipairs(tagnode:field('name')) do
|
||||
for _, val in ipairs(tagnode:field 'name') do
|
||||
if val:type() == 'identifier' then
|
||||
identifier = val
|
||||
end
|
||||
@@ -62,28 +78,37 @@ local function jsx_node_tagname(node, buf)
|
||||
end
|
||||
|
||||
local function convert_ts(child, children, bufnr)
|
||||
local is_frag = (child:type() == 'jsx_fragment')
|
||||
local is_frag = (child:type() == 'jsx_fragment')
|
||||
|
||||
local a, b, c, d = child:range()
|
||||
local range = { start = { line = a, character = b }, ['end'] = { line = c, character = d } }
|
||||
local a, b, c, d = child:range()
|
||||
local range = {
|
||||
start = { line = a, character = b },
|
||||
['end'] = { line = c, character = d },
|
||||
}
|
||||
|
||||
local converted = {
|
||||
name = (not is_frag and (jsx_node_tagname(child, bufnr) or '<unknown>')) or 'fragment',
|
||||
children = (#children > 0 and children) or nil,
|
||||
kind = (is_frag and SYMBOL_FRAGMENT) or SYMBOL_COMPONENT,
|
||||
detail = jsx_node_detail(child, bufnr),
|
||||
range = range,
|
||||
selectionRange = range
|
||||
}
|
||||
local converted = {
|
||||
name = (not is_frag and (jsx_node_tagname(child, bufnr) or '<unknown>'))
|
||||
or 'fragment',
|
||||
children = (#children > 0 and children) or nil,
|
||||
kind = (is_frag and SYMBOL_FRAGMENT) or SYMBOL_COMPONENT,
|
||||
detail = jsx_node_detail(child, bufnr),
|
||||
range = range,
|
||||
selectionRange = range,
|
||||
}
|
||||
|
||||
return converted
|
||||
return converted
|
||||
end
|
||||
|
||||
local function parse_ts(root, children, bufnr)
|
||||
children = children or {}
|
||||
|
||||
for child in root:iter_children() do
|
||||
if vim.tbl_contains({ 'jsx_element', 'jsx_self_closing_element' }, child:type()) then
|
||||
if
|
||||
vim.tbl_contains(
|
||||
{ 'jsx_element', 'jsx_self_closing_element' },
|
||||
child:type()
|
||||
)
|
||||
then
|
||||
local new_children = {}
|
||||
|
||||
parse_ts(child, new_children, bufnr)
|
||||
@@ -105,7 +130,7 @@ function M.request_symbols(on_symbols)
|
||||
|
||||
local symbols = parse_ts(root, nil, bufnr)
|
||||
-- local symbols = convert_ts(ctree)
|
||||
on_symbols({ [1000000] = { result = symbols }})
|
||||
on_symbols { [1000000] = { result = symbols } }
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -8,7 +8,15 @@ function M.should_use_provider(bufnr)
|
||||
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
|
||||
|
||||
@@ -23,7 +23,15 @@ 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)
|
||||
@@ -51,7 +59,12 @@ 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
|
||||
|
||||
@@ -27,12 +27,17 @@ function M.rename()
|
||||
|
||||
params.newName = new_name
|
||||
|
||||
buf_request(params.bufnr, 'textDocument/rename', params, function(_, result, ctx)
|
||||
if result ~= nil then
|
||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||
vim.lsp.util.apply_workspace_edit(result, client.offset_encoding)
|
||||
buf_request(
|
||||
params.bufnr,
|
||||
'textDocument/rename',
|
||||
params,
|
||||
function(_, result, ctx)
|
||||
if result ~= nil then
|
||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||
vim.lsp.util.apply_workspace_edit(result, client.offset_encoding)
|
||||
end
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -17,7 +17,14 @@ function M.clear_hover_highlight(bufnr)
|
||||
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)
|
||||
@@ -36,18 +43,32 @@ 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
|
||||
vim.cmd(string.format('hi SymbolsOutlineConnector guifg=%s', comment_fg_gui))
|
||||
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(
|
||||
'marker_vertical',
|
||||
M.markers.vertical,
|
||||
'SymbolsOutlineConnector'
|
||||
)
|
||||
highlight_text(
|
||||
'markers_horizontal',
|
||||
M.markers.horizontal,
|
||||
'SymbolsOutlineConnector'
|
||||
)
|
||||
highlight_text('markers_bottom', M.markers.bottom, 'SymbolsOutlineConnector')
|
||||
end
|
||||
|
||||
|
||||
@@ -8,9 +8,13 @@ function M.nmap(bufnr, keys, action)
|
||||
keys = { keys }
|
||||
end
|
||||
|
||||
|
||||
for _, lhs in ipairs(keys) do
|
||||
vim.keymap.set('n', lhs, action, { silent = true, noremap = true, buffer = bufnr })
|
||||
vim.keymap.set(
|
||||
'n',
|
||||
lhs,
|
||||
action,
|
||||
{ silent = true, noremap = true, buffer = bufnr }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,12 @@ local function mk_handler(fn)
|
||||
local client_id = select(4, ...)
|
||||
local bufnr = select(5, ...)
|
||||
local config = select(6, ...)
|
||||
fn(err, result, { method = method, client_id = client_id, bufnr = bufnr }, config)
|
||||
fn(
|
||||
err,
|
||||
result,
|
||||
{ method = method, client_id = client_id, bufnr = bufnr },
|
||||
config
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +47,10 @@ function View:close()
|
||||
end
|
||||
|
||||
function View:is_open()
|
||||
return self.winnr and self.bufnr and vim.api.nvim_buf_is_valid(self.bufnr) and vim.api.nvim_win_is_valid(self.winnr)
|
||||
return self.winnr
|
||||
and self.bufnr
|
||||
and vim.api.nvim_buf_is_valid(self.bufnr)
|
||||
and vim.api.nvim_win_is_valid(self.winnr)
|
||||
end
|
||||
|
||||
return View
|
||||
|
||||
@@ -26,7 +26,14 @@ end
|
||||
function M.add_highlights(bufnr, hl_info)
|
||||
for line, line_hl in ipairs(hl_info) do
|
||||
hl_start, hl_end, hl_type = unpack(line_hl)
|
||||
vim.api.nvim_buf_add_highlight(bufnr, hlns, hl_type, line - 1, hl_start, hl_end)
|
||||
vim.api.nvim_buf_add_highlight(
|
||||
bufnr,
|
||||
hlns,
|
||||
hl_type,
|
||||
line - 1,
|
||||
hl_start,
|
||||
hl_end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
column_width = 120
|
||||
column_width = 80
|
||||
line_endings = 'Unix'
|
||||
indent_type = 'Spaces'
|
||||
indent_width = 2
|
||||
|
||||
Reference in New Issue
Block a user