Nvim 0 6 lsp signature changes (#56)

* bugfix diagnostic error

* bugfix for code lens for neovim 0.6

* gh test workflow

* bugfix github workflow
pull/60/head
rayx 3 years ago committed by GitHub
parent f33a3e8e7d
commit 08dba1beb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,13 +9,13 @@ local path_sep = require"navigator.util".path_sep()
local path_cur = require"navigator.util".path_cur()
local M = {}
local function call_hierarchy_handler(direction, err, api, result, _, _, error_message)
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
log('call_hierarchy')
log('call_hierarchy', direction, err, result)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if err ~= nil then
log(api, "dir", direction, "result", result, "err", err)
log("hierarchy error", ctx, "dir", direction, "result", result, "err", err)
print("ERROR: " .. error_message)
return
end
@ -24,7 +24,7 @@ local function call_hierarchy_handler(direction, err, api, result, _, _, error_m
local items = {}
for _, call_hierarchy in pairs(result) do
local kind = ''
range = call_hierarchy.range
local range = call_hierarchy.range
local filename = assert(vim.uri_to_fname(call_hierarchy.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
@ -32,7 +32,7 @@ local function call_hierarchy_handler(direction, err, api, result, _, _, error_m
local bufnr = vim.uri_to_bufnr(call_hierarchy.uri)
local row = range.start.line
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
fn = ""
local fn = ""
if line ~= nil then
fn = line:sub(range.start.character, range['end'].character + 1)
end
@ -52,18 +52,17 @@ end
local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
local function incoming_calls_handler(bang, err, method, result, client_id, bufnr)
local function incoming_calls_handler(bang, err, result, ctx, cfg)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
local results = call_hierarchy_handler_from(err, method, result, client_id, bufnr,
"Incoming calls not found")
local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})
end
local function outgoing_calls_handler(bang, err, method, result, client_id, bufnr)
local results = call_hierarchy_handler_to(err, method, result, client_id, bufnr,
"Outgoing calls not found")
-- err, method, result, client_id, bufnr
local function outgoing_calls_handler(bang, err, result, ctx, cfg)
local results = call_hierarchy_handler_to(err, result, ctx, cfg, "Outgoing calls not found")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})

@ -5,8 +5,8 @@ local code_action = {}
local gui = require "navigator.gui"
local config = require("navigator").config_values()
local api = vim.api
function code_action.code_action_handler(err, _, actions, cid, bufnr, _, customSelectionHandler)
log(cid, bufnr, actions)
code_action.code_action_handler = util.mk_handler(function(err, actions, ctx, cfg)
log(actions, ctx)
if actions == nil or vim.tbl_isempty(actions) then
print("No code actions available")
return
@ -58,7 +58,7 @@ function code_action.code_action_handler(err, _, actions, cid, bufnr, _, customS
return pos
end
}
end
end)
-- https://github.com/glepnir/lspsaga.nvim/blob/main/lua/lspsaga/codeaction.lua
-- lspsaga has a clever design to inject code action indicator
@ -163,7 +163,7 @@ local special_buffers = {
-- return Action:action_callback()
-- end
local action_vritual_call_back = function(line, diagnostics)
local action_virtual_call_back = function(line, diagnostics)
return code_action:render_action_virtual_text(line, diagnostics)
end
@ -190,7 +190,7 @@ code_action.code_action_prompt = function()
local winid = get_current_winid()
code_action[winid] = code_action[winid] or {}
code_action[winid].lightbulb_line = code_action[winid].lightbulb_line or 0
code_action_req(action_vritual_call_back, diagnostics)
code_action_req(action_virtual_call_back, diagnostics)
end
return code_action

@ -4,6 +4,8 @@
local codelens = require('vim.lsp.codelens')
local log = require"navigator.util".log
local mk_handler = require"navigator.util".mk_handler
local nvim_0_6 = require"navigator.util".nvim_0_6
local trace = require"navigator.util".trace
local lsphelper = require "navigator.lspwrapper"
@ -42,16 +44,16 @@ local function _update_sign(line)
end
end
local function codelens_hdlr(err, _, result, client_id, bufnr)
local codelens_hdlr = mk_handler(function(err, result, ctx, cfg)
if err or result == nil then
log("lsp code lens", vim.inspect(err))
log("lsp code lens", vim.inspect(err), ctx, cfg)
return
end
trace("codelenes result", result)
for _, v in pairs(result) do
_update_sign(v.range.start.line)
end
end
end)
function M.setup()
vim.cmd('highlight! link LspCodeLens LspDiagnosticsHint')
@ -65,10 +67,17 @@ function M.setup()
"autocmd BufEnter,CursorHold,InsertLeave <buffer> lua require('navigator.codelens').refresh()")
vim.cmd('augroup end')
local on_codelens = vim.lsp.handlers["textDocument/codeLens"]
vim.lsp.handlers["textDocument/codeLens"] = function(err, _, result, client_id, bufnr)
on_codelens(err, _, result, client_id, bufnr)
codelens_hdlr(err, _, result, client_id, bufnr)
end
vim.lsp.handlers["textDocument/codeLens"] = mk_handler(
function(err, result, ctx, cfg)
log(err, result, ctx.client_id, ctx.bufnr, cfg)
if nvim_0_6() then
on_codelens(err, result, ctx, cfg)
codelens_hdlr(err, result, ctx, cfg)
else
on_codelens(err, ctx.method, result, ctx.client_id, ctx.bufnr)
codelens_hdlr(err, _, result, ctx.client_id or 0, ctx.bufnr or 0)
end
end)
end
M.lsp_clients = {}

@ -5,10 +5,10 @@ local gui = require "navigator.gui"
local log = util.log
local TextView = require("guihua.textview")
-- callback for lsp definition, implementation and declaration handler
local function definition_hdlr(err, _, locations, _, bufnr)
local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
-- log(locations)
if err ~= nil then
print(err)
print(err, ctx)
return
end
if type(locations) == "number" then
@ -29,7 +29,7 @@ local function definition_hdlr(err, _, locations, _, bufnr)
else
vim.lsp.util.jump_to_location(locations)
end
end
end)
local function get_symbol()
local currentWord = vim.fn.expand('<cword>')

@ -9,6 +9,7 @@ local trace = require"guihua.log".trace
local error = util.error
local path_sep = require"navigator.util".path_sep()
local mk_handler = require"navigator.util".mk_handler
local path_cur = require"navigator.util".path_cur()
diagnostic_list[vim.bo.filetype] = {}
@ -90,7 +91,7 @@ local function error_marker(result, client_id)
end
end
local diag_hdlr = function(err, method, result, client_id, bufnr, config)
local diag_hdlr = mk_handler(function(err, result, ctx, config)
trace(result)
if err ~= nil then
log(err, config)
@ -103,8 +104,16 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
end
-- vim.lsp.diagnostic.clear(vim.fn.bufnr(), client.id, nil, nil)
vim.lsp.diagnostic.on_publish_diagnostics(err, method, result, client_id, bufnr, config)
if util.nvim_0_6() then
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
else
vim.lsp.diagnostic.on_publish_diagnostics(err, _, result, ctx.client_id, _, config)
end
local uri = result.uri
if err then
log("diag", err, result)
return
end
-- log("diag: ", result, client_id)
if result and result.diagnostics then
@ -143,13 +152,13 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
-- local old_items = vim.fn.getqflist()
diagnostic_list[ft][uri] = item_list
error_marker(result, client_id)
error_marker(result, ctx.client_id)
else
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
_NG_VT_NS = nil
end
end
end)
local M = {}
local diagnostic_cfg = {
@ -167,9 +176,16 @@ local diagnostic_cfg = {
if _NgConfigValues.lsp.diagnostic_virtual_text == false then
diagnostic_cfg.virtual_text = false
end
-- vim.lsp.handlers["textDocument/publishDiagnostics"] =
-- vim.lsp.handlers["textDocument/publishDiagnostics"]
M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg)
M.hide_diagnostic = function()
if _NG_VT_NS then
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
_NG_VT_NS = nil
end
end
M.show_diagnostic = function()
vim.lsp.diagnostic.get_all()

@ -1,6 +1,7 @@
local util = require "navigator.util"
local log = util.log
local trace = util.trace
local mk_handler = util.mk_handler
local api = vim.api
local references = {}
_NG_hi_list = {}
@ -137,20 +138,21 @@ local function before(r1, r2)
return false
end
local function handle_document_highlight(_, _, result, _, bufnr, _)
if not bufnr then
local handle_document_highlight = mk_handler(function(_, result, ctx)
if not ctx.bufnr then
log("ducment highlight error", result, ctx)
return
end
if type(result) ~= "table" then
vim.lsp.util.buf_clear_references(bufnr)
vim.lsp.util.buf_clear_references(ctx.bufnr)
return
end
table.sort(result, function(a, b)
return before(a.range, b.range)
end)
references[bufnr] = result
end
references[ctx.bufnr] = result
end)
-- modify from vim-illuminate
local function goto_adjent_reference(opt)
trace(opt)
@ -212,8 +214,9 @@ local function documentHighlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]], false)
vim.lsp.handlers["textDocument/documentHighlight"] =
function(err, _, result, _, bufnr)
vim.lsp.handlers["textDocument/documentHighlight"] = mk_handler(
function(err, result, ctx)
local bufnr = ctx.bufnr
if err then
print(err)
return
@ -235,7 +238,7 @@ local function documentHighlight()
end)
references[bufnr] = result
add_locs(bufnr, result)
end
end)
end
return {

@ -1,4 +1,5 @@
local log = require"navigator.util".log
local mk_handler = require"navigator.util".mk_handler
local lsp = vim.lsp
local api = vim.api
@ -88,18 +89,18 @@ function M.debug_folds()
end
end
function M.fold_handler(err, method, result, client, bufnr)
M.fold_handler = mk_handler(function(err, result, ctx, config)
-- params: err, method, result, client_id, bufnr
-- XXX: handle err?
if err or result == nil or #result == 0 then
print(err, method, client)
print(err, ctx.method, ctx.client_id)
return
end
M.debug_folds()
local current_bufnr = api.nvim_get_current_buf()
-- Discard the folding result if buffer focus has changed since the request was
-- done.
if current_bufnr == bufnr then
if current_bufnr == ctx.bufnr then
for _, fold in ipairs(result) do
fold['startLine'] = M.adjust_foldstart(fold['startLine'])
fold['endLine'] = M.adjust_foldend(fold['endLine'])
@ -112,7 +113,7 @@ function M.fold_handler(err, method, result, client, bufnr)
api.nvim_win_set_option(current_window, 'foldmethod', 'expr')
api.nvim_win_set_option(current_window, 'foldexpr', 'foldlsp#foldexpr()')
end
end
end)
function M.adjust_foldstart(line_no)
return line_no + 1

@ -1,16 +1,17 @@
-- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua
local mk_handler = require"navigator.util".mk_handler
return {
format_hdl = function(err, _, result, _, bufnr) -- FIXME: bufnr is nil
format_hdl = mk_handler(function(err, result, ctx, cfg) -- FIXME: bufnr is nil
if err ~= nil or result == nil then
return
end
-- If the buffer hasn't been modified before the formatting has finished,
-- update the buffer
if not vim.api.nvim_buf_get_option(bufnr, 'modified') then
if not vim.api.nvim_buf_get_option(ctx.bufnr, 'modified') then
local view = vim.fn.winsaveview()
vim.lsp.util.apply_text_edits(result, bufnr)
vim.lsp.util.apply_text_edits(result, ctx.bufnr)
vim.fn.winrestview(view)
-- FIXME: commented out as a workaround
-- if bufnr == vim.api.nvim_get_current_buf() then
@ -20,5 +21,5 @@ return {
-- vim.api.nvim_command('silent doautocmd <nomodeline> User FormatterPost')
-- end
end
end
end)
}

@ -9,11 +9,11 @@ local path_cur = require"navigator.util".path_cur()
local cwd = vim.fn.getcwd(0)
local M = {}
local function call_hierarchy_handler(direction, err, _, result, _, _, error_message)
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
log('call_hierarchy')
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if err ~= nil then
log("dir", direction, "result", result, "err", err)
log("dir", direction, "result", result, "err", err, ctx)
print("ERROR: " .. error_message)
return
end
@ -46,20 +46,18 @@ end
local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
local function incoming_calls_handler(bang, err, method, result, client_id, bufnr)
local function incoming_calls_handler(bang, err, result, ctx, cfg)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
local results = call_hierarchy_handler_from(err, method, result, client_id, bufnr,
"Incoming calls not found")
local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})
end
local function outgoing_calls_handler(bang, err, method, result, client_id, bufnr)
local results = call_hierarchy_handler_to(err, method, result, client_id, bufnr,
"Outgoing calls not found")
local function outgoing_calls_handler(bang, err, result, ctx, cfg)
local results = call_hierarchy_handler_to(err, result, ctx, cfg, "Outgoing calls not found")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = ''})
-- fzf_locations(bang, "", "Outgoing Calls", results, false)
end

@ -1,23 +1,24 @@
-- TODO: change background and use TextView?
local lsp = require("vim.lsp")
return { hover_handler = function(_, method, result)
vim.lsp.util.focusable_float(
method,
function()
if not (result and result.contents) then
return
end
local markdown_lines = lsp.util.convert_input_to_markdown_lines(result.contents)
markdown_lines = lsp.util.trim_empty_lines(markdown_lines)
if vim.tbl_isempty(markdown_lines) then
return
end
local bnr, contents_winid, _, border_winid = vim.lsp.util.fancy_floating_markdown(markdown_lines)
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, contents_winid)
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, border_winid)
return bnr, contents_winid
local mk_handler = require"navigator.util".mk_handler
return {
hover_handler = mk_handler(function(_, result, ctx, cfg)
vim.lsp.util.focusable_float(ctx.method or "Hover", function()
if not (result and result.contents) then
return
end
)
end
local markdown_lines = lsp.util.convert_input_to_markdown_lines(result.contents)
markdown_lines = lsp.util.trim_empty_lines(markdown_lines)
if vim.tbl_isempty(markdown_lines) then
return
end
local bnr, contents_winid, _, border_winid =
vim.lsp.util.fancy_floating_markdown(markdown_lines)
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, contents_winid)
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, border_winid)
return bnr, contents_winid
end)
end)
}

@ -1,4 +1,5 @@
local util = require "navigator.util"
local mk_handler = util.mk_handler
local lsphelper = require "navigator.lspwrapper"
local gui = require "navigator.gui"
local M = {}
@ -7,18 +8,17 @@ local partial = util.partial
local locations_to_items = lsphelper.locations_to_items
local log = util.log
-- dataformat should be same as reference
local function location_handler(err, _, locations, _, bufnr, error_message)
local function location_handler(err, locations, ctx, cfg, msg)
if err ~= nil then
print("ERROR: " .. tostring(err) .. error_message)
print("ERROR: " .. tostring(err) .. msg)
return
end
return locations_to_items(locations)
end
local function implementation_handler(bang, err, method, result, client_id, bufnr)
local results =
location_handler(err, method, result, client_id, bufnr, "Implementation not found")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
local function implementation_handler(bang, err, result, ctx, cfg)
local results = location_handler(err, result, ctx, "Implementation not found")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = 'Implementation'})
end
@ -30,7 +30,8 @@ function M.implementation(bang, opts)
local params = vim.lsp.util.make_position_params()
log("impel params", params)
util.call_sync("textDocument/implementation", params, opts, partial(implementation_handler, bang))
lsphelper.call_sync("textDocument/implementation", params, opts,
partial(implementation_handler, bang))
end
M.implementation_call = partial(M.implementation, 0)

@ -1,6 +1,8 @@
local M = {}
local util = require "navigator.util"
local nvim_0_6 = util.nvim_0_6()
local gutil = require "guihua.util"
local lsp = require "vim.lsp"
local api = vim.api
@ -144,7 +146,11 @@ function M.call_sync(method, params, opts, handler)
local results_lsp, err = lsp.buf_request_sync(0, method, params,
opts.timeout or vim.g.navtator_timeout or 1000)
handler(err, method, extract_result(results_lsp), nil, nil)
if nvim_0_6() then
handler(err, extract_result(results_lsp), {method = method}, nil)
else
handler(err, method, extract_result(results_lsp), nil, nil)
end
end
function M.call_async(method, params, handler)

@ -1,4 +1,5 @@
local util = require "navigator.util"
local mk_handler = util.mk_handler
local log = util.log
local lsphelper = require "navigator.lspwrapper"
local gui = require "navigator.gui"
@ -9,24 +10,23 @@ local trace = require"navigator.util".trace
-- local lsphelper = require "navigator.lspwrapper"
local locations_to_items = lsphelper.locations_to_items
local function ref_hdlr(err, api, locations, num, bufnr)
local ref_hdlr = mk_handler(function(err, locations, ctx, cfg)
local opts = {}
trace("arg1", err, api, locations, num, bufnr)
trace("arg1", err, ctx, locations)
log(api)
trace(locations)
-- log("num", num)
-- log("bfnr", bufnr)
if err ~= nil then
print('lsp ref callback error', err, api, vim.inspect(locations))
log('ref callback error, lsp may not ready', err, api, vim.inspect(locations))
print('lsp ref callback error', err, ctx, vim.inspect(locations))
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
return
end
if type(locations) ~= 'table' then
log(api)
log(locations)
log("num", num)
log("bfnr", bufnr)
error(locations)
log("ctx", ctx)
print("incorrect setup", location)
return
end
if locations == nil or vim.tbl_isempty(locations) then
print "References not found"
@ -34,7 +34,7 @@ local function ref_hdlr(err, api, locations, num, bufnr)
end
local items, width = locations_to_items(locations)
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
local wwidth = vim.api.nvim_get_option("columns")
local mwidth = _NgConfigValues.width
@ -49,7 +49,7 @@ local function ref_hdlr(err, api, locations, num, bufnr)
enable_preview_edit = true
})
return listview, items, width
end
end)
local async_reference_request = function()
local ref_params = vim.lsp.util.make_position_params()

@ -1,11 +1,13 @@
local gui = require "navigator.gui"
local util = require "navigator.util"
local mk_handler = util.mk_handler
local log = util.log
local partial = util.partial
local lsphelper = require "navigator.lspwrapper"
local cwd = vim.fn.getcwd(0)
local M = {}
--- navigator signature
local match_parameter = function(result)
local signatures = result.signatures
if #signatures < 1 then
@ -46,7 +48,7 @@ local match_parameter = function(result)
end
end
local function signature_handler(err, method, result, _, bufnr, config)
local signature_handler = mk_handler(function(err, result, ctx, config)
if config == nil then
log("config nil")
end
@ -61,8 +63,7 @@ local function signature_handler(err, method, result, _, bufnr, config)
end
local syntax = vim.lsp.util.try_trim_markdown_code_blocks(lines)
config.focus_id = method .. "lsp_signature"
config.focus_id = ctx.bufnr .. "lsp_signature"
vim.lsp.util.open_floating_preview(lines, syntax, config)
end
end)
return {signature_handler = signature_handler}

@ -1,6 +1,7 @@
local gui = require "navigator.gui"
local M = {}
local log = require"navigator.util".log
local mk_handler = require"navigator.util".mk_handler
local lsphelper = require "navigator.lspwrapper"
local locations_to_items = lsphelper.locations_to_items
local clone = require"guihua.util".clone
@ -74,13 +75,13 @@ function M.workspace_symbols(opts)
end
end
function M.document_symbol_handler(err, _, result, _, bufnr)
M.document_symbol_handler = mk_handler(function(err, result, ctx)
if err then
print(bufnr, "failed to get document symbol")
print("failed to get document symbol", ctx)
end
if not result or vim.tbl_isempty(result) then
print(bufnr, "symbol not found for buf")
print("symbol not found for buf", ctx)
return
end
-- log(result)
@ -150,14 +151,14 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
-- item.text = nil
-- end
-- opts.data = data
end
end)
function M.workspace_symbol_handler(err, _, result, _, bufnr)
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
if err then
print(bufnr, "failed to get workspace symbol")
print("failed to get workspace symbol", ctx)
end
if not result or vim.tbl_isempty(result) then
print(bufnr, "symbol not found for buf")
print("symbol not found for buf", ctx)
return
end
log(result[1])
@ -177,7 +178,7 @@ function M.workspace_symbol_handler(err, _, result, _, bufnr)
-- end
-- local items = locations_to_items(locations)
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = ""})
-- if locations == nil or vim.tbl_isempty(locations) then
@ -199,6 +200,6 @@ function M.workspace_symbol_handler(err, _, result, _, bufnr)
-- item.text = nil
-- end
-- opts.data = data
end
end)
return M

@ -3,6 +3,9 @@
-- Some of function copied from https://github.com/RishabhRD/nvim-lsputils
local M = {log_path = vim.lsp.get_log_path()}
-- local is_windows = uv.os_uname().version:match("Windows")
local nvim_0_6
M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find("Windows")
if is_win then
@ -144,8 +147,12 @@ elseif _NgConfigValues.debug == "trace" then
level = "trace"
end
local default_config = {plugin = "navigator", use_console = false, use_file = true, level = level}
M._log = require("guihua.log").new({level = default_config.level}, true)
local default_config = {use_console = false, use_file = true, level = level}
if _NgConfigValues.debug_console_output then
default_config.use_console = true
default_config.use_file = false
end
M._log = require("guihua.log").new(default_config, true)
-- add log to you lsp.log
M.log = M._log.info
@ -290,12 +297,6 @@ function M.exists(var)
end
end
function M.partial(func, arg)
return (function(...)
return func(arg, ...)
end)
end
local exclude_ft = {"scrollbar", "help", "NvimTree"}
function M.exclude(fname)
for i = 1, #exclude_ft do
@ -349,4 +350,40 @@ function M.get_current_winid()
return api.nvim_get_current_win()
end
function M.nvim_0_6()
if nvim_0_6 ~= nil then
return nvim_0_6
end
if debug.getinfo(vim.lsp.handlers.signature_help).nparams == 4 then
nvim_0_6 = true
else
nvim_0_6 = false
end
return nvim_0_6
end
function M.mk_handler(fn)
return function(...)
local config_or_client_id = select(4, ...)
local is_new = M.nvim_0_6()
if is_new then
return fn(...)
else
local err = select(1, ...)
local method = select(2, ...)
local result = select(3, ...)
local client_id = select(4, ...)
local bufnr = select(5, ...)
local config = select(6, ...)
return fn(err, result, {method = method, client_id = client_id, bufnr = bufnr}, config)
end
end
end
function M.partial(func, arg)
return (M.mk_handler(function(...)
return func(arg, ...)
end))
end
return M

@ -9,8 +9,10 @@ local cur_dir = vim.fn.expand("%:p:h")
-- local ulog = require('go.utils').log
describe("should run lsp reference", function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
-- status = require("plenary.reload").reload_module("go.nvim")
local nvim_6 = true
if debug.getinfo(vim.lsp.handlers.signature_help).nparams > 4 then
nvim_6 = false
end
it("should show references", function()
local status = require("plenary.reload").reload_module("navigator")
@ -26,7 +28,7 @@ describe("should run lsp reference", function()
local bufn = vim.fn.bufnr("")
-- require'lspconfig'.gopls.setup {}
require'navigator'.setup({
debug = false, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
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
@ -39,7 +41,7 @@ describe("should run lsp reference", function()
vim.wait(400, function()
end)
local clients = vim.lsp.get_active_clients()
print(vim.inspect(clients))
print("lsp clients: ", #clients)
if #clients > 0 then
break
end
@ -68,20 +70,24 @@ describe("should run lsp reference", function()
vim.bo.filetype = "go"
require'navigator'.setup({
debug = false, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
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'
})
_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(vim.inspect(clients))
print("clients ", #clients)
if #clients > 0 then
break
end
@ -115,12 +121,29 @@ describe("should run lsp reference", function()
uri = "file://" .. cur_dir .. "/tests/fixtures/interface_test.go"
}
}
local win, items, width = require('navigator.reference').reference_handler(nil,
"textDocument/references",
result, 1, 1)
local win, items, width
if nvim_6 then
win, items, width = require('navigator.reference').reference_handler(nil, result, {
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))
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")
-- eq(width, 60)
end)
end)

Loading…
Cancel
Save