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

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

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

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

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

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

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

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

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

@ -1,23 +1,24 @@
-- TODO: change background and use TextView? -- TODO: change background and use TextView?
local lsp = require("vim.lsp") 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) local mk_handler = require"navigator.util".mk_handler
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, contents_winid) return {
lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, border_winid) hover_handler = mk_handler(function(_, result, ctx, cfg)
return bnr, contents_winid 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)
end 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 util = require "navigator.util"
local mk_handler = util.mk_handler
local lsphelper = require "navigator.lspwrapper" local lsphelper = require "navigator.lspwrapper"
local gui = require "navigator.gui" local gui = require "navigator.gui"
local M = {} local M = {}
@ -7,18 +8,17 @@ local partial = util.partial
local locations_to_items = lsphelper.locations_to_items local locations_to_items = lsphelper.locations_to_items
local log = util.log local log = util.log
-- dataformat should be same as reference -- 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 if err ~= nil then
print("ERROR: " .. tostring(err) .. error_message) print("ERROR: " .. tostring(err) .. msg)
return return
end end
return locations_to_items(locations) return locations_to_items(locations)
end end
local function implementation_handler(bang, err, method, result, client_id, bufnr) local function implementation_handler(bang, err, result, ctx, cfg)
local results = local results = location_handler(err, result, ctx, "Implementation not found")
location_handler(err, method, result, client_id, bufnr, "Implementation not found") local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = 'Implementation'}) gui.new_list_view({items = results, ft = ft, api = 'Implementation'})
end end
@ -30,7 +30,8 @@ function M.implementation(bang, opts)
local params = vim.lsp.util.make_position_params() local params = vim.lsp.util.make_position_params()
log("impel params", 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 end
M.implementation_call = partial(M.implementation, 0) M.implementation_call = partial(M.implementation, 0)

@ -1,6 +1,8 @@
local M = {} local M = {}
local util = require "navigator.util" local util = require "navigator.util"
local nvim_0_6 = util.nvim_0_6()
local gutil = require "guihua.util" local gutil = require "guihua.util"
local lsp = require "vim.lsp" local lsp = require "vim.lsp"
local api = vim.api 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, local results_lsp, err = lsp.buf_request_sync(0, method, params,
opts.timeout or vim.g.navtator_timeout or 1000) 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 end
function M.call_async(method, params, handler) function M.call_async(method, params, handler)

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

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

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

@ -3,6 +3,9 @@
-- Some of function copied from https://github.com/RishabhRD/nvim-lsputils -- Some of function copied from https://github.com/RishabhRD/nvim-lsputils
local M = {log_path = vim.lsp.get_log_path()} local M = {log_path = vim.lsp.get_log_path()}
-- local is_windows = uv.os_uname().version:match("Windows") -- local is_windows = uv.os_uname().version:match("Windows")
local nvim_0_6
M.path_sep = function() M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find("Windows") local is_win = vim.loop.os_uname().sysname:find("Windows")
if is_win then if is_win then
@ -144,8 +147,12 @@ elseif _NgConfigValues.debug == "trace" then
level = "trace" level = "trace"
end end
local default_config = {plugin = "navigator", use_console = false, use_file = true, level = level} local default_config = {use_console = false, use_file = true, level = level}
M._log = require("guihua.log").new({level = default_config.level}, true) 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 -- add log to you lsp.log
M.log = M._log.info M.log = M._log.info
@ -290,12 +297,6 @@ function M.exists(var)
end end
end end
function M.partial(func, arg)
return (function(...)
return func(arg, ...)
end)
end
local exclude_ft = {"scrollbar", "help", "NvimTree"} local exclude_ft = {"scrollbar", "help", "NvimTree"}
function M.exclude(fname) function M.exclude(fname)
for i = 1, #exclude_ft do for i = 1, #exclude_ft do
@ -349,4 +350,40 @@ function M.get_current_winid()
return api.nvim_get_current_win() return api.nvim_get_current_win()
end 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 return M

@ -9,8 +9,10 @@ local cur_dir = vim.fn.expand("%:p:h")
-- local ulog = require('go.utils').log -- local ulog = require('go.utils').log
describe("should run lsp reference", function() describe("should run lsp reference", function()
-- vim.fn.readfile('minimal.vim') -- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) local nvim_6 = true
-- status = require("plenary.reload").reload_module("go.nvim") if debug.getinfo(vim.lsp.handlers.signature_help).nparams > 4 then
nvim_6 = false
end
it("should show references", function() it("should show references", function()
local status = require("plenary.reload").reload_module("navigator") local status = require("plenary.reload").reload_module("navigator")
@ -26,7 +28,7 @@ describe("should run lsp reference", function()
local bufn = vim.fn.bufnr("") local bufn = vim.fn.bufnr("")
-- require'lspconfig'.gopls.setup {} -- require'lspconfig'.gopls.setup {}
require'navigator'.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 ", code_action_icon = "A ",
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) 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 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() vim.wait(400, function()
end) end)
local clients = vim.lsp.get_active_clients() local clients = vim.lsp.get_active_clients()
print(vim.inspect(clients)) print("lsp clients: ", #clients)
if #clients > 0 then if #clients > 0 then
break break
end end
@ -68,20 +70,24 @@ describe("should run lsp reference", function()
vim.bo.filetype = "go" vim.bo.filetype = "go"
require'navigator'.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 ", code_action_icon = "A ",
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) 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 height = 0.3, -- max list window height, 0.3 by default
preview_height = 0.35, -- max height of preview windows preview_height = 0.35, -- max height of preview windows
debug_console_output = true,
border = 'none' border = 'none'
}) })
_NgConfigValues.debug_console_output = true
vim.bo.filetype = "go"
-- allow gopls start -- allow gopls start
for i = 1, 10 do for i = 1, 10 do
vim.wait(400, function() vim.wait(400, function()
end) end)
local clients = vim.lsp.get_active_clients() local clients = vim.lsp.get_active_clients()
print(vim.inspect(clients)) print("clients ", #clients)
if #clients > 0 then if #clients > 0 then
break break
end end
@ -115,12 +121,29 @@ 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 win, items, width = require('navigator.reference').reference_handler(nil,
"textDocument/references", local win, items, width
result, 1, 1)
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[1].display_filename, "./interface.go")
eq(win.ctrl.data[2].range.start.line, 14) eq(win.ctrl.data[2].range.start.line, 14)
eq(items[1].display_filename, "./interface.go") eq(items[1].display_filename, "./interface.go")
-- eq(width, 60) -- eq(width, 60)
end) end)
end) end)

Loading…
Cancel
Save