diff --git a/README.md b/README.md index 74b975f..f6eeb25 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ - Easy code navigation, view diagnostic errors, see relationships of functions, variables -- A plugin combines the power of LSP and 🌲🏡 Treesitter together. Not only provids a better highlight but also help you analyse symbol context effectively. +- A plugin combines the power of LSP and 🌲🏡 Treesitter together. Not only provides a better highlight but also help you analyse symbol context effectively. - ctags fuzzy search & build ctags symbols @@ -140,7 +140,7 @@ I'd like to go beyond what the system is offering. ## Install -Require nvim-0.6.1 or above, nightly (0.8) prefered +Require nvim-0.9 or above, nightly (0.10 or greater) preferred You can remove your lspconfig setup and use this plugin. The plugin depends on lspconfig and [guihua.lua](https://github.com/ray-x/guihua.lua), which provides GUI and fzy support(migrate from [romgrk's project](romgrk/fzy-lua-native)). @@ -364,7 +364,7 @@ require'navigator'.setup({ diagnostic_virtual_text = true, -- show virtual for diagnostic message diagnostic_update_in_insert = false, -- update diagnostic message in insert mode display_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors, set to false if you want to ignore it - -- set to 'trouble' to show diagnositcs in Trouble + -- set to 'trouble' to show diagnostcs in Trouble tsserver = { filetypes = {'typescript'} -- disable javascript etc, -- set to {} to disable the lspclient for all filetypes @@ -401,7 +401,7 @@ require'navigator'.setup({ sumneko_root_path = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server", sumneko_binary = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server/bin/macOS/lua-language-server", }, - servers = {'cmake', 'ltex'}, -- by default empty, and it should load all LSP clients avalible based on filetype + servers = {'cmake', 'ltex'}, -- by default empty, and it should load all LSP clients available based on filetype -- but if you want navigator load e.g. `cmake` and `ltex` for you , you -- can put them in the `servers` list and navigator will auto load them. -- you could still specify the custom config like this @@ -425,7 +425,7 @@ local servers = { } ``` -Navigator will try to load avalible lsp server/client based on filetype. The clients has none default on_attach. +Navigator will try to load available lsp server/client based on filetype. The clients has none default on_attach. incremental sync and debounce is enabled by navigator. And the lsp snippet will be enabled. So you could use COQ and nvim-cmp snippet expand. @@ -572,7 +572,7 @@ LspDiagnosticsXXX are used for diagnostic. Please check highlight.lua and dochig - treesitter (list treesitter symbols, object analysis) - lsp-signature (better signature help) -The plugin can be loaded lazily (packer `opt = true` ), And it will check if optional plugins existance and load those plugins only if they existed. +The plugin can be loaded lazily (packer `opt = true` ), And it will check if optional plugins existence and load those plugins only if they existed. The terminal will need to be able to output nerdfont and emoji correctly. I am using Kitty with nerdfont (Victor Mono). @@ -778,16 +778,16 @@ You can override the above highlight to fit your current colorscheme | command | function | | --------------- | ------------------------------------------------------------------------- | | LspToggleFmt | toggle lsp auto format | -| LspKeymaps | show LSP releated keymaps | +| LspKeymaps | show LSP related keymaps | | Nctags {args} | show ctags symbols, args: -g regen ctags | | LspRestart | reload lsp | | LspToggleFmt | toggle lsp format | | LspSymbols | document symbol in side panel | -| LspAndDiag | document symbol and diagnostics in side panel | +| LspAndDiag | document symbol and diagnostics in side panel | | NRefPanel | show symbol reference in side panel | | TSymbols | treesitter symbol in side panel | -| TsAndDiag | treesitter symbol and diagnostics in side panel | -| Calltree {args} | lsp call hierarchy call tree, args: -i (incomming default), -o (outgoing) | +| TsAndDiag | treesitter symbol and diagnostics in side panel | +| Calltree {args} | lsp call hierarchy call tree, args: -i (incoming default), -o (outgoing) | ## Screenshots @@ -866,7 +866,7 @@ You can in place edit your code in floating window -(Note: This feature only avalible in `find reference` and `find diagnostic`, You can not add/remove lines in floating window) +(Note: This feature only available in `find reference` and `find diagnostic`, You can not add/remove lines in floating window) ### Implementation @@ -897,7 +897,7 @@ You can in place edit your code in floating window Treetsitter symbols in all buffers ![treesitter](https://user-images.githubusercontent.com/1681295/118734953-cc6eba00-b882-11eb-9db8-0a052630d57e.jpg?raw=true) -### Call hierarchy (incomming/outgoing calls) +### Call hierarchy (incoming/outgoing calls) ![incomming_calls](https://user-images.githubusercontent.com/1681295/142348079-49b71486-4f16-4f10-95c9-483aad11c262.jpg) @@ -987,7 +987,7 @@ end ## API and extensions The plugin built on top of guihua, you can extend the plugin based on your requirements. -e.g. A side pannel of lsp symbols and lsp diagnostics: +e.g. A side panel of lsp symbols and lsp diagnostics: ```lua @@ -1040,10 +1040,11 @@ end ## Errors and Bug Reporting -- Please double check your setup and check if minium setup works or not -- It should works for 0.6.1, neovim 0.8.x prefered. +- Please double check your setup and check if minimum setup works or not +- It should works for 0.6.1, neovim 0.8.x preferred. - Check console output - Check `LspInfo` and treesitter status with `checkhealth` - Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log -- Submit Issue with minium vimrc. Please check playground/init.lua as a vimrc template. !!!Please DONOT use a packer vimrc. - That installs everything to default folder!!! Also check this repo [navigator bug report](https://github.com/fky2015/navigator.nvim-bug-report) +- Submit Issue with minium init.lua. Please check playground/init.lua as a vimrc template. + Also check this repo [navigator bug report](https://github.com/fky2015/navigator.nvim-bug-report) on how to report bug + with minimum setup. diff --git a/lua/navigator.lua b/lua/navigator.lua index 5246d18..8cb4d3b 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -186,8 +186,8 @@ _NgConfigValues = { -- Diagnostics (floating window) diagnostic_head_severity_1 = '🈲', - diagnostic_head_severity_2 = '☣️', - diagnostic_head_severity_3 = '👎', + diagnostic_head_severity_2 = '🛠️', + diagnostic_head_severity_3 = '🔧', diagnostic_head_description = '👹', -- suffix for severities diagnostic_virtual_text = '🦊', -- floating text preview (set to empty to disable) diagnostic_file = '🚑', -- icon in floating window, indicates the file contains diagnostics @@ -195,7 +195,7 @@ _NgConfigValues = { -- Values (floating window) value_definition = '🐶🍡', -- identifier defined value_changed = '📝', -- identifier modified - context_separator = '  ', -- separator between text and value + context_separator = ' ', -- separator between text and value -- Formatting for Side Panel side_panel = { @@ -206,7 +206,7 @@ _NgConfigValues = { outer_node = '╰○', bracket_left = '⟪', bracket_right = '⟫', - tab = '󰌒' + tab = '󰌒', }, fold = { prefix = '⚡', @@ -247,6 +247,10 @@ M.deprecated = function(cfg) warn('ts_fold option changed, refer to README for more details') cfg.ts_fold = { enable = cfg.ts_fold } end + local has_nvim_011 = vim.fn.has('nvim-0.11.0') + if not has_nvim_011 then + vim.lsp.get_clients = vim.lsp.get_active_clients + end end local extend_config = function(opts) @@ -381,7 +385,11 @@ M.setup = function(cfg) _NgConfigValues.loaded = true end - if _NgConfigValues.ts_fold.enable == true and not vim.tbl_contains(_NgConfigValues.ts_fold.disable_filetypes, vim.o.filetype) and not vim.wo.diff then + if + _NgConfigValues.ts_fold.enable == true + and not vim.tbl_contains(_NgConfigValues.ts_fold.disable_filetypes, vim.o.filetype) + and not vim.wo.diff + then require('navigator.foldts').on_attach() end @@ -389,7 +397,7 @@ M.setup = function(cfg) vim.lsp.start_client = function(lsp_config) -- add highlight for Lspxxx require('navigator.lspclient.highlight').add_highlight() - require('navigator.lspclient.highlight').diagnositc_config_sign() + require('navigator.lspclient.highlight').config_signs() -- require('navigator.lspclient.mapping').setup() require('navigator.lspclient.lspkind').init() return _start_client(lsp_config) diff --git a/lua/navigator/cclshierarchy.lua b/lua/navigator/cclshierarchy.lua index 9d0664e..8e7ad89 100644 --- a/lua/navigator/cclshierarchy.lua +++ b/lua/navigator/cclshierarchy.lua @@ -14,7 +14,7 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me log('call_hierarchy') log('call_hierarchy', direction, err, result, ctx, cfg) - assert(next(vim.lsp.get_active_clients()), 'Must have a client running to use lsp_tags') + assert(next(vim.lsp.get_clients()), 'Must have a client running to use lsp_tags') if err ~= nil then log('hierarchy error', ctx, 'dir', direction, 'result', result, 'err', err) vim.notify('ERROR: ' .. error_message, vim.log.levels.WARN) @@ -54,7 +54,7 @@ local call_hierarchy_handler_to = partial(call_hierarchy_handler, 'to') local function incoming_calls_handler(_, err, result, ctx, cfg) local bufnr = vim.api.nvim_get_current_buf() - assert(next(vim.lsp.get_active_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags' ) + assert(next(vim.lsp.get_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags' ) local results = call_hierarchy_handler_from(err, result, ctx, cfg, 'Incoming calls not found') @@ -72,7 +72,7 @@ end function M.incoming_calls(bang, opts) local bufnr = vim.api.nvim_get_current_buf() - assert(next(vim.lsp.get_active_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags' ) + assert(next(vim.lsp.get_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags' ) -- if not lsphelper.check_capabilities("call_hierarchy") then -- return -- end @@ -89,7 +89,7 @@ end function M.outgoing_calls(bang, opts) local bufnr = vim.api.nvim_get_current_buf() - assert(next(vim.lsp.get_active_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags') + assert(next(vim.lsp.get_clients({buffer = bufnr})), 'Must have a client running to use lsp_tags') local params = vim.lsp.util.make_position_params() params['levels'] = 2 params['callee'] = true diff --git a/lua/navigator/codeAction.lua b/lua/navigator/codeAction.lua index f47c1d8..04dbff0 100644 --- a/lua/navigator/codeAction.lua +++ b/lua/navigator/codeAction.lua @@ -81,7 +81,7 @@ function code_action:render_action_virtual_text(line, diagnostics) return function(err, actions, context) trace(actions, context) if context and context.client_id then - local cname = vim.lsp.get_active_clients({ id = context.client_id })[1].name + local cname = vim.lsp.get_clients({ id = context.client_id })[1].name if cname == 'null-ls' and _NgConfigValues.lsp.disable_nulls_codeaction_sign then return end diff --git a/lua/navigator/codelens.lua b/lua/navigator/codelens.lua index 6fce7fe..32f6f71 100644 --- a/lua/navigator/codelens.lua +++ b/lua/navigator/codelens.lua @@ -84,7 +84,7 @@ M.lsp_clients = {} function M.refresh() local bufnr = vim.api.nvim_get_current_buf() - if next(vim.lsp.get_active_clients({ buffer = bufnr })) == nil then + if next(vim.lsp.get_clients({ buffer = bufnr })) == nil then log('Must have a client running to use lsp code action') return end @@ -124,7 +124,7 @@ M.inline = function() end local bufnr = api.nvim_get_current_buf() - if next(vim.lsp.get_active_clients({ buffer = bufnr })) == nil then + if next(vim.lsp.get_clients({ buffer = bufnr })) == nil then return end if vim.tbl_contains(M.disabled, bufnr) then diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index 4e9f4c0..1e07ed6 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -58,7 +58,7 @@ local function get_symbol() end local function def_preview(timeout_ms, method) - assert(next(vim.lsp.get_active_clients({ buffer = 0 })), 'Must have a client running') + assert(next(vim.lsp.get_clients({ buffer = 0 })), 'Must have a client running') method = method or 'textDocument/definition' local params = vim.lsp.util.make_position_params() local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 1000) diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index b2965db..278da93 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -15,15 +15,12 @@ _NG_VT_DIAG_NS = api.nvim_create_namespace('navigator_lua_diag') util.nvim_0_8() -local diag_map = {} -if vim.diagnostic then - diag_map = { - Error = vim.diagnostic.severity.ERROR, - Warning = vim.diagnostic.severity.WARN, - Info = vim.diagnostic.severity.Info, - Hint = vim.diagnostic.severity.Hint, - } -end +local diag_map = { + Error = vim.diagnostic.severity.ERROR, + Warning = vim.diagnostic.severity.WARN, + Info = vim.diagnostic.severity.Info, + Hint = vim.diagnostic.severity.Hint, +} local diagnostic_cfg @@ -55,8 +52,7 @@ local function error_marker(result, ctx, config) end local first_line = vim.fn.line('w0') local last_line = vim.fn.line('w$') - local wheight = last_line - first_line + 1 - -- local rootfolder = vim.fn.expand('%:h:t') -- get the current file root folder + local weight = last_line - first_line + 1 -- local rootfolder = vim.fn.expand('%:h:t') -- get the current file root folder local bufnr = ctx.bufnr if bufnr == nil and result.uri then @@ -89,23 +85,13 @@ local function error_marker(result, ctx, config) return end - -- total line num of current buffer - - -- local winid = vim.fn.win_getid(vim.fn.winnr()) - -- local winid = api.nvim_get_current_win() local total_num = api.nvim_buf_line_count(bufnr) if total_num == 0 then return end - -- local total_num = vim.fn.getbufinfo(vim.fn.winbufnr(winid))[1].linecount - -- window size of current buffer - - -- local stats = api.nvim_list_uis()[1] or {} - -- local wwidth = stats.width; - -- local wheight = stats.height or 0 - if total_num < wheight then - wheight = total_num + if total_num < weight then + weight = total_num end if _NG_VT_DIAG_NS == nil then _NG_VT_DIAG_NS = api.nvim_create_namespace('navigator_lua_diag') @@ -119,7 +105,7 @@ local function error_marker(result, ctx, config) diags[i].range = { start = { line = diags[i].lnum } } end end - local ratio = wheight / total_num + local ratio = weight / total_num table.sort(diags, function(a, b) return a.range.start.line < b.range.start.line end) @@ -196,7 +182,7 @@ local update_err_marker_async = function() end local diag_hdlr = function(err, result, ctx, config) - require('navigator.lspclient.highlight').diagnositc_config_sign() + require('navigator.lspclient.highlight').config_signs() config = config or diagnostic_cfg if err ~= nil then log(err, config, result) @@ -316,12 +302,49 @@ local diag_hdlr = function(err, result, ctx, config) end end +local function diag_signs() + if not _NgConfigValues.lsp.diagnostic or _NgConfigValues.lsp.diagnostic.signs == false then + return + end + local icons = _NgConfigValues.icons + if icons.icons then + local e, w, i, h = + icons.diagnostic_err, icons.diagnostic_warn, icons.diagnostic_info, icons.diagnostic_hint + local t = vim.fn.sign_getdefined('DiagnosticSignWarn') + local text = { + [vim.diagnostic.severity.ERROR] = e, + [vim.diagnostic.severity.WARN] = w, + [vim.diagnostic.severity.INFO] = i, + [vim.diagnostic.severity.HINT] = h, + } + -- in case there are duplicated signs defined in _NgConfigValues.lsp.diagnostic.signs + if + _NgConfigValues.lsp.diagnostic.signs + and type(_NgConfigValues.lsp.diagnostic.signs) == 'table' + and _NgConfigValues.lsp.diagnostic.signs.text + then + for k, v in pairs(_NgConfigValues.lsp.diagnostic.signs) do + text[k] = v + end + end + if vim.tbl_isempty(t) or (t[1] and t[1].text:find('W')) then + local signs = { + text = text, + linehl = { + [vim.diagnostic.severity.ERROR] = 'ErrorMsg', + }, + } + return signs + end + end +end + -- local diag_hdlr_async = function() -- local debounce = require('navigator.debounce').debounce_trailing -- return debounce(100, diag_hdlr) -- end -function M.setup() +function M.setup(cfg) if diagnostic_cfg ~= nil and diagnostic_cfg.float ~= nil then return end @@ -331,10 +354,10 @@ function M.setup() -- Enable virtual -- Use a function to dynamically turn signs off -- and on, using buffer local variables - signs = true, update_in_insert = _NgConfigValues.lsp.diagnostic.update_in_insert or false, severity_sort = _NgConfigValues.lsp.diagnostic.severity_sort, float = _NgConfigValues.lsp.diagnostic.float, + signs = diag_signs(), } diagnostic_cfg.virtual_text = _NgConfigValues.lsp.diagnostic.virtual_text if @@ -344,6 +367,7 @@ function M.setup() end -- vim.lsp.handlers["textDocument/publishDiagnostics"] M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg) + diagnostic_cfg = vim.tbl_extend('force', diagnostic_cfg, cfg) vim.diagnostic.config(diagnostic_cfg) @@ -376,12 +400,8 @@ M.hide_diagnostic = function() end M.toggle_diagnostics = function() - if M.diagnostic_enabled then - M.diagnostic_enabled = false - return vim.diagnostic.disable() - end - vim.diagnostic.enable() - M.diagnostic_enabled = true + M.diagnostic_enabled = not vim.diagnostic.enable() + vim.diagnostic.enable(M.diagnostic_enabled) end M.show_buf_diagnostics = function() @@ -427,14 +447,14 @@ M.setloclist = function(bufnr) return vim.cmd('lclose') end - local clients = vim.lsp.get_active_clients({ buffer = bufnr }) + local clients = vim.lsp.get_clients({ buffer = bufnr }) local cfg = { open = diag_cnt > 0 } for _, client in pairs(clients) do cfg.client_id = client['id'] break end - if not vim.tbl_isempty(vim.lsp.get_active_clients({ buffer = bufnr })) then + if not vim.tbl_isempty(vim.lsp.get_clients({ buffer = bufnr })) then local err_cnt = get_count(0, [[Error]]) if err_cnt > 0 then if _NgConfigValues.lsp.display_diagnostic_qf then @@ -493,7 +513,7 @@ function M.get_line_diagnostic() local diags = diagnostic.get(api.nvim_get_current_buf(), { lnum = lnum }) table.sort(diags, function(diag1, diag2) - return diag1.severity < diag2.severity + return diag1.severity or 0 < diag2.severity or 0 end) return diags end @@ -525,24 +545,15 @@ function M.show_diagnostics(pos) end function M.config(cfg) - M.setup() cfg = cfg or {} log('diag config', cfg) - local default_cfg = { - underline = true, - virtual_text = true, - update_in_insert = false, - } - if _NgConfigValues.icons then - default_cfg.signs = { _NgConfigValues.icons.diagnostic_err } - end - + local default_cfg = {} cfg = vim.tbl_extend('keep', cfg, default_cfg) if vim.diagnostic == nil then vim.notify('deprecated: please update nvim to 0.7+') return end - vim.diagnostic.config(cfg) + M.setup(cfg) end return M diff --git a/lua/navigator/foldlsp.lua b/lua/navigator/foldlsp.lua index c523658..5215144 100644 --- a/lua/navigator/foldlsp.lua +++ b/lua/navigator/foldlsp.lua @@ -37,7 +37,7 @@ function M.setup_plugin() end, }) - local clients = vim.lsp.get_active_clients({buffer = 0}) + local clients = vim.lsp.get_clients({buffer = 0}) for _, client in pairs(clients) do local client_id = client['id'] @@ -60,7 +60,7 @@ function M.update_folds() -- In diff mode, use diff folding. api.nvim_win_set_option(current_window, 'foldmethod', 'diff') else - local clients = lsp.get_active_clients({buffer = 0}) + local clients = lsp.get_clients({buffer = 0}) for client_id, client in pairs(clients) do if M.active_folding_clients[client_id] then -- XXX: better to pass callback in this method or add it directly in the config? diff --git a/lua/navigator/hierarchy.lua b/lua/navigator/hierarchy.lua index ba8a43c..6ba2b3a 100644 --- a/lua/navigator/hierarchy.lua +++ b/lua/navigator/hierarchy.lua @@ -53,7 +53,7 @@ local function call_hierarchy_result_procesor(direction, err, result, ctx, confi -- trace('call_hierarchy', result) local bufnr = ctx.bufnr or vim.api.nvim_get_current_buf() - assert(next(vim.lsp.get_active_clients({buffer = bufnr})), 'Must have a client running to use call hierarchy') + assert(next(vim.lsp.get_clients({buffer = bufnr})), 'Must have a client running to use call hierarchy') if err ~= nil then log('dir', direction, 'result', result, 'err', err, ctx) vim.notify('ERROR: ' .. err, vim.log.levels.WARN) @@ -104,7 +104,7 @@ hierarchy_handler = function(dir, handler, show, api, err, result, ctx, cfg) local opts = ctx.opts or {} vim.validate({ handler = { handler, 'function' }, show = { show, 'function' }, api = { api, 'string' } }) local bufnr = ctx.bufnr or vim.api.nvim_get_current_buf() - assert(next(vim.lsp.get_active_clients({buffer = bufnr})), 'Must have a client running to use lsp hierarchy') + assert(next(vim.lsp.get_clients({buffer = bufnr})), 'Must have a client running to use lsp hierarchy') local results = handler(err, result, ctx, cfg, 'Incoming calls not found') diff --git a/lua/navigator/lspclient/attach.lua b/lua/navigator/lspclient/attach.lua index a111478..6999d89 100644 --- a/lua/navigator/lspclient/attach.lua +++ b/lua/navigator/lspclient/attach.lua @@ -27,7 +27,7 @@ M.on_attach = function(client, bufnr) -- add highlight for Lspxxx require('navigator.lspclient.highlight').add_highlight() - require('navigator.lspclient.highlight').diagnositc_config_sign() + require('navigator.lspclient.highlight').config_signs() api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') require('navigator.lspclient.mapping').setup({ diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 2e4b5d3..e7e07bf 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -118,7 +118,7 @@ local function load_cfg(ft, client, cfg, loaded, starting) end end - local clients = vim.lsp.get_active_clients({buffer = 0 }) + local clients = vim.lsp.get_clients({buffer = 0 }) for _, c in pairs(clients or {}) do log("lsp start up in progress client", client, c.name) if c.name == client then @@ -228,7 +228,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) local capabilities = update_capabilities() for _, lspclient in ipairs(servers) do - local clients = vim.lsp.get_active_clients() or {} + local clients = vim.lsp.get_clients() or {} for _, client in ipairs(clients) do if client ~= nil then loaded[client.name] = client.id @@ -582,7 +582,7 @@ local function setup(user_opts) trace(debug.traceback()) - local clients = vim.lsp.get_active_clients({buffer = bufnr}) + local clients = vim.lsp.get_clients({buffer = bufnr}) for key, client in pairs(clients) do if client.name ~= 'null_ls' and client.name ~= 'efm' then if vim.tbl_contains(client.filetypes or {}, vim.bo.ft) then @@ -597,7 +597,7 @@ local function setup(user_opts) local retry = true log('loading for ft ', ft, uri) - highlight.diagnositc_config_sign() + highlight.config_signs() highlight.add_highlight() local lsp_opts = user_opts.lsp or {} @@ -638,7 +638,7 @@ local function on_filetype() if _NG_Loaded[bufnr].cnt > 1 then log('navigator was loaded for ft', ft, bufnr) -- check if lsp is loaded - local clients = vim.lsp.get_active_clients({buffer = bufnr}) + local clients = vim.lsp.get_clients({buffer = bufnr}) for key, client in pairs(clients) do if client.name ~= 'null_ls' and client.name ~= 'efm' then loaded = _NG_Loaded[bufnr].lsp[client.name] diff --git a/lua/navigator/lspclient/highlight.lua b/lua/navigator/lspclient/highlight.lua index 9fe8f69..00333af 100644 --- a/lua/navigator/lspclient/highlight.lua +++ b/lua/navigator/lspclient/highlight.lua @@ -5,7 +5,7 @@ local api = vim.api local cmd_group = api.nvim_create_augroup('NGHiGroup', {}) -- lsp sign          ﮻         ﯭ        ﳀ   -function M.diagnositc_config_sign() +function M.config_signs() if M.configed then return end @@ -24,32 +24,6 @@ function M.diagnositc_config_sign() { text = icons.code_lens_action_icon, texthl = 'LspDiagnosticsSignHint' } ) end - - if icons.icons then - local e, w, i, h = - icons.diagnostic_err, icons.diagnostic_warn, icons.diagnostic_info, icons.diagnostic_hint - local t = vim.fn.sign_getdefined('DiagnosticSignWarn') - if vim.tbl_isempty(t) or t[1].text == 'W ' then - vim.fn.sign_define( - 'DiagnosticSignError', - { text = e, texthl = 'DiagnosticError', linehl = '', numhl = '' } - ) - vim.fn.sign_define( - 'DiagnosticSignWarn', - { text = w, texthl = 'DiagnosticWarn', linehl = '', numhl = '' } - ) - vim.fn.sign_define( - 'DiagnosticSignInfo', - { text = i, texthl = 'DiagnosticInfo', linehl = '', numhl = '' } - ) - vim.fn.sign_define( - 'DiagnosticSignHint', - { text = h, texthl = 'DiagnosticHint', linehl = '', numhl = '' } - ) - - t = vim.fn.sign_getdefined('DiagnosticSignWarn') - end - end M.configed = true end diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index 418b497..40ca17b 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -101,7 +101,7 @@ local ccls_mappings = { } local check_cap = function(opts) - -- log(vim.lsp.get_active_clients({buffer = 0})) + -- log(vim.lsp.get_clients({buffer = 0})) local fmt, rfmt, ccls local cap = opts.cap if cap == nil then @@ -115,7 +115,7 @@ local check_cap = function(opts) if cap and cap.documentRangeFormattingProvider then rfmt = true end - for _, value in pairs(vim.lsp.get_active_clients({ buffer = 0 })) do + for _, value in pairs(vim.lsp.get_clients({ buffer = 0 })) do trace(value) if value ~= nil and value.server_capabilities == nil then if value.server_capabilities.documentFormattingProvider then diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index af8527a..c80b59a 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -120,7 +120,7 @@ local function extract_result(results_lsp) end function M.check_capabilities(feature, bufnr) - local clients = lsp.get_active_clients({ buffer = bufnr or vim.api.nvim_get_current_buf() }) + local clients = lsp.get_clients({ buffer = bufnr or vim.api.nvim_get_current_buf() }) local supported_client = false for _, client in pairs(clients) do diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index a6a7bc2..7c119b9 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -226,7 +226,7 @@ end -- https://github.com/smjonas/inc-rename.nvim/blob/main/lua/inc_rename/init.lua local function fetch_lsp_references(bufnr, params, callback) if not vim.lsp.get_clients then - vim.lsp.get_clients = vim.lsp.get_active_clients + vim.lsp.get_clients = vim.lsp.get_clients end local clients = vim.lsp.get_clients({ bufnr = bufnr, diff --git a/lua/navigator/rename.lua b/lua/navigator/rename.lua index 38fea1d..ee4c3a3 100644 --- a/lua/navigator/rename.lua +++ b/lua/navigator/rename.lua @@ -376,7 +376,7 @@ function M.rename_inplace(new_name, options) state.lsp_params = make_position_params() rename_group = api.nvim_create_augroup('nav-rename', {}) local bufnr = options.bufnr or api.nvim_get_current_buf() - local clients = vim.lsp.get_active_clients({ + local clients = vim.lsp.get_clients({ bufnr = bufnr, name = options.name, }) diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 228ec09..90e4e57 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -277,7 +277,7 @@ function M.printError(msg) end function M.reload() - vim.lsp.stop_client(vim.lsp.get_active_clients()) + vim.lsp.stop_client(vim.lsp.get_clients()) vim.cmd([[edit]]) end diff --git a/playground/init_packer.lua b/playground/init_packer.lua deleted file mode 100644 index bbbf904..0000000 --- a/playground/init_packer.lua +++ /dev/null @@ -1,133 +0,0 @@ -vim.cmd([[set runtimepath=$VIMRUNTIME]]) -vim.cmd([[set packpath=/tmp/nvim/site]]) - -local package_root = '/tmp/nvim/site/pack' -local install_path = package_root .. '/packer/start/packer.nvim' - --- IMPORTANT: update the sumneko setup if you need lua language server --- I installed it in '/github/sumneko/lua-language-server' -local sumneko_root_path = vim.fn.expand('$HOME') .. '/github/sumneko/lua-language-server' -local sumneko_binary = vim.fn.expand('$HOME') - .. '/github/sumneko/lua-language-server/bin/macOS/lua-language-server' - -local lua_cfg = { - -- cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' }, - settings = { - Lua = { - runtime = { version = 'LuaJIT', path = vim.split(package.path, ';') }, - diagnostics = { enable = true }, - }, - }, -} - -if vim.fn.executable('lua-language-server') == 0 then - lua_cfg.cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' } -end - -local function load_plugins() - require('packer').startup({ - function(use) - use({ 'wbthomason/packer.nvim' }) - use({ - 'nvim-treesitter/nvim-treesitter', - config = function() - require('nvim-treesitter.configs').setup({ - ensure_installed = { 'python', 'go', 'javascript' }, - highlight = { enable = true }, - }) - end, - run = ':TSUpdate', - }) - use({ 'neovim/nvim-lspconfig' }) - use({ 'ray-x/lsp_signature.nvim' }) - use({ 'ray-x/aurora' }) - use({ - 'ray-x/navigator.lua', - -- '~/github/ray-x/navigator.lua', - requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' }, - config = function() - require('navigator').setup({ - debug = true, - keymaps = { - { key = 'gK', func = vim.lsp.buf.definition, doc = 'definition' }, - { - key = 'ld', - func = require('navigator.diagnostics').show_buf_diagnostics, - desc = 'show_buf_diagnostics', - }, - }, - icons = { - diagnostic_virtual_text = '', - }, - }) - end, - }) - use({ 'L3MON4D3/LuaSnip' }) - use({ - 'hrsh7th/nvim-cmp', - requires = { - 'hrsh7th/cmp-nvim-lsp', - 'saadparwaiz1/cmp_luasnip', - }, - config = function() - local cmp = require('cmp') - local luasnip = require('luasnip') - cmp.setup({ - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - - mapping = { - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.confirm({ select = true }) - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - }, - - sources = { - { name = 'nvim_lsp' }, - { name = 'buffer' }, - }, - }) - require('cmp').setup.cmdline(':', { - sources = { - { name = 'cmdline' }, - }, - }) - require('cmp').setup.cmdline('/', { - sources = { - { name = 'buffer' }, - }, - }) - end, - }) - end, - config = { - package_root = package_root, - compile_path = install_path .. '/plugin/packer_compiled.lua', - }, - }) -end - -if vim.fn.isdirectory(install_path) == 0 then - vim.fn.system({ - 'git', - 'clone', - 'https://github.com/wbthomason/packer.nvim', - install_path, - }) - load_plugins() - require('packer').sync() - vim.cmd('colorscheme aurora') -else - load_plugins() - vim.cmd('colorscheme aurora') -end diff --git a/tests/call_hierarchy_spec.lua b/tests/call_hierarchy_spec.lua index 1a64170..6d7e7fc 100644 --- a/tests/call_hierarchy_spec.lua +++ b/tests/call_hierarchy_spec.lua @@ -30,7 +30,7 @@ describe('should run lsp call hierarchy', function() for _ = 1, 20 do vim.wait(400, function() end) local found = false - for _, client in ipairs(vim.lsp.get_active_clients()) do + for _, client in ipairs(vim.lsp.get_clients()) do if client.name == 'gopls' then found = true break diff --git a/tests/reference_spec.lua b/tests/reference_spec.lua index 2dd1b63..1c71fe4 100644 --- a/tests/reference_spec.lua +++ b/tests/reference_spec.lua @@ -75,7 +75,7 @@ describe('should run lsp reference', function() for _ = 1, 20 do vim.wait(400, function() end) local found = false - for _, client in ipairs(vim.lsp.get_active_clients()) do + for _, client in ipairs(vim.lsp.get_clients()) do if client.name == 'gopls' then found = true break diff --git a/tests/treesitter_spec.lua b/tests/treesitter_spec.lua index 81e805e..f632497 100644 --- a/tests/treesitter_spec.lua +++ b/tests/treesitter_spec.lua @@ -200,7 +200,7 @@ describe('should run lsp reference', function() -- allow gopls start for i = 1, 10 do vim.wait(400, function() end) - local clients = vim.lsp.get_active_clients() + local clients = vim.lsp.get_clients() print('lsp clients: ', #clients) if #clients > 0 then break