RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.14k stars 47 forks source link

Error "table index is nil" when using server that doesn't support 'textDocument/documentHighlight' #57

Closed jemag closed 3 years ago

jemag commented 3 years ago

Plugin does not seem to work with lsp configuration for terraformls language server. image

Does work properly for others, like gopls, bashls, tsserver with same configuration:

-- common attach config
local on_attach_common = function(client)
    print("LSP STARTED")
    require'completion'.on_attach(client)
    require'illuminate'.on_attach(client)
end

require'lspconfig'.tsserver.setup{
  on_attach = function(client)
  on_attach_common(client)
  end,
}

require'lspconfig'.bashls.setup{
  on_attach = function(client)
  on_attach_common(client)
  end,
}

require'lspconfig'.terraformls.setup{
  on_attach = function(client)
  on_attach_common(client)
  end,
}
jemag commented 3 years ago

Same problem with jsonls: image and same configuration as working ones again:

require'lspconfig'.jsonls.setup{
  on_attach = function(client)
  on_attach_common(client)
  end,
}

and for yamlls: image

RRethy commented 3 years ago

Unrelated, but you can use the following syntax for your config:

require'lspconfig'.gopls.setup{
  on_attach = on_attach_common
}

As for the error, those language servers don't support textDocument/documentHighlight which is the part of the LSP that vim-illuminate uses. The best I can do is improve the error message (or I might just hide the error msg) so it makes more sense, but this will mean vim-illuminate doesn't work for those language servers. You can still use normal vim-illuminate functionality (regex based highlighting) if you don't call require 'illuminate'.on_attach for those language servers.

RRethy commented 3 years ago

Turns the lsp client returns a nil bufnr when the server doesn't implement a call, now it fails silently.

jemag commented 3 years ago

Thank you for the clarification and the lua tip