new tests for hierarchy, refactor reference_spec test

neovim_0.6^2
ray-x 2 years ago
parent 7d84a9f0c0
commit a225d18eaf

@ -253,7 +253,7 @@ call_hierarchy = function(method, opts)
return opts.handler(err, result, ctx, cfg) return opts.handler(err, result, ctx, cfg)
end end
-- log(opts, params) -- log(opts, params)
request( return request(
bufnr, bufnr,
'textDocument/prepareCallHierarchy', 'textDocument/prepareCallHierarchy',
params, params,
@ -299,6 +299,8 @@ end
M.incoming_calls_handler = incoming_calls_handler M.incoming_calls_handler = incoming_calls_handler
M.outgoing_calls_handler = outgoing_calls_handler M.outgoing_calls_handler = outgoing_calls_handler
-- for testing
M._call_hierarchy = call_hierarchy
function M.calltree(args) function M.calltree(args)
if args == '-o' then if args == '-o' then

@ -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)

@ -44,94 +44,59 @@ describe('should run lsp reference', function()
uri = 'file://' .. cur_dir .. '/tests/fixtures/interface_test.go', uri = 'file://' .. cur_dir .. '/tests/fixtures/interface_test.go',
}, },
} }
local status = require('plenary.reload').reload_module('navigator')
it('should show references', function() status = require('plenary.reload').reload_module('guihua')
local status = require('plenary.reload').reload_module('navigator') status = require('plenary.reload').reload_module('lspconfig')
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]])
vim.cmd([[packadd navigator.lua]]) local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p
vim.cmd([[packadd guihua.lua]]) local cmd = " silent exe 'e " .. path .. "'"
local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p vim.cmd(cmd)
local cmd = " silent exe 'e " .. path .. "'" vim.cmd([[cd %:p:h]])
vim.cmd(cmd) local bufn = vim.fn.bufnr('')
vim.cmd([[cd %:p:h]]) -- require'lspconfig'.gopls.setup {}
local bufn = vim.fn.bufnr('') require('navigator').setup({
-- require'lspconfig'.gopls.setup {} debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
require('navigator').setup({ icons = { code_action_icon = 'A ' },
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)
icons = { code_action_icon = 'A ' }, height = 0.3, -- max list window height, 0.3 by default
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) preview_height = 0.35, -- max height of preview windows
height = 0.3, -- max list window height, 0.3 by default border = 'none',
preview_height = 0.35, -- max height of preview windows })
border = 'none',
}) if vim.fn.has('nvim-0.7') then
_NgConfigValues.treesitter_analysis = true
if vim.fn.has('nvim-0.7') then else
_NgConfigValues.treesitter_analysis = true _NgConfigValues.treesitter_analysis = false
else end
_NgConfigValues.treesitter_analysis = false -- allow gopls start
end
-- allow gopls start for _ = 1, 20 do
for i = 1, 10 do vim.wait(400, function() end)
vim.wait(400, function() end) local found = false
local clients = vim.lsp.get_active_clients() for _, client in ipairs(vim.lsp.get_active_clients()) do
print('lsp clients: ', #clients) if client.name == 'gopls' then
if #clients > 0 then found = true
break break
end end
end end
if found then
break
end
end
it('should show references', function()
vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width
vim.bo.filetype = 'go' vim.bo.filetype = 'go'
-- vim.lsp.buf.references() vim.lsp.buf.references()
eq(1, 1) eq(1, 1)
end) end)
it('reference handler should return items', function() 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.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' 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 -- allow gopls start
vim.wait(200, function() end) vim.wait(200, function() end)
@ -156,50 +121,6 @@ describe('should run lsp reference', function()
-- eq(width, 60) -- eq(width, 60)
end) end)
it('reference handler should return items with thread', function() 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) vim.wait(200, function() end)
local win, items, width local win, items, width
@ -213,7 +134,6 @@ describe('should run lsp reference', function()
else else
win, items, width = require('navigator.reference').reference_handler(nil, 'textDocument/references', result, 1, 1) win, items, width = require('navigator.reference').reference_handler(nil, 'textDocument/references', result, 1, 1)
end end
print('win', vim.inspect(win)) print('win', vim.inspect(win))
print('items', vim.inspect(items)) print('items', vim.inspect(items))
-- eq(win.ctrl.data, "./interface.go") -- eq(win.ctrl.data, "./interface.go")

Loading…
Cancel
Save