VidocqH / lsp-lens.nvim

Neovim plugin for displaying references and difinition infos upon functions like JB's IDEA.
MIT License
252 stars 15 forks source link

Check for required language server functionality. #18

Closed dsully closed 1 year ago

dsully commented 1 year ago

If a language server doesn't support functionality required by lps-lens.nvim many errors are emitted:

method textDocument/references is not supported by any of the servers registered for the current buffer

repeatedly.

I see that this function exists:

local function lsp_support_method(buf, method)
  for _, client in pairs(lsp.get_active_clients({ bufnr = buf })) do
    if client.supports_method(method) then
      return true
    end
  end
  return false
end

But isn't called for every client request. This will fix it:

diff --git lua/lsp-lens/lens-util.lua lua/lsp-lens/lens-util.lua
index 7814e21..ea6ae8e 100644
--- lua/lsp-lens/lens-util.lua
+++ lua/lsp-lens/lens-util.lua
@@ -173,7 +173,7 @@ local function do_request(symbols)
       finished[idx][1] = true
     end

-    if config.config.sections.definition == true then
+    if config.config.sections.definition == true and lsp_support_method(vim.api.nvim_get_current_buf(), methods[2]) then
       lsp.buf_request_all(symbols.bufnr, methods[2], params, function(definition)
         counting["definition"] = result_count(definition)
         finished[idx][2] = true
@@ -182,7 +182,7 @@ local function do_request(symbols)
       finished[idx][2] = true
     end

-    if config.config.sections.references == true then
+    if config.config.sections.references == true and lsp_support_method(vim.api.nvim_get_current_buf(), methods[3]) then
       params.context = { includeDeclaration = config.config.include_declaration }
       lsp.buf_request_all(symbols.bufnr, methods[3], params, function(reference)
         counting["reference"] = result_count(reference)
VidocqH commented 1 year ago

Should fix now, reopen if you re-encounter the bug. :)