mirror of
https://github.com/ray-x/navigator.lua
synced 2024-11-05 12:00:21 +00:00
update gui for workspace symbol
This commit is contained in:
parent
873135bf9a
commit
abf5de64fd
@ -2,14 +2,14 @@ local log = require('navigator.util').log
|
||||
local trace = require('navigator.util').trace
|
||||
|
||||
local event_hdlrs = {
|
||||
{ ev = 'BufWritePre', func = [[require "navigator.diagnostics".set_diag_loclist()]] },
|
||||
{ ev = 'CursorHold', func = 'document_highlight()' },
|
||||
{ ev = 'CursorHoldI', func = 'document_highlight()' },
|
||||
{ ev = 'CursorMoved', func = 'clear_references()' },
|
||||
{ev = 'BufWritePre', func = [[require "navigator.diagnostics".set_diag_loclist()]]},
|
||||
{ev = 'CursorHold', func = 'document_highlight()'},
|
||||
{ev = 'CursorHoldI', func = 'document_highlight()'},
|
||||
{ev = 'CursorMoved', func = 'clear_references()'}
|
||||
}
|
||||
|
||||
local double = { '╔', '═', '╗', '║', '╝', '═', '╚', '║' }
|
||||
local single = { '╭', '─', '╮', '│', '╯', '─', '╰', '│' }
|
||||
local double = {'╔', '═', '╗', '║', '╝', '═', '╚', '║'}
|
||||
local single = {'╭', '─', '╮', '│', '╯', '─', '╰', '│'}
|
||||
-- LuaFormatter off
|
||||
local key_maps = {
|
||||
{ key = 'gr', func = "require('navigator.reference').reference()" },
|
||||
@ -17,7 +17,7 @@ local key_maps = {
|
||||
{ mode = 'i', key = '<M-k>', func = 'signature_help()' },
|
||||
{ key = '<c-k>', func = 'signature_help()' },
|
||||
{ key = 'g0', func = "require('navigator.symbols').document_symbols()" },
|
||||
{ key = 'gW', func = 'workspace_symbol()' },
|
||||
{ key = 'gW', func = "require('navigator.workspace').workspace_symbol()" },
|
||||
{ key = '<c-]>', func = "require('navigator.definition').definition()" },
|
||||
{ key = 'gD', func = "declaration({ border = 'rounded', max_width = 80 })" },
|
||||
{ key = 'gp', func = "require('navigator.definition').definition_preview()" },
|
||||
@ -26,7 +26,7 @@ local key_maps = {
|
||||
{ key = 'K', func = 'hover({ popup_opts = { border = single, max_width = 80 }})' },
|
||||
{ key = '<Space>ca', mode = 'n', func = "require('navigator.codeAction').code_action()" },
|
||||
{ key = '<Space>cA', mode = 'v', func = 'range_code_action()' },
|
||||
{ key = '<Leader>re', func = 'rename()' },
|
||||
-- { key = '<Leader>re', func = 'rename()' },
|
||||
{ key = '<Space>rn', func = "require('navigator.rename').rename()" },
|
||||
{ key = '<Leader>gi', func = 'incoming_calls()' },
|
||||
{ key = '<Leader>go', func = 'outgoing_calls()' },
|
||||
@ -42,11 +42,11 @@ local key_maps = {
|
||||
{ key = '<C-LeftMouse>', func = 'definition()' },
|
||||
{ key = 'g<LeftMouse>', func = 'implementation()' },
|
||||
{ key = '<Leader>k', func = "require('navigator.dochighlight').hi_symbol()" },
|
||||
{ key = '<Space>wa', func = 'add_workspace_folder()' },
|
||||
{ key = '<Space>wr', func = 'remove_workspace_folder()' },
|
||||
{ key = '<Space>wa', func = "require('navigator.workspace').add_workspace_folder()" },
|
||||
{ key = '<Space>wr', func = "require('navigator.workspace').remove_workspace_folder()" },
|
||||
{ key = '<Space>ff', func = 'formatting()', mode = 'n' },
|
||||
{ key = '<Space>ff', func = 'range_formatting()', mode = 'v' },
|
||||
{ key = '<Space>wl', func = 'vim.notify(vim.inspect(vim.lsp.buf.list_workspace_folders()))' },
|
||||
{ key = '<Space>wl', func = "require('navigator.workspace').list_workspace_folders()" },
|
||||
{ key = '<Space>la', mode = 'n', func = "require('navigator.codelens').run_action()" },
|
||||
}
|
||||
|
||||
@ -55,8 +55,8 @@ local key_maps_help = {}
|
||||
local M = {}
|
||||
|
||||
local ccls_mappings = {
|
||||
{ key = '<Leader>gi', func = "require('navigator.cclshierarchy').incoming_calls()" },
|
||||
{ key = '<Leader>go', func = "require('navigator.cclshierarchy').outgoing_calls()" },
|
||||
{key = '<Leader>gi', func = "require('navigator.cclshierarchy').incoming_calls()"},
|
||||
{key = '<Leader>go', func = "require('navigator.cclshierarchy').outgoing_calls()"}
|
||||
}
|
||||
|
||||
local check_cap = function(cap)
|
||||
@ -89,7 +89,7 @@ end
|
||||
|
||||
local function set_mapping(user_opts)
|
||||
log('setup mapping')
|
||||
local opts = { noremap = true, silent = true }
|
||||
local opts = {noremap = true, silent = true}
|
||||
user_opts = user_opts or {}
|
||||
|
||||
local user_key = _NgConfigValues.keymaps or {}
|
||||
@ -182,21 +182,18 @@ local function set_mapping(user_opts)
|
||||
end
|
||||
|
||||
local function autocmd(user_opts)
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
vim.api.nvim_exec([[
|
||||
aug NavigatorDocHlAu
|
||||
au!
|
||||
au CmdlineLeave : lua require('navigator.dochighlight').cmd_nohl()
|
||||
aug END
|
||||
]],
|
||||
false
|
||||
)
|
||||
]], false)
|
||||
end
|
||||
|
||||
local function set_event_handler(user_opts)
|
||||
user_opts = user_opts or {}
|
||||
local file_types =
|
||||
'c,cpp,h,go,python,vim,sh,javascript,html,css,lua,typescript,rust,javascriptreact,typescriptreact,json,yaml,kotlin,php,dart,nim,terraform,java'
|
||||
'c,cpp,h,go,python,vim,sh,javascript,html,css,lua,typescript,rust,javascriptreact,typescriptreact,json,yaml,kotlin,php,dart,nim,terraform,java'
|
||||
-- local format_files = "c,cpp,h,go,python,vim,javascript,typescript" --html,css,
|
||||
vim.api.nvim_command([[augroup nvim_lsp_autos]])
|
||||
vim.api.nvim_command([[autocmd!]])
|
||||
@ -259,7 +256,7 @@ function M.setup(user_opts)
|
||||
vim.lsp.handlers['textDocument/typeDefinition'] = require('navigator.definition').typeDefinition_handler
|
||||
vim.lsp.handlers['textDocument/implementation'] = require('navigator.implementation').implementation_handler
|
||||
|
||||
vim.lsp.handlers['textDocument/documentSymbol'] = require('navigator.symbols').document_symbol_handler
|
||||
-- vim.lsp.handlers['textDocument/documentSymbol'] = require('navigator.symbols').document_symbol_handler
|
||||
vim.lsp.handlers['workspace/symbol'] = require('navigator.symbols').workspace_symbol_handler
|
||||
vim.lsp.handlers['textDocument/publishDiagnostics'] = require('navigator.diagnostics').diagnostic_handler
|
||||
|
||||
@ -273,11 +270,11 @@ function M.setup(user_opts)
|
||||
end
|
||||
else
|
||||
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(require('navigator.signature').signature_handler, {
|
||||
border = { '╭', '─', '╮', '│', '╯', '─', '╰', '│' },
|
||||
border = {'╭', '─', '╮', '│', '╯', '─', '╰', '│'}
|
||||
})
|
||||
end
|
||||
|
||||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = single })
|
||||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {border = single})
|
||||
if cap.document_formatting then
|
||||
log('formatting enabled setup hdl')
|
||||
vim.lsp.handlers['textDocument/formatting'] = require('navigator.formatting').format_hdl
|
||||
@ -291,8 +288,8 @@ M.get_keymaps_help = function()
|
||||
border = 'none',
|
||||
prompt = true,
|
||||
enter = true,
|
||||
rect = { height = 20, width = 90 },
|
||||
data = key_maps_help,
|
||||
rect = {height = 20, width = 90},
|
||||
data = key_maps_help
|
||||
})
|
||||
|
||||
return win
|
||||
|
@ -1,6 +1,7 @@
|
||||
local gui = require('navigator.gui')
|
||||
local M = {}
|
||||
local log = require('navigator.util').log
|
||||
local trace = require('navigator.util').trace
|
||||
local mk_handler = require('navigator.util').mk_handler
|
||||
local lsphelper = require('navigator.lspwrapper')
|
||||
local locations_to_items = lsphelper.locations_to_items
|
||||
@ -8,45 +9,19 @@ local clone = require('guihua.util').clone
|
||||
local symbol_kind = require('navigator.lspclient.lspkind').symbol_kind
|
||||
local symbols_to_items = lsphelper.symbols_to_items
|
||||
|
||||
-- function M.document_symbols(opts)
|
||||
-- assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running")
|
||||
-- opts = opts or {}
|
||||
-- local params = vim.lsp.util.make_position_params()
|
||||
-- params.context = {includeDeclaration = true}
|
||||
-- params.query = ""
|
||||
-- local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 3000)
|
||||
-- local locations = {}
|
||||
-- log(results_lsp)
|
||||
-- for _, server_results in pairs(results_lsp) do
|
||||
-- if server_results.result then
|
||||
-- vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result) or {})
|
||||
-- end
|
||||
-- end
|
||||
-- local lines = {}
|
||||
--
|
||||
-- for _, loc in ipairs(locations) do
|
||||
-- table.insert(lines, string.format("%s:%s:%s", loc.filename, loc.lnum, loc.text))
|
||||
-- end
|
||||
-- if #lines > 0 then
|
||||
-- gui.new_list_view({data = lines})
|
||||
-- else
|
||||
-- vim.notify("symbols not found")
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function M.workspace_symbols(query)
|
||||
opts = opts or {}
|
||||
local lspopts = {
|
||||
loc = 'top_center',
|
||||
prompt = true,
|
||||
-- rawdata = true,
|
||||
api = ' ',
|
||||
api = ' '
|
||||
}
|
||||
|
||||
query = query or pcall(vim.fn.input, 'Query: ')
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.list_extend(lspopts, opts)
|
||||
local params = { query = query }
|
||||
local params = {query = query}
|
||||
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr)
|
||||
if client.resolved_capabilities.workspace_symbol then
|
||||
client.request('workspace/symbol', params, M.workspace_symbol_handler, _bufnr)
|
||||
@ -60,13 +35,13 @@ function M.document_symbols(opts)
|
||||
loc = 'top_center',
|
||||
prompt = true,
|
||||
-- rawdata = true,
|
||||
api = ' ',
|
||||
api = ' '
|
||||
}
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.list_extend(lspopts, opts)
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
params.context = { includeDeclaration = true }
|
||||
params.context = {includeDeclaration = true}
|
||||
params.query = opts.prompt or ''
|
||||
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr)
|
||||
if client.resolved_capabilities.document_symbol then
|
||||
@ -85,7 +60,6 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx)
|
||||
vim.notify('symbol not found for buf', ctx, vim.lsp.log_levels.WARN)
|
||||
return
|
||||
end
|
||||
-- log(result)
|
||||
local locations = {}
|
||||
local fname = vim.fn.expand('%:p:f')
|
||||
local uri = vim.uri_from_fname(fname)
|
||||
@ -122,17 +96,18 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx)
|
||||
child.uri = uri
|
||||
child.lnum = c.range.start.line + 1
|
||||
child.detail = c.detail or ''
|
||||
child.text = ' [' .. ckind .. '] ' .. child.name .. ' ' .. child.detail
|
||||
child.text = ' ' .. ckind .. '' .. child.name .. ' ' .. child.detail
|
||||
table.insert(locations, child)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
|
||||
gui.new_list_view({ items = locations, prompt = true, rawdata = true, ft = ft, api = ' ' })
|
||||
gui.new_list_view({items = locations, prompt = true, rawdata = true, ft = ft, api = ' '})
|
||||
end)
|
||||
|
||||
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
|
||||
trace(err, result, ctx, cfg)
|
||||
if err then
|
||||
vim.notify('failed to get workspace symbol', ctx, vim.lsp.log_levels.WARN)
|
||||
end
|
||||
@ -143,42 +118,10 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
|
||||
log(result[1])
|
||||
local items = symbols_to_items(result)
|
||||
log(items[1])
|
||||
-- local locations = {}
|
||||
-- for i = 1, #result do
|
||||
-- local item = result[i].location or {}
|
||||
-- item.kind = result[i].kind
|
||||
-- item.containerName = result[i].containerName or ""
|
||||
-- item.name = result[i].name
|
||||
-- item.text = result[i].name
|
||||
-- if #item.containerName > 0 then
|
||||
-- item.text = item.text:gsub(item.containerName, "", 1)
|
||||
-- end
|
||||
-- table.insert(locations, item)
|
||||
-- end
|
||||
-- local items = locations_to_items(locations)
|
||||
|
||||
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
|
||||
-- gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = " "})
|
||||
gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = " "})
|
||||
|
||||
-- if locations == nil or vim.tbl_isempty(locations) then
|
||||
-- vim.notify "References not found"
|
||||
-- return
|
||||
-- end
|
||||
-- local items = locations_to_items(locations)
|
||||
-- gui.new_list_view({items = items})
|
||||
-- local filename = vim.api.nvim_buf_get_name(bufnr)
|
||||
-- local items = vim.lsp.util.symbols_to_items(result, bufnr)
|
||||
-- local data = {}
|
||||
-- for i, item in pairs(action.items) do
|
||||
-- data[i] = item.text
|
||||
-- if filename ~= item.filename then
|
||||
-- local cwd = vim.loop.cwd() .. "/"
|
||||
-- local add = util.get_relative_path(cwd, item.filename)
|
||||
-- data[i] = data[i] .. " - " .. add
|
||||
-- end
|
||||
-- item.text = nil
|
||||
-- end
|
||||
-- opts.data = data
|
||||
end)
|
||||
|
||||
return M
|
||||
|
@ -6,8 +6,7 @@ local util = require('navigator.util')
|
||||
M.add_workspace_folder = function()
|
||||
util.log(vim.ui.input)
|
||||
local input = require('guihua.floating').input
|
||||
input({ prompt = 'Workspace To Add: ', default = vim.fn.expand('%:p:h') }, function(inputs)
|
||||
util.log(inputs)
|
||||
input({prompt = 'Workspace To Add: ', default = vim.fn.expand('%:p:h')}, function(inputs)
|
||||
vim.lsp.buf.add_workspace_folder(inputs)
|
||||
end)
|
||||
end
|
||||
@ -17,21 +16,19 @@ M.remove_workspace_folder = function()
|
||||
local folders = vim.lsp.buf.list_workspace_folders()
|
||||
|
||||
if #folders > 1 then
|
||||
select(folders, { prompt = 'select workspace to delete' }, function(workspace)
|
||||
util.log(workspace)
|
||||
select(folders, {prompt = 'select workspace to delete'}, function(workspace)
|
||||
vim.lsp.buf.remove_workspace_folder(workspace)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
M.workspace_symbol = function()
|
||||
local input = vim.ui.input
|
||||
|
||||
vim.ui.input = require('guihua.floating').input
|
||||
vim.lsp.buf.workspace_symbol()
|
||||
vim.defer_fn(function()
|
||||
vim.ui.input = input
|
||||
end, 1000)
|
||||
local input = require('guihua.floating').input
|
||||
input({prompt = 'Find symbol: ', default = ''}, function(inputs)
|
||||
util.log(inputs)
|
||||
print(inputs)
|
||||
vim.lsp.buf.workspace_symbol(inputs)
|
||||
end)
|
||||
end
|
||||
|
||||
M.list_workspace_folders = function()
|
||||
@ -41,7 +38,8 @@ M.list_workspace_folders = function()
|
||||
items = folders,
|
||||
border = 'single',
|
||||
rawdata = true,
|
||||
on_move = function(...) end,
|
||||
on_move = function(...)
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user