workspace symbole search improvements. allows to show interactive search results in the symbol list.

neovim_0.6^2
ray-x 2 years ago
parent 01801ba8fa
commit 6e937e9019

@ -1,4 +1,5 @@
# Navigator
- Source code analysis and navigate tool
- Easy code navigation, view diagnostic errors, see relationships of functions, variables

@ -57,7 +57,6 @@ function M.new_list_view(opts)
end
function M.select(items, opts, on_choice)
return
end
return M

@ -26,7 +26,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 = "require('navigator.workspace').workspace_symbol()" },
{ key = 'gW', func = "require('navigator.workspace').workspace_symbol_live()" },
{ key = '<c-]>', func = "require('navigator.definition').definition()" },
{ key = 'gd', func = "require('navigator.definition').definition()" },
{ key = 'gD', func = "declaration({ border = 'rounded', max_width = 80 })" },
@ -154,8 +154,8 @@ local function set_mapping(user_opts)
local diagnostic = '<Cmd>lua vim.'
diagnostic = '<Cmd>lua vim.'
f = diagnostic .. value.func .. '<CR>'
-- elseif string.find(value.func, 'vim.') then
-- f = '<Cmd>lua ' .. value.func .. '<string.find(value.func, 'vim.')CR>'
-- elseif string.find(value.func, 'vim.') then
-- f = '<Cmd>lua ' .. value.func .. '<string.find(value.func, 'vim.')CR>'
end
local k = value.key
local m = value.mode or 'n'

@ -74,6 +74,7 @@ end
function M.symbols_to_items(result)
local locations = {}
result = result or {}
-- log(result)
for i = 1, #result do
local item = result[i].location

@ -1,12 +1,15 @@
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/rename.lua
local M = {}
local util = require('navigator.util')
local gutil = require('guihua.util')
local lsphelper = require('navigator.lspwrapper')
local symbols_to_items = lsphelper.symbols_to_items
-- local rename_prompt = 'Rename -> '
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)
input({ prompt = 'Workspace To Add: ', default = vim.fn.expand('%:p:h') }, function(inputs)
vim.lsp.buf.add_workspace_folder(inputs)
end)
end
@ -16,7 +19,7 @@ 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)
select(folders, { prompt = 'select workspace to delete' }, function(workspace)
vim.lsp.buf.remove_workspace_folder(workspace)
end)
end
@ -24,13 +27,55 @@ end
M.workspace_symbol = function()
local input = require('guihua.floating').input
input({prompt = 'Find symbol: ', default = ''}, function(inputs)
input({ prompt = 'Search symbol: ', default = '' }, function(inputs)
util.log(inputs)
print(inputs)
vim.lsp.buf.workspace_symbol(inputs)
end)
end
function M.workspace_symbol_live()
local height = 15
local bufnr = vim.api.nvim_get_current_buf()
local data = { { text = 'input the symbol name to start fuzzy search' } }
for _ = 1, height do
table.insert(data, { text = '' })
end
local ListView = require('guihua.listview')
local opt = {
api = '',
bg = 'GHListDark',
data = data,
items = data,
enter = true,
ft = 'go',
loc = 'top_center',
transparency = 50,
prompt = true,
on_confirm = function(item)
vim.defer_fn(function()
if item and item.name then
require('navigator.symbols').workspace_symbols(item.name)
end
end, 10)
end,
on_input_filter = function(text)
local params = { query = text or '#' }
local result = vim.lsp.buf_request_sync(bufnr, 'workspace/symbol', params)
util.log(vim.inspect(result[1].result))
result = result[1].result -- this is different from handler,
-- result[1].result is same as result in handler
local items = symbols_to_items(result)
items = gutil.dedup(items, 'name', 'kind')
return items
end,
rect = { height = height, pos_x = 0, pos_y = 0, width = 120 },
}
local win = ListView:new(opt)
win:on_draw({})
-- require('guihua.gui').new_list_view(opt)
end
M.list_workspace_folders = function()
local folders = vim.lsp.buf.list_workspace_folders()
if #folders > 0 then
@ -38,8 +83,7 @@ M.list_workspace_folders = function()
items = folders,
border = 'single',
rawdata = true,
on_move = function()
end
on_move = function() end,
})
end
end

Loading…
Cancel
Save