diff --git a/README.md b/README.md index 24b706f..bd9feb5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Navigator +- Source code analysis and navigate tool - Easy code navigation, view diagnostic errors, see relationships of functions, variables diff --git a/lua/navigator/gui.lua b/lua/navigator/gui.lua index e433a8f..d4ac0fc 100644 --- a/lua/navigator/gui.lua +++ b/lua/navigator/gui.lua @@ -57,7 +57,6 @@ function M.new_list_view(opts) end function M.select(items, opts, on_choice) - return end return M diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index c30b20b..18ddba0 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -26,7 +26,7 @@ local key_maps = { { mode = 'i', key = '', func = 'signature_help()' }, { key = '', 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 = '', 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 = 'lua vim.' diagnostic = 'lua vim.' f = diagnostic .. value.func .. '' - -- elseif string.find(value.func, 'vim.') then - -- f = 'lua ' .. value.func .. '' + -- elseif string.find(value.func, 'vim.') then + -- f = 'lua ' .. value.func .. '' end local k = value.key local m = value.mode or 'n' diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index b0a1bce..9079c9d 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -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 diff --git a/lua/navigator/workspace.lua b/lua/navigator/workspace.lua index 2b6c0ce..ec85703 100644 --- a/lua/navigator/workspace.lua +++ b/lua/navigator/workspace.lua @@ -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