2021-08-24 07:14:43 +00:00
|
|
|
local helpers = {}
|
|
|
|
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')
|
2021-09-05 22:34:26 +00:00
|
|
|
local nvim_6 = true
|
|
|
|
if debug.getinfo(vim.lsp.handlers.signature_help).nparams > 4 then
|
|
|
|
nvim_6 = false
|
|
|
|
end
|
2021-08-24 07:14:43 +00:00
|
|
|
it("should show references", function()
|
|
|
|
|
|
|
|
local status = require("plenary.reload").reload_module("navigator")
|
|
|
|
local status = require("plenary.reload").reload_module("guihua")
|
2021-08-24 11:18:00 +00:00
|
|
|
local status = require("plenary.reload").reload_module("lspconfig")
|
2021-08-24 07:14:43 +00:00
|
|
|
|
|
|
|
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("")
|
2021-08-24 11:18:00 +00:00
|
|
|
-- require'lspconfig'.gopls.setup {}
|
2021-08-24 07:14:43 +00:00
|
|
|
require'navigator'.setup({
|
2021-09-05 22:34:26 +00:00
|
|
|
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
2021-08-24 07:14:43 +00:00
|
|
|
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'
|
|
|
|
})
|
2021-08-24 07:49:10 +00:00
|
|
|
|
2021-08-24 11:18:00 +00:00
|
|
|
-- allow gopls start
|
|
|
|
for i = 1, 10 do
|
|
|
|
vim.wait(400, function()
|
|
|
|
end)
|
|
|
|
local clients = vim.lsp.get_active_clients()
|
2021-09-05 22:34:26 +00:00
|
|
|
print("lsp clients: ", #clients)
|
2021-08-24 11:18:00 +00:00
|
|
|
if #clients > 0 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2021-08-24 07:49:10 +00:00
|
|
|
|
2021-08-24 07:14:43 +00:00
|
|
|
vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width
|
|
|
|
|
|
|
|
vim.bo.filetype = "go"
|
2021-09-09 02:59:58 +00:00
|
|
|
-- vim.lsp.buf.references()
|
2021-08-24 07:14:43 +00:00
|
|
|
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)
|
2021-09-09 02:59:58 +00:00
|
|
|
-- vim.cmd([[cd %:p:h]])
|
2021-08-24 07:14:43 +00:00
|
|
|
local bufn = vim.fn.bufnr("")
|
|
|
|
|
|
|
|
vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width
|
|
|
|
|
|
|
|
vim.bo.filetype = "go"
|
|
|
|
require'navigator'.setup({
|
2021-09-05 22:34:26 +00:00
|
|
|
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
2021-08-24 07:14:43 +00:00
|
|
|
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
|
2021-09-05 22:34:26 +00:00
|
|
|
debug_console_output = true,
|
2021-08-24 07:14:43 +00:00
|
|
|
border = 'none'
|
|
|
|
})
|
2021-08-24 07:37:45 +00:00
|
|
|
|
2021-09-05 22:34:26 +00:00
|
|
|
_NgConfigValues.debug_console_output = true
|
|
|
|
|
|
|
|
vim.bo.filetype = "go"
|
2021-08-24 11:18:00 +00:00
|
|
|
-- allow gopls start
|
|
|
|
for i = 1, 10 do
|
|
|
|
vim.wait(400, function()
|
|
|
|
end)
|
|
|
|
local clients = vim.lsp.get_active_clients()
|
2021-09-05 22:34:26 +00:00
|
|
|
print("clients ", #clients)
|
2021-08-24 11:18:00 +00:00
|
|
|
if #clients > 0 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-24 07:37:45 +00:00
|
|
|
-- allow gopls start
|
|
|
|
vim.wait(200, function()
|
|
|
|
end)
|
2021-08-24 07:14:43 +00:00
|
|
|
local result = {
|
|
|
|
{
|
|
|
|
range = {['end'] = {character = 6, line = 14}, start = {character = 1, line = 14}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 15, line = 24}, start = {character = 10, line = 24}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 17, line = 28}, start = {character = 12, line = 28}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 19, line = 51}, start = {character = 14, line = 51}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 19, line = 55}, start = {character = 14, line = 55}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 16, line = 59}, start = {character = 11, line = 59}},
|
|
|
|
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface.go"
|
|
|
|
}, {
|
|
|
|
range = {['end'] = {character = 16, line = 5}, start = {character = 11, line = 5}},
|
|
|
|
uri = "file://" .. cur_dir .. "/tests/fixtures/interface_test.go"
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 22:34:26 +00:00
|
|
|
|
|
|
|
local win, items, width
|
|
|
|
|
|
|
|
if nvim_6 then
|
2021-09-09 02:59:58 +00:00
|
|
|
win, items, width = require('navigator.reference').ref_view(nil, result, {
|
2021-09-05 22:34:26 +00:00
|
|
|
method = 'textDocument/references',
|
|
|
|
bufnr = 1,
|
|
|
|
client_id = 1
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
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))
|
2021-08-24 07:14:43 +00:00
|
|
|
eq(win.ctrl.data[1].display_filename, "./interface.go")
|
|
|
|
eq(win.ctrl.data[2].range.start.line, 14)
|
|
|
|
eq(items[1].display_filename, "./interface.go")
|
2021-09-05 22:34:26 +00:00
|
|
|
|
2021-08-24 11:18:00 +00:00
|
|
|
-- eq(width, 60)
|
2021-08-24 07:14:43 +00:00
|
|
|
end)
|
|
|
|
end)
|