From d1836f42994ab9e78d189fae57bfd9d52491ad58 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 30 Apr 2022 21:45:26 +1000 Subject: [PATCH 1/8] update resolved_capacities --- lua/navigator/codelens.lua | 2 +- lua/navigator/definition.lua | 3 ++- lua/navigator/dochighlight.lua | 2 +- lua/navigator/hierarchy.lua | 4 ++-- lua/navigator/implementation.lua | 2 +- lua/navigator/lspclient/attach.lua | 6 +++--- lua/navigator/lspclient/clients.lua | 16 ++++++++-------- lua/navigator/lspclient/mapping.lua | 22 +++++++++++----------- lua/navigator/lspwrapper.lua | 3 ++- lua/navigator/reference.lua | 2 +- lua/navigator/symbols.lua | 6 ++++-- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/lua/navigator/codelens.lua b/lua/navigator/codelens.lua index 994f297..41a79c9 100644 --- a/lua/navigator/codelens.lua +++ b/lua/navigator/codelens.lua @@ -96,7 +96,7 @@ function M.refresh() log('Must have a client running to use lsp code action') return end - if not lsphelper.check_capabilities('code_lens') then + if not lsphelper.check_capabilities('codeLensProvider') then return end vim.lsp.codelens.refresh() diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index b491dd6..d02dc0c 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -144,7 +144,8 @@ local def = function() local ref_params = vim.lsp.util.make_position_params() vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) - if client.resolved_capabilities.goto_definition then + -- if client.resolved_capabilities.goto_definition then + if client.server_capabilities.definitionProvider then client.request('textDocument/definition', ref_params, definition_hdlr, _bufnr) end end) diff --git a/lua/navigator/dochighlight.lua b/lua/navigator/dochighlight.lua index 742c183..1b97f01 100644 --- a/lua/navigator/dochighlight.lua +++ b/lua/navigator/dochighlight.lua @@ -210,7 +210,7 @@ _G.nav_doc_hl = function() local bufnr = vim.api.nvim_get_current_buf() local ref_params = vim.lsp.util.make_position_params() vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, bufnr) - if client.resolved_capabilities.document_highlight then + if client.server_capabilities.documentHighlightProvider then client.request('textDocument/documentHighlight', ref_params, handle_document_highlight, bufnr) end end) diff --git a/lua/navigator/hierarchy.lua b/lua/navigator/hierarchy.lua index 36badd5..5e80118 100644 --- a/lua/navigator/hierarchy.lua +++ b/lua/navigator/hierarchy.lua @@ -79,7 +79,7 @@ end function M.incoming_calls(bang, opts) local bufnr = vim.api.nvim_get_current_buf() assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy') - if not lsphelper.check_capabilities('call_hierarchy') then + if not lsphelper.check_capabilities('callHierarchyProvider') then return end @@ -90,7 +90,7 @@ end function M.outgoing_calls(bang, opts) local bufnr = vim.api.nvim_get_current_buf() assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp_tags') - if not lsphelper.check_capabilities('call_hierarchy') then + if not lsphelper.check_capabilities('callHierarchyProvider') then return end diff --git a/lua/navigator/implementation.lua b/lua/navigator/implementation.lua index 6096e60..208641d 100644 --- a/lua/navigator/implementation.lua +++ b/lua/navigator/implementation.lua @@ -23,7 +23,7 @@ local function implementation_handler(bang, err, result, ctx, cfg) end function M.implementation(bang, opts) - if not lsphelper.check_capabilities('implementation') then + if not lsphelper.check_capabilities('implementationProvider') then return end diff --git a/lua/navigator/lspclient/attach.lua b/lua/navigator/lspclient/attach.lua index 19dd8d3..3be7800 100644 --- a/lua/navigator/lspclient/attach.lua +++ b/lua/navigator/lspclient/attach.lua @@ -34,7 +34,7 @@ M.on_attach = function(client, bufnr) bufnr = bufnr, }) - if client.resolved_capabilities.document_highlight then + if client.server_capabilities.documentHighlightProvider then require('navigator.dochighlight').documentHighlight() end @@ -60,8 +60,8 @@ M.on_attach = function(client, bufnr) end if _NgConfigValues.lsp.code_action.enable then - if client.resolved_capabilities.code_action then - log('code action enabled for client', client.resolved_capabilities.code_action) + if client.server_capabilities.codeActionProvider then + log('code action enabled for client', client.server_capabilities.codeActionProvider) vim.cmd([[autocmd CursorHold,CursorHoldI lua require'navigator.codeAction'.code_action_prompt()]]) end end diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index a333bd1..1da0f52 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -184,8 +184,8 @@ local setups = { '--cross-file-rename', }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, - on_attach = function(client, buffnr) - client.resolved_capabilities.document_formatting = true + on_attach = function(client, bufnr) + client.server_capabilities.documentFormattingProvider = true on_attach(client, bufnr) end, }, @@ -208,7 +208,7 @@ local setups = { sqls = { filetypes = { 'sql' }, on_attach = function(client, bufnr) - client.resolved_capabilities.execute_command = true + client.server_capabilities.executeCommandProvider = true highlight.diagnositc_config_sign() require('sqls').setup({ picker = 'telescope' }) -- or default end, @@ -546,7 +546,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) if config.combined_attach == nil then cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) - client.resolved_capabilities.document_formatting = enable_fmt + client.server_capabilities.documentFormattingProvider = enable_fmt end end if config.combined_attach == 'mine' then @@ -555,7 +555,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) end cfg.on_attach = function(client, bufnr) config.on_attach(client, bufnr) - client.resolved_capabilities.document_formatting = enable_fmt + client.server_capabilities.documentFormattingProvider = enable_fmt require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -567,7 +567,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) config.on_attach(client, bufnr) - client.resolved_capabilities.document_formatting = enable_fmt + client.server_capabilities.documentFormattingProvider = enable_fmt require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -577,7 +577,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) end if config.combined_attach == 'both' then cfg.on_attach = function(client, bufnr) - client.resolved_capabilities.document_formatting = enable_fmt + client.server_capabilities.documentFormattingProvider = enable_fmt if config.on_attach and type(config.on_attach) == 'function' then config.on_attach(client, bufnr) end @@ -605,7 +605,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) else cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) - client.resolved_capabilities.document_formatting = enable_fmt + client.server_capabilities.documentFormattingProvider = enable_fmt end end diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index 6cc650b..95c9709 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -71,23 +71,23 @@ local check_cap = function(opts) local fmt, rfmt, ccls local cap = opts.cap if cap == nil then - if opts.client and opts.client.resolved_capabilities then - cap = opts.client.resolved_capabilities + if opts.client and opts.client.server_capabilities then + cap = opts.client.server_capabilities end end - if cap and cap.document_formatting then + if cap and cap.documentFormattingProvider then fmt = true end - if cap and cap.document_range_formatting then + if cap and cap.documentRangeFormattingProvider then rfmt = true end for _, value in pairs(vim.lsp.buf_get_clients(0)) do trace(value) - if value ~= nil and value.resolved_capabilities == nil then - if value.resolved_capabilities.document_formatting then + if value ~= nil and value.server_capabilities == nil then + if value.server_capabilities.documentFormattingProvider then fmt = true end - if value.resolved_capabilities.document_range_formatting then + if value.server_capabilities.documentRangeFormattingProvider then rfmt = true end @@ -257,11 +257,11 @@ function M.setup(user_opts) set_event_handler(user_opts) local client = user_opts.client or {} - local cap = client.resolved_capabilities or vim.lsp.protocol.make_client_capabilities() + local cap = client.server_capabilities or vim.lsp.protocol.make_client_capabilities() log('lsp cap:', cap) - if cap.call_hierarchy or cap.callHierarchy then + if cap.call_hierarchy or cap.callHierarchyProvider then vim.lsp.handlers['callHierarchy/incomingCalls'] = require('navigator.hierarchy').incoming_calls_handler vim.lsp.handlers['callHierarchy/outgoingCalls'] = require('navigator.hierarchy').outgoing_calls_handler end @@ -270,7 +270,7 @@ function M.setup(user_opts) -- vim.lsp.handlers["textDocument/codeAction"] = require"navigator.codeAction".code_action_handler vim.lsp.handlers['textDocument/definition'] = require('navigator.definition').definition_handler - if cap.declaration then + if cap.declarationProvider then vim.lsp.handlers['textDocument/declaration'] = require('navigator.definition').declaration_handler end @@ -298,7 +298,7 @@ function M.setup(user_opts) end vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = single }) - if cap.document_formatting then + if cap.documentFormattingProvider then log('formatting enabled setup hdl') vim.lsp.handlers['textDocument/formatting'] = require('navigator.formatting').format_hdl end diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index 143e03a..c1164b8 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -122,7 +122,8 @@ function M.check_capabilities(feature, client_id) local supported_client = false for _, client in pairs(clients) do - supported_client = client.resolved_capabilities[feature] + -- supported_client = client.resolved_capabilities[feature] + supported_client = client.server_capabilities[feature] if supported_client then break end diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index 38cb1ca..cfc3bdb 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -206,7 +206,7 @@ local ref = function() local ref_params = vim.lsp.util.make_position_params() vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, bufnr) - if client.resolved_capabilities.find_references then + if client.server_capabilities.referencesProvider then client.request('textDocument/references', ref_params, ref_hdlr, bufnr) end end) diff --git a/lua/navigator/symbols.lua b/lua/navigator/symbols.lua index 6f121bc..939f348 100644 --- a/lua/navigator/symbols.lua +++ b/lua/navigator/symbols.lua @@ -14,7 +14,8 @@ function M.workspace_symbols(query) local bufnr = vim.api.nvim_get_current_buf() local params = { query = query } vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) - if client.resolved_capabilities.workspace_symbol then + -- if client.resolved_capabilities.workspace_symbol then + if client.server_capabilities.workspaceSymbolProvider then client.request('workspace/symbol', params, M.workspace_symbol_handler, _bufnr) end end) @@ -35,7 +36,8 @@ function M.document_symbols(opts) params.context = { includeDeclaration = true } params.query = opts.prompt or '' vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr) - if client.resolved_capabilities.document_symbol then + -- if client.resolved_capabilities.document_symbol then + if client.server_capabilities.documentSymbolProvider then client.request('textDocument/documentSymbol', params, M.document_symbol_handler, _bufnr) end end) From 500553ae6be1aab7a44c94917391bb87faa243e1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 8 May 2022 21:09:35 +1000 Subject: [PATCH 2/8] format renaming --- lua/navigator/lspclient/clients.lua | 42 ++++++++++++++++++++++++----- lua/navigator/lspclient/mapping.lua | 10 ++++--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 1da0f52..eb7ff1a 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -185,7 +185,8 @@ local setups = { }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, on_attach = function(client, bufnr) - client.server_capabilities.documentFormattingProvider = true + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or true on_attach(client, bufnr) end, }, @@ -208,7 +209,7 @@ local setups = { sqls = { filetypes = { 'sql' }, on_attach = function(client, bufnr) - client.server_capabilities.executeCommandProvider = true + client.server_capabilities.executeCommandProvider = client.server_capabilities.documentFormattingProvider or true highlight.diagnositc_config_sign() require('sqls').setup({ picker = 'telescope' }) -- or default end, @@ -546,7 +547,12 @@ local function lsp_startup(ft, retry, user_lsp_opts) if config.combined_attach == nil then cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) - client.server_capabilities.documentFormattingProvider = enable_fmt + if enable_fmt then + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enable_fmt + else + client.server_capabilities.documentFormattingProvider = false + end end end if config.combined_attach == 'mine' then @@ -555,7 +561,12 @@ local function lsp_startup(ft, retry, user_lsp_opts) end cfg.on_attach = function(client, bufnr) config.on_attach(client, bufnr) - client.server_capabilities.documentFormattingProvider = enable_fmt + if enable_fmt then + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enable_fmt + else + client.server_capabilities.documentFormattingProvider = false + end require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -567,7 +578,12 @@ local function lsp_startup(ft, retry, user_lsp_opts) cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) config.on_attach(client, bufnr) - client.server_capabilities.documentFormattingProvider = enable_fmt + if enable_fmt then + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enable_fmt + else + client.server_capabilities.documentFormattingProvider = false + end require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -577,7 +593,13 @@ local function lsp_startup(ft, retry, user_lsp_opts) end if config.combined_attach == 'both' then cfg.on_attach = function(client, bufnr) - client.server_capabilities.documentFormattingProvider = enable_fmt + if enable_fmt then + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enable_fmt + else + client.server_capabilities.documentFormattingProvider = false + end + if config.on_attach and type(config.on_attach) == 'function' then config.on_attach(client, bufnr) end @@ -605,7 +627,13 @@ local function lsp_startup(ft, retry, user_lsp_opts) else cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) - client.server_capabilities.documentFormattingProvider = enable_fmt + + if enable_fmt then + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enable_fmt + else + client.server_capabilities.documentFormattingProvider = false + end end end diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index 95c9709..ea6f9bb 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -9,6 +9,10 @@ local event_hdlrs = { { ev = 'CursorMoved', func = 'clear_references()' }, } +if vim.lsp.buf.format == nil then + vim.lsp.buf.format = vim.lsp.buf.formatting +end + if vim.diagnostic == nil then util.error('Please update nvim to 0.6.1+') end @@ -51,7 +55,7 @@ local key_maps = { { key = 'k', func = "require('navigator.dochighlight').hi_symbol()" }, { key = 'wa', func = "require('navigator.workspace').add_workspace_folder()" }, { key = 'wr', func = "require('navigator.workspace').remove_workspace_folder()" }, - { key = 'ff', func = 'formatting()', mode = 'n' }, + { key = 'ff', func = 'format({async = true})', mode = 'n' }, { key = 'ff', func = 'range_formatting()', mode = 'v' }, { key = 'wl', func = "require('navigator.workspace').list_workspace_folders()" }, { key = 'la', mode = 'n', func = "require('navigator.codelens').run_action()" }, @@ -157,7 +161,7 @@ local function set_mapping(user_opts) local m = value.mode or 'n' if string.find(value.func, 'range_formatting') then rfmtkey = value.key - elseif string.find(value.func, 'formatting') then + elseif string.find(value.func, 'format') then fmtkey = value.key end log('binding', k, f) @@ -174,7 +178,7 @@ local function set_mapping(user_opts) vim.cmd([[ aug NavigatorAuFormat au! - autocmd BufWritePre lua vim.lsp.buf.formatting() + autocmd BufWritePre lua vim.lsp.buf.format({async = true}) aug END ]]) elseif fmtkey then From 0ac13663cf53419c8a9d6e4c798462ebea411dfe Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 8 May 2022 21:52:21 +1000 Subject: [PATCH 3/8] remove comments --- lua/navigator/lspclient/clients.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index eb7ff1a..8f5d36b 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -380,12 +380,6 @@ local configs = {} -- check and load based on file type local function load_cfg(ft, client, cfg, loaded) - -- if _NG_LSPCfgSetup ~= true then - -- log(lspconfig_setup) - -- lspconfig_setup(cfg) - -- _NG_LSPCfgSetup = true - -- end - log(ft, client, loaded) trace(cfg) if lspconfig[client] == nil then From 4d931729152640708597ea7c4863abbdaafdd0ba Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 11 May 2022 00:22:18 +1000 Subject: [PATCH 4/8] remove mk_handler. update documentFormator --- lua/navigator/codelens.lua | 19 +++------- lua/navigator/definition.lua | 4 +- lua/navigator/diagnostics.lua | 5 +-- lua/navigator/dochighlight.lua | 9 ++--- lua/navigator/foldlsp.lua | 5 +-- lua/navigator/formatting.lua | 5 +-- lua/navigator/implementation.lua | 1 - lua/navigator/lspclient/clients.lua | 59 ++++++++++++----------------- lua/navigator/lspwrapper.lua | 7 +--- lua/navigator/reference.lua | 5 +-- lua/navigator/signature.lua | 5 +-- lua/navigator/symbols.lua | 9 ++--- lua/navigator/util.lua | 18 +++++++-- 13 files changed, 66 insertions(+), 85 deletions(-) diff --git a/lua/navigator/codelens.lua b/lua/navigator/codelens.lua index 41a79c9..40a0b96 100644 --- a/lua/navigator/codelens.lua +++ b/lua/navigator/codelens.lua @@ -4,8 +4,6 @@ local codelens = require('vim.lsp.codelens') local log = require('navigator.util').log -local mk_handler = require('navigator.util').mk_handler -local nvim_0_6_1 = require('navigator.util').nvim_0_6_1 local trace = require('navigator.util').trace local lsphelper = require('navigator.lspwrapper') @@ -49,7 +47,7 @@ local function _update_sign(line) end end -local codelens_hdlr = mk_handler(function(err, result, ctx, cfg) +local codelens_hdlr = function(err, result, ctx, cfg) trace(ctx, result) M.codelens_ctx = ctx if err or result == nil then @@ -62,7 +60,7 @@ local codelens_hdlr = mk_handler(function(err, result, ctx, cfg) for _, v in pairs(result) do _update_sign(v.range.start.line) end -end) +end function M.setup() vim.cmd('highlight! link LspCodeLens LspDiagnosticsHint') @@ -75,18 +73,13 @@ function M.setup() vim.cmd("autocmd BufEnter,CursorHold,InsertLeave lua require('navigator.codelens').refresh()") vim.cmd('augroup end') local on_codelens = vim.lsp.handlers['textDocument/codeLens'] - vim.lsp.handlers['textDocument/codeLens'] = mk_handler(function(err, result, ctx, cfg) + vim.lsp.handlers['textDocument/codeLens'] = function(err, result, ctx, cfg) -- trace(err, result, ctx.client_id, ctx.bufnr, cfg or {}) cfg = cfg or {} ctx = ctx or { bufnr = vim.api.nvim_get_current_buf() } - if nvim_0_6_1() 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, nil, result, ctx.client_id or 0, ctx.bufnr or 0) - end - end) + on_codelens(err, result, ctx, cfg) + codelens_hdlr(err, result, ctx, cfg) + end end M.lsp_clients = {} diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index d02dc0c..c14c7f5 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -5,7 +5,7 @@ local gui = require('navigator.gui') local log = util.log local TextView = require('guihua.textview') -- callback for lsp definition, implementation and declaration handler -local definition_hdlr = util.mk_handler(function(err, locations, ctx, _) +local definition_hdlr = function(err, locations, ctx, _) -- log(locations) if err ~= nil then vim.notify('Defination: ' .. tostring(err) .. vim.inspect(ctx), vim.lsp.log_levels.WARN) @@ -31,7 +31,7 @@ local definition_hdlr = util.mk_handler(function(err, locations, ctx, _) else vim.lsp.util.jump_to_location(locations, oe) end -end) +end local function get_symbol() local currentWord = vim.fn.expand('') diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 244c963..c3f75bc 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -9,7 +9,6 @@ local trace = require('guihua.log').trace -- trace = log 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() local empty = util.empty @@ -194,7 +193,7 @@ local update_err_marker_async = function() return debounce(400, error_marker) end -local diag_hdlr = mk_handler(function(err, result, ctx, config) +local diag_hdlr = function(err, result, ctx, config) require('navigator.lspclient.highlight').diagnositc_config_sign() config = config or diagnostic_cfg if err ~= nil then @@ -305,7 +304,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config) vim.api.nvim_buf_clear_namespace(0, _NG_VT_DIAG_NS, 0, -1) _NG_VT_DIAG_NS = nil end -end) +end local diag_hdlr_async = function() local debounce = require('navigator.debounce').debounce_trailing diff --git a/lua/navigator/dochighlight.lua b/lua/navigator/dochighlight.lua index 1b97f01..97b6ede 100644 --- a/lua/navigator/dochighlight.lua +++ b/lua/navigator/dochighlight.lua @@ -1,7 +1,6 @@ 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 = {} @@ -139,7 +138,7 @@ local function before(r1, r2) return false end -local handle_document_highlight = mk_handler(function(_, result, ctx) +local handle_document_highlight = function(_, result, ctx) trace(result, ctx) if not ctx.bufnr then log('ducment highlight error', result, ctx) @@ -157,7 +156,7 @@ local handle_document_highlight = mk_handler(function(_, result, ctx) references[ctx.bufnr] = result local client_id = ctx.client_id vim.lsp.util.buf_highlight_references(ctx.bufnr, result, util.encoding(client_id)) -end) +end -- modify from vim-illuminate local function goto_adjent_reference(opt) trace(opt) @@ -227,7 +226,7 @@ local function documentHighlight() ]], false ) - vim.lsp.handlers['textDocument/documentHighlight'] = mk_handler(function(err, result, ctx) + vim.lsp.handlers['textDocument/documentHighlight'] = function(err, result, ctx) local bufnr = ctx.bufnr or api.nvim_get_current_buf() if err then vim.notify(err, vim.lsp.log_levels.ERROR) @@ -250,7 +249,7 @@ local function documentHighlight() end) references[bufnr] = result add_locs(bufnr, result) - end) + end end return { diff --git a/lua/navigator/foldlsp.lua b/lua/navigator/foldlsp.lua index 43f3f6b..6e70528 100644 --- a/lua/navigator/foldlsp.lua +++ b/lua/navigator/foldlsp.lua @@ -1,5 +1,4 @@ local log = require('navigator.util').log -local mk_handler = require('navigator.util').mk_handler local lsp = vim.lsp local api = vim.api @@ -88,7 +87,7 @@ function M.debug_folds() end end -M.fold_handler = mk_handler(function(err, result, ctx, config) +M.fold_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 @@ -112,7 +111,7 @@ M.fold_handler = mk_handler(function(err, result, ctx, config) 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 diff --git a/lua/navigator/formatting.lua b/lua/navigator/formatting.lua index ad9ce6c..18f4954 100644 --- a/lua/navigator/formatting.lua +++ b/lua/navigator/formatting.lua @@ -1,8 +1,7 @@ -- 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 = mk_handler(function(err, result, ctx, cfg) -- FIXME: bufnr is nil + format_hdl = function(err, result, ctx, cfg) -- FIXME: bufnr is nil if err ~= nil or result == nil then return end @@ -31,5 +30,5 @@ return { -- end end end, 100) - end), + end, } diff --git a/lua/navigator/implementation.lua b/lua/navigator/implementation.lua index 208641d..7c2e0f8 100644 --- a/lua/navigator/implementation.lua +++ b/lua/navigator/implementation.lua @@ -1,5 +1,4 @@ local util = require('navigator.util') -local mk_handler = util.mk_handler local lsphelper = require('navigator.lspwrapper') local gui = require('navigator.gui') local M = {} diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 8f5d36b..2f0b769 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -432,8 +432,25 @@ local function load_cfg(ft, client, cfg, loaded) -- need to verify the lsp server is up end +local function setup_fmt(client, enabled) + if not require('navigator.util').nvim_0_8() then + if enabled == false then + client.resolved_capabilities.document_formatting = enabled + else + client.resolved_capabilities.document_formatting = client.resolved_capabilities.document_formatting or enabled + end + end + + if enabled == false then + client.server_capabilities.documentFormattingProvider = false + else + client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider + or enabled + end +end + local function update_capabilities() - trace(ft, 'lsp startup') + trace(vim.o.ft, 'lsp startup') local loaded = {} local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -521,6 +538,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) -- filetype disabled if not vim.tbl_contains(cfg.filetypes or {}, ft) then trace('ft', ft, 'disabled for', lspclient) + goto continue end @@ -539,15 +557,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) -- log(lsp_opts[lspclient], cfg) cfg = vim.tbl_deep_extend('force', cfg, user_lsp_opts[lspclient]) if config.combined_attach == nil then - cfg.on_attach = function(client, bufnr) - on_attach(client, bufnr) - if enable_fmt then - client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider - or enable_fmt - else - client.server_capabilities.documentFormattingProvider = false - end - end + setup_fmt(client, enable_fmt) end if config.combined_attach == 'mine' then if config.on_attach == nil then @@ -555,12 +565,8 @@ local function lsp_startup(ft, retry, user_lsp_opts) end cfg.on_attach = function(client, bufnr) config.on_attach(client, bufnr) - if enable_fmt then - client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider - or enable_fmt - else - client.server_capabilities.documentFormattingProvider = false - end + + setup_fmt(client, enable_fmt) require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -572,12 +578,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) config.on_attach(client, bufnr) - if enable_fmt then - client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider - or enable_fmt - else - client.server_capabilities.documentFormattingProvider = false - end + setup_fmt(client, enable_fmt) require('navigator.lspclient.mapping').setup({ client = client, bufnr = bufnr, @@ -587,12 +588,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) end if config.combined_attach == 'both' then cfg.on_attach = function(client, bufnr) - if enable_fmt then - client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider - or enable_fmt - else - client.server_capabilities.documentFormattingProvider = false - end + setup_fmt(client, enable_fmt) if config.on_attach and type(config.on_attach) == 'function' then config.on_attach(client, bufnr) @@ -622,12 +618,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) cfg.on_attach = function(client, bufnr) on_attach(client, bufnr) - if enable_fmt then - client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider - or enable_fmt - else - client.server_capabilities.documentFormattingProvider = false - end + setup_fmt(client, enable_fmt) end end diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index c1164b8..3439fc5 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -1,7 +1,6 @@ local M = {} local util = require('navigator.util') -local nvim_0_6_1 = util.nvim_0_6_1() local gutil = require('guihua.util') local lsp = require('vim.lsp') @@ -146,11 +145,7 @@ function M.call_sync(method, params, opts, handler) opts = opts or {} local results_lsp, err = lsp.buf_request_sync(0, method, params, opts.timeout or vim.g.navtator_timeout or 1000) - if nvim_0_6_1 then - handler(err, extract_result(results_lsp), { method = method }, nil) - else - handler(err, method, extract_result(results_lsp), nil, nil) - end + handler(err, extract_result(results_lsp), { method = method }, nil) end function M.call_async(method, params, handler) diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index cfc3bdb..ae4ae7c 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -1,5 +1,4 @@ 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') @@ -135,7 +134,7 @@ local ref_view = function(err, locations, ctx, cfg) return listview, items, width end -local ref_hdlr = mk_handler(function(err, locations, ctx, cfg) +local ref_hdlr = function(err, locations, ctx, cfg) _NgConfigValues.closer = nil trace(err, locations, ctx, cfg) M.async_hdlr = vim.loop.new_async(vim.schedule_wrap(function() @@ -145,7 +144,7 @@ local ref_hdlr = mk_handler(function(err, locations, ctx, cfg) end end)) M.async_hdlr:send() -end) +end local async_ref = function() local ref_params = vim.lsp.util.make_position_params() diff --git a/lua/navigator/signature.lua b/lua/navigator/signature.lua index 62afa6e..1d15ea9 100644 --- a/lua/navigator/signature.lua +++ b/lua/navigator/signature.lua @@ -1,6 +1,5 @@ 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" @@ -47,7 +46,7 @@ local match_parameter = function(result) end end -local signature_handler = mk_handler(function(err, result, ctx, config) +local signature_handler = function(err, result, ctx, config) if config == nil then log("config nil") end @@ -71,5 +70,5 @@ local signature_handler = mk_handler(function(err, result, ctx, config) local syntax = vim.lsp.util.try_trim_markdown_code_blocks(lines) config.focus_id = ctx.bufnr .. "lsp_signature" vim.lsp.util.open_floating_preview(lines, syntax, config) -end) +end return {signature_handler = signature_handler} diff --git a/lua/navigator/symbols.lua b/lua/navigator/symbols.lua index 939f348..055d30a 100644 --- a/lua/navigator/symbols.lua +++ b/lua/navigator/symbols.lua @@ -2,7 +2,6 @@ local gui = require('navigator.gui') local M = {} local log = require('navigator.util').log local trace = require('navigator.util').trace -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 @@ -43,7 +42,7 @@ function M.document_symbols(opts) end) end -M.document_symbol_handler = mk_handler(function(err, result, ctx) +M.document_symbol_handler = function(err, result, ctx) if err then vim.notify('failed to get document symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN) end @@ -101,9 +100,9 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx) local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') gui.new_list_view({ items = locations, prompt = true, rawdata = true, ft = ft, api = ' ' }) -end) +end -M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg) +M.workspace_symbol_handler = function(err, result, ctx, cfg) trace(err, result, ctx, cfg) if err then vim.notify('failed to get workspace symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN) @@ -123,6 +122,6 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg) local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft') gui.new_list_view({ items = items, prompt = true, ft = ft, rowdata = true, api = ' ' }) -end) +end return M diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 1d6fc4d..87a5c06 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -5,6 +5,7 @@ local M = { log_path = vim.lsp.get_log_path() } -- local is_windows = uv.os_uname().version:match("Windows") local guihua = require('guihua.util') local nvim_0_6_1 +local nvim_0_8 M.path_sep = function() local is_win = vim.loop.os_uname().sysname:find('Windows') @@ -354,11 +355,20 @@ function M.nvim_0_6_1() return nvim_0_6_1 end +function M.nvim_0_8() + if nvim_0_8 ~= nil then + return nvim_0_8 + end + nvim_0_8 = vim.fn.has('nvim-0.8') == 1 + if nvim_0_8 == false then + M.warn('Please use navigator 0.4 version for neovim version < 0.8') + end + return nvim_0_8 +end + function M.mk_handler(fn) return function(...) - if M.nvim_0_6_1() then - return fn(...) - end + return fn(...) end end @@ -392,7 +402,7 @@ function M.encoding(client) return 'utf-8' end if type(oe) == 'table' then - oe = oe[1] or 'utf-8' + return oe[1] end return oe end From 45385ccc9abd9844ce6dd3090111aae79c6f22f5 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 14 May 2022 20:42:59 +1000 Subject: [PATCH 5/8] bumpup test image to ubuntu 22.04 --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fef8136..6cb51ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,15 +10,15 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-20.04 + - os: ubuntu-22.04 url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz manager: sudo snap packages: go - - os: ubuntu-20.04 + - os: ubuntu-22.04 url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz manager: sudo snap packages: go - - os: ubuntu-20.04 + - os: ubuntu-22.04 url: https://github.com/neovim/neovim/releases/download/v0.6.1/nvim-linux64.tar.gz manager: sudo snap packages: go @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: "^1.17.2" # The Go version to download (if necessary) and use. + go-version: "^1.18.1" # The Go version to download (if necessary) and use. - run: date +%F > todays-date - name: Restore cache for today's nightly. uses: actions/cache@v2 From 96ca715ea6692da0c9d8367d9384d0889e00b975 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 15 May 2022 22:40:22 +1000 Subject: [PATCH 6/8] add logs when neovim is lower than 0.8 --- lua/navigator/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 87a5c06..08e1126 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -361,7 +361,7 @@ function M.nvim_0_8() end nvim_0_8 = vim.fn.has('nvim-0.8') == 1 if nvim_0_8 == false then - M.warn('Please use navigator 0.4 version for neovim version < 0.8') + M.log('Please use navigator 0.4 version for neovim version < 0.8') end return nvim_0_8 end From 8a32139e1ada2f364b48b3251bf475fadb7a8aee Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 17 May 2022 23:15:16 +1000 Subject: [PATCH 7/8] lsp installer path issue #187 --- lua/navigator/lazyloader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/navigator/lazyloader.lua b/lua/navigator/lazyloader.lua index c72022f..d3157e4 100644 --- a/lua/navigator/lazyloader.lua +++ b/lua/navigator/lazyloader.lua @@ -25,7 +25,7 @@ return { end if _NgConfigValues.lsp_installer == true then - local has_lspinst, lspinst = pcall(require, 'lsp_installer') + local has_lspinst, lspinst = pcall(require, 'nvim-lsp-installer') log('lsp_installer installed', has_lspinst) if has_lspinst then lspinst.setup() From 51a05252a5c7414c20db92edb7a49bf4b93abf73 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 19 May 2022 23:19:28 +1000 Subject: [PATCH 8/8] reformat reference_spec --- tests/reference_spec.lua | 176 +++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 91 deletions(-) diff --git a/tests/reference_spec.lua b/tests/reference_spec.lua index 2386c65..19306ca 100644 --- a/tests/reference_spec.lua +++ b/tests/reference_spec.lua @@ -1,13 +1,13 @@ local helpers = {} -local busted = require("plenary/busted") +local busted = require('plenary/busted') local eq = assert.are.same -local cur_dir = vim.fn.expand("%:p:h") +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() +describe('should run lsp reference', function() -- vim.fn.readfile('minimal.vim') local nvim_6 = true if debug.getinfo(vim.lsp.handlers.signature_help).nparams > 4 then @@ -15,113 +15,114 @@ describe("should run lsp reference", function() end 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" - } - } + 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 } }, - it("should show references", function() + 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', + }, + } - local status = require("plenary.reload").reload_module("navigator") - local status = require("plenary.reload").reload_module("guihua") - local status = require("plenary.reload").reload_module("lspconfig") + 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 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("") + local bufn = vim.fn.bufnr('') -- require'lspconfig'.gopls.setup {} - require'navigator'.setup({ + require('navigator').setup({ debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log - icons = {code_action_icon = "A "}, + 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' + border = 'none', }) -- allow gopls start for i = 1, 10 do - vim.wait(400, function() - end) + vim.wait(400, function() end) local clients = vim.lsp.get_active_clients() - print("lsp clients: ", #clients) + print('lsp clients: ', #clients) if #clients > 0 then break end end - 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() 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") + 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 + 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("") + 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({ + 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 "}, + 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' + border = 'none', }) _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) + vim.wait(400, function() end) local clients = vim.lsp.get_active_clients() - print("clients ", #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 @@ -129,65 +130,60 @@ describe("should run lsp reference", function() win, items, width = require('navigator.reference').ref_view(nil, result, { method = 'textDocument/references', bufnr = 1, - client_id = 1 + client_id = 1, }, {}) - 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 - print("win", vim.inspect(win)) - print("items", vim.inspect(items)) - eq(win.ctrl.data[1].display_filename, "./interface.go") + 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(items[1].display_filename, './interface.go') -- 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") + 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 + local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p print(path) - local cmd = " silent exe 'e " .. path .. "'" + local cmd = "silent exe 'e " .. path .. "'" vim.cmd(cmd) vim.cmd([[cd %:p:h]]) - local bufn = vim.fn.bufnr("") + 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({ + 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 "}, + 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' + border = 'none', }) _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) + vim.wait(400, function() end) local clients = vim.lsp.get_active_clients() - print("clients ", #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 @@ -195,18 +191,16 @@ describe("should run lsp reference", function() win, items, width = require('navigator.reference').ref_view(nil, result, { method = 'textDocument/references', bufnr = 1, - client_id = 1 - }, {truncate = 2}) - + client_id = 1, + }, { truncate = 2 }) 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 - print("win", vim.inspect(win)) - print("items", vim.inspect(items)) + print('win', vim.inspect(win)) + print('items', vim.inspect(items)) -- eq(win.ctrl.data, "./interface.go") - 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(items[1].display_filename, "./interface.go")