diff --git a/lua/navigator.lua b/lua/navigator.lua index 52f6db6..01e304a 100755 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -100,6 +100,15 @@ _NgConfigValues = { -- Values value_changed = 'πŸ“', value_definition = '🐢🍑', -- it is easier to see than πŸ¦• + side_panel = { + section_separator = 'ο››', + line_num_left = 'ξ‚²', + line_num_right = 'ξ‚°', + inner_node = 'β”œβ—‹', + outer_node = 'β•°β—‹', + bracket_left = 'βŸͺ', + bracket_right = '⟫', + }, -- Treesitter match_kinds = { var = 'ξž› ', -- "πŸ‘Ή", -- Vampaire @@ -110,6 +119,8 @@ _NgConfigValues = { namespace = 'πŸš€', type = 'ο ‹ ', field = '🏈', + module = 'πŸ“¦', + flag = '🎏', }, treesitter_defult = '🌲', doc_symbols = 'ξœ–', diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 68fed45..678c3d4 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -470,7 +470,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) local clients = vim.lsp.get_active_clients() or {} for _, client in ipairs(clients) do if client ~= nil then - loaded[client.name] = true + loaded[client.name] = client.id end end -- check should load lsp @@ -502,7 +502,6 @@ local function lsp_startup(ft, retry, user_lsp_opts) end local default_config = {} - log(lspclient) if lspconfig[lspclient] == nil then vim.notify( 'lspclient' .. vim.inspect(lspclient) .. 'no longer support by lspconfig, please submit an issue', @@ -532,6 +531,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) local disable_fmt = false + log(lspclient) -- if user provides override values cfg.capabilities = capabilities log(lspclient, config.lsp.disable_format_cap) @@ -785,10 +785,10 @@ local function setup(user_opts, cnt) user_opts = vim.tbl_extend('keep', user_opts, config) -- incase setup was triggered from autocmd - log(user_opts) + log('running lsp setup', ft, bufnr) local retry = true - log('loading for ft ', ft, uri, user_opts) + log('loading for ft ', ft, uri) highlight.diagnositc_config_sign() highlight.add_highlight() local lsp_opts = user_opts.lsp or {} diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index f833865..434ce7d 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -119,12 +119,12 @@ local function set_cmds(_) end end -local function set_mapping(user_opts) +local function set_mapping(lsp_info) local opts = { noremap = true, silent = true } - user_opts = user_opts or {} - log('setup mapping', user_opts) + lsp_info = lsp_info or {} + log('setup mapping', lsp_info.client.name, lsp_info.client.cmd) local user_key = _NgConfigValues.keymaps or {} - local bufnr = user_opts.bufnr or 0 + local bufnr = lsp_info.bufnr or 0 local function del_keymap(...) vim.api.nvim_buf_del_keymap(bufnr, ...) @@ -136,7 +136,7 @@ local function set_mapping(user_opts) -- local function buf_set_option(...) -- vim.api.nvim_buf_set_option(bufnr, ...) -- end - local doc_fmt, range_fmt, ccls = check_cap(user_opts) + local doc_fmt, range_fmt, ccls = check_cap(lsp_info) if ccls then vim.list_extend(key_maps, ccls_mappings) @@ -200,8 +200,8 @@ local function set_mapping(user_opts) del_keymap('n', fmtkey) end - if user_opts.cap and user_opts.cap.document_range_formatting then - log('formatting enabled', user_opts.cap) + if lsp_info.cap and lsp_info.cap.document_range_formatting then + log('formatting enabled', lsp_info.cap) end if not range_fmt and rfmtkey then diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index b8b2e4d..bc33f62 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -311,6 +311,7 @@ local function get_all_nodes(bufnr, filter, summary) ['arrow_function'] = true, ['type'] = true, ['class'] = true, + ['var'] = true, ['struct'] = true, ['method'] = true, } @@ -436,6 +437,7 @@ local function get_all_nodes(bufnr, filter, summary) if should_unload then vim.api.nvim_buf_delete(bufnr, { unload = true }) end + lprint(all_nodes) return all_nodes, length end @@ -496,7 +498,7 @@ function M.buf_ts() local all_nodes, width = get_all_nodes(bufnr) local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') - gui.new_list_view({ + local listview = gui.new_list_view({ items = all_nodes, prompt = true, ft = ft, @@ -506,6 +508,7 @@ function M.buf_ts() width = width + 10, api = _NgConfigValues.icons.treesitter_defult, }) + return listview, all_nodes, width end M.get_all_nodes = get_all_nodes diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 7de3fe8..e456621 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -443,7 +443,7 @@ function M.encoding(client) end local oe = client.offset_encoding if oe == nil then - return 'utf-8' + return 'utf-16' end if type(oe) == 'table' then return oe[1] diff --git a/tests/treesitter_spec.lua b/tests/treesitter_spec.lua new file mode 100644 index 0000000..f9ac0d7 --- /dev/null +++ b/tests/treesitter_spec.lua @@ -0,0 +1,211 @@ +local golden_result = { + { + col = 9, + display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + full_text = 'package main', + kind = 'πŸš€', + lnum = 1, + node_scope = { + ['end'] = { + character = 0, + line = 12, + }, + start = { + character = 0, + line = 0, + }, + }, + node_text = 'main', + range = { + ['end'] = { + character = 12, + line = 0, + }, + start = { + character = 8, + line = 0, + }, + }, + text = ' πŸš€ main \t package main', + type = 'namespace', + uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + }, + { + col = 6, + display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + full_text = 'func interfaceTest()', + kind = 'ο‚š ', + lnum = 5, + node_scope = { + ['end'] = { + character = 1, + line = 11, + }, + start = { + character = 0, + line = 4, + }, + }, + node_text = 'interfaceTest', + range = { + ['end'] = { + character = 18, + line = 4, + }, + start = { + character = 5, + line = 4, + }, + }, + text = ' ο‚š interfaceTest\t func interfaceTest()', + type = 'function', + uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + }, + { + col = 2, + display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + full_text = 'r := rect{width: 3, height: 4}', + kind = 'ξž› ', + lnum = 6, + node_scope = { + ['end'] = { + character = 1, + line = 11, + }, + start = { + character = 21, + line = 4, + }, + }, + node_text = 'r', + range = { + ['end'] = { + character = 2, + line = 5, + }, + start = { + character = 1, + line = 5, + }, + }, + text = ' ξž›  r \t r := rect{width: 3, height: 4}', + type = 'var', + uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + }, + { + col = 2, + display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + full_text = 'c := circle{radius: 5}', + kind = 'ξž› ', + lnum = 7, + node_scope = { + ['end'] = { + character = 1, + line = 11, + }, + start = { + character = 21, + line = 4, + }, + }, + node_text = 'c', + range = { + ['end'] = { + character = 2, + line = 6, + }, + start = { + character = 1, + line = 6, + }, + }, + text = ' ξž›  c \t c := circle{radius: 5}', + type = 'var', + uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + }, + { + col = 2, + display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + full_text = 'd := circle{radius: 10}', + kind = 'ξž› ', + lnum = 10, + node_scope = { + ['end'] = { + character = 1, + line = 11, + }, + start = { + character = 21, + line = 4, + }, + }, + node_text = 'd', + range = { + ['end'] = { + character = 2, + line = 9, + }, + start = { + character = 1, + line = 9, + }, + }, + text = ' ξž›  d \t d := circle{radius: 10}', + type = 'var', + uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go', + }, +} + +print(golden_result[1].node_text) + +local busted = require('plenary/busted') + +local eq = assert.are.same +local cur_dir = vim.fn.expand('%:p:h') +-- local status = require("plenary.reload").reload_module("go.nvim") +-- status = require("plenary.reload").reload_module("nvim-treesitter") + +-- local ulog = require('go.utils').log +describe('should run lsp reference', function() + -- vim.fn.readfile('minimal.vim') + it('should show ts nodes', function() + local status = require('plenary.reload').reload_module('navigator') + local status = require('plenary.reload').reload_module('guihua') + local status = require('plenary.reload').reload_module('lspconfig') + + vim.cmd([[packadd nvim-lspconfig]]) + vim.cmd([[packadd navigator.lua]]) + vim.cmd([[packadd guihua.lua]]) + local path = cur_dir .. '/tests/fixtures/interface_test.go' -- %:p:h ? %:p + local cmd = " silent exe 'e " .. path .. "'" + vim.cmd(cmd) + vim.cmd([[cd %:p:h]]) + local bufn = vim.fn.bufnr('') + -- require'lspconfig'.gopls.setup {} + require('navigator').setup({ + debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log + }) + + -- allow gopls start + for i = 1, 10 do + vim.wait(400, function() end) + local clients = vim.lsp.get_active_clients() + print('lsp clients: ', #clients) + if #clients > 0 then + break + end + end + + vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width + + vim.bo.filetype = 'go' + local view, items, w = require('navigator.treesitter').buf_ts() + eq(items[1].node_text, golden_result[1].node_text) + eq(items[2].node_text, golden_result[2].node_text) + end) +end)