From a225d18eafe208bed96f025adeae5855715f0c3e Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 3 Jul 2022 21:29:00 +1000 Subject: [PATCH] new tests for hierarchy, refactor reference_spec test --- lua/navigator/hierarchy.lua | 4 +- tests/call_hierarchy_spec.lua | 65 ++++++++++++++ tests/reference_spec.lua | 160 +++++++++------------------------- 3 files changed, 108 insertions(+), 121 deletions(-) create mode 100644 tests/call_hierarchy_spec.lua diff --git a/lua/navigator/hierarchy.lua b/lua/navigator/hierarchy.lua index cfa9d81..da55047 100644 --- a/lua/navigator/hierarchy.lua +++ b/lua/navigator/hierarchy.lua @@ -253,7 +253,7 @@ call_hierarchy = function(method, opts) return opts.handler(err, result, ctx, cfg) end -- log(opts, params) - request( + return request( bufnr, 'textDocument/prepareCallHierarchy', params, @@ -299,6 +299,8 @@ end M.incoming_calls_handler = incoming_calls_handler M.outgoing_calls_handler = outgoing_calls_handler +-- for testing +M._call_hierarchy = call_hierarchy function M.calltree(args) if args == '-o' then diff --git a/tests/call_hierarchy_spec.lua b/tests/call_hierarchy_spec.lua new file mode 100644 index 0000000..10c6212 --- /dev/null +++ b/tests/call_hierarchy_spec.lua @@ -0,0 +1,65 @@ +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 call hierarchy', 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 navigator.lua]]) + vim.cmd([[packadd guihua.lua]]) + local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p + local cmd = " silent exe 'e " .. path .. "'" + vim.cmd(cmd) + vim.cmd([[cd %:p:h]]) + local bufn = vim.fn.bufnr('') + vim.bo.filetype = 'go' + require('navigator').setup({ + debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log + width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) + height = 0.3, -- max list window height, 0.3 by default + preview_height = 0.35, -- max height of preview windows + border = 'none', + }) + + vim.bo.filetype = 'go' + -- allow gopls start + for _ = 1, 20 do + vim.wait(400, function() end) + local found = false + for _, client in ipairs(vim.lsp.get_active_clients()) do + if client.name == 'gopls' then + found = true + break + end + end + if found then + break + end + end + + it('should show panel', function() + vim.fn.setpos('.', { bufn, 24, 15, 0 }) + require('navigator.hierarchy').incoming_calls_panel() + + local panel = require('guihua.panel').debug() + eq(panel.name, 'Panel') + + vim.wait(400, function() end) + panel = require('guihua.panel').debug() + eq(panel.activePanel.sections[1].header[1], "──────────Call Hierarchy──────────") + eq(panel.activePanel.sections[1].nodes[1].name, "measure") + + end) + + it('should show hierarchy', function() + vim.fn.setpos('.', { bufn, 24, 15, 0 }) + require('navigator.hierarchy')._call_hierarchy() + vim.wait(400, function() end) + end) +end) diff --git a/tests/reference_spec.lua b/tests/reference_spec.lua index 08219b6..4cc8e4e 100644 --- a/tests/reference_spec.lua +++ b/tests/reference_spec.lua @@ -44,94 +44,59 @@ describe('should run lsp reference', function() uri = 'file://' .. cur_dir .. '/tests/fixtures/interface_test.go', }, } - - it('should show references', 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 navigator.lua]]) - vim.cmd([[packadd guihua.lua]]) - local path = cur_dir .. '/tests/fixtures/interface.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 - icons = { code_action_icon = 'A ' }, - width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) - height = 0.3, -- max list window height, 0.3 by default - preview_height = 0.35, -- max height of preview windows - border = 'none', - }) - - if vim.fn.has('nvim-0.7') then - _NgConfigValues.treesitter_analysis = true - else - _NgConfigValues.treesitter_analysis = false - end - -- 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 + local status = require('plenary.reload').reload_module('navigator') + status = require('plenary.reload').reload_module('guihua') + status = require('plenary.reload').reload_module('lspconfig') + + vim.cmd([[packadd navigator.lua]]) + vim.cmd([[packadd guihua.lua]]) + local path = cur_dir .. '/tests/fixtures/interface.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 + icons = { code_action_icon = 'A ' }, + width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) + height = 0.3, -- max list window height, 0.3 by default + preview_height = 0.35, -- max height of preview windows + border = 'none', + }) + + if vim.fn.has('nvim-0.7') then + _NgConfigValues.treesitter_analysis = true + else + _NgConfigValues.treesitter_analysis = false + end + -- allow gopls start + + for _ = 1, 20 do + vim.wait(400, function() end) + local found = false + for _, client in ipairs(vim.lsp.get_active_clients()) do + if client.name == 'gopls' then + found = true break end end - + if found then + break + end + end + it('should show references', function() vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width vim.bo.filetype = 'go' - -- vim.lsp.buf.references() + vim.lsp.buf.references() eq(1, 1) end) it('reference handler should return items', function() - local status = require('plenary.reload').reload_module('navigator') - local status = require('plenary.reload').reload_module('guihua') - vim.cmd([[packadd navigator.lua]]) - vim.cmd([[packadd guihua.lua]]) - local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p - print(path) - local cmd = " silent exe 'e " .. path .. "'" - vim.cmd(cmd) - -- vim.cmd([[cd %:p:h]]) - local bufn = vim.fn.bufnr('') - vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width - vim.bo.filetype = 'go' - require('navigator').setup({ - debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log - icons = { code_action_icon = 'A ' }, - width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) - height = 0.3, -- max list window height, 0.3 by default - preview_height = 0.35, -- max height of preview windows - debug_console_output = true, - border = 'none', - }) - - if vim.fn.has('nvim-0.7') then - _NgConfigValues.treesitter_analysis = true - else - _NgConfigValues.treesitter_analysis = false - end - - _NgConfigValues.debug_console_output = true vim.bo.filetype = 'go' - -- allow gopls start - for i = 1, 10 do - vim.wait(400, function() end) - local clients = vim.lsp.get_active_clients() - print('clients ', #clients) - if #clients > 0 then - break - end - end - -- allow gopls start vim.wait(200, function() end) @@ -156,50 +121,6 @@ describe('should run lsp reference', function() -- eq(width, 60) end) it('reference handler should return items with thread', function() - local status = require('plenary.reload').reload_module('navigator') - local status = require('plenary.reload').reload_module('guihua') - vim.cmd([[packadd navigator.lua]]) - vim.cmd([[packadd guihua.lua]]) - local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p - print(path) - local cmd = "silent exe 'e " .. path .. "'" - vim.cmd(cmd) - vim.cmd([[cd %:p:h]]) - local bufn = vim.fn.bufnr('') - - vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width - - vim.bo.filetype = 'go' - require('navigator').setup({ - debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log - icons = { code_action_icon = 'A ' }, - width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) - height = 0.3, -- max list window height, 0.3 by default - preview_height = 0.35, -- max height of preview windows - debug_console_output = true, - border = 'none', - }) - - - if vim.fn.has('nvim-0.7') then - _NgConfigValues.treesitter_analysis = true - else - _NgConfigValues.treesitter_analysis = false - end - _NgConfigValues.debug_console_output = true - - vim.bo.filetype = 'go' - -- allow gopls start - for i = 1, 10 do - vim.wait(400, function() end) - local clients = vim.lsp.get_active_clients() - print('clients ', #clients) - if #clients > 0 then - break - end - end - - -- allow gopls start vim.wait(200, function() end) local win, items, width @@ -213,7 +134,6 @@ describe('should run lsp reference', function() else win, items, width = require('navigator.reference').reference_handler(nil, 'textDocument/references', result, 1, 1) end - print('win', vim.inspect(win)) print('items', vim.inspect(items)) -- eq(win.ctrl.data, "./interface.go")