nvim: lsp-utils: Set capabilities

We missed setting this and it gives an error like below when using
HLS and rust-analyzer.

```bash
LSP[rust-analyzer]: Error SERVER_REQUEST_HANDLER_ERROR: "/usr/local/share/nvim/runtime/lua/vim/lsp/_watchfiles.lua:199: attempt to index field 'capabilities' (a nil value)"
```
This commit is contained in:
Sanchayan Maity 2023-05-24 12:13:00 +05:30
parent 0678e79929
commit 269382b363
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -70,12 +70,15 @@ local get_root_directory = function(root_files)
return vim.fs.dirname(path[1])
end
local default_capabilities = vim.lsp.protocol.make_client_capabilities()
function M.bashls_config()
local root_directory = vim.fn.getcwd()
return {
name = "bashls",
cmd = { 'bash-language-server', 'start' },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'sh' },
single_file_support = true,
@ -90,14 +93,6 @@ function M.bashls_config()
end
function M.clangd_config()
local default_capabilities = {
textDocument = {
completion = {
editsNearCursor = true,
},
},
offsetEncoding = { 'utf-8', 'utf-16' },
}
local root_files = { '.clangd', '.clang-tidy', '.clang-format', 'compile_commands.json', 'compile_flags.txt' }
local clangd_cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--header-insertion=never" }
local root_directory = get_root_directory(root_files)
@ -105,10 +100,10 @@ function M.clangd_config()
return {
name = "clangd",
cmd = clangd_cmd,
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'c', 'cpp' },
single_file_support = true,
capabilities = default_capabilities,
}
end
@ -120,6 +115,7 @@ function M.deno_config()
return {
cmd = { 'deno', 'lsp' },
capabilities = default_capabilities,
filetypes = file_types,
root_dir = root_directory,
init_options = {
@ -162,6 +158,7 @@ function M.gopls_config()
return {
name = "gopls",
cmd = { "gopls" },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
}
@ -174,6 +171,7 @@ function M.hls_config()
return {
name = "hls",
cmd = { 'haskell-language-server-wrapper', '--lsp' },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'haskell' },
single_file_support = true,
@ -188,6 +186,7 @@ function M.jedi_config()
return {
name = "jedi-language-server",
cmd = { "jedi-language-server" },
capabilities = default_capabilities,
filetypes = { 'python' },
root_dir = root_directory,
init_options = {
@ -213,6 +212,7 @@ function M.pursls_config()
return {
name = "purescriptls",
cmd = { 'purescript-language-server', '--stdio' },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'purescript' },
single_file_support = false,
@ -231,6 +231,7 @@ function M.ra_config()
return {
name = "rust-analyzer",
cmd = { "rust-analyzer" },
capabilities = default_capabilities,
root_dir = root_directory,
settings = {
["rust-analyzer"] = {
@ -252,6 +253,7 @@ function M.scheme_config()
return {
name = "racket-langserver",
cmd = { 'racket', '--lib', 'racket-langserver' },
capabilities = default_capabilities,
filetypes = { 'scheme', 'racket' },
root_dir = root_directory,
single_file_support = true,
@ -266,6 +268,7 @@ function M.tsserver_config()
return {
name = "tsserver",
cmd = { "typescript-language-server", "--stdio" },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = file_types,
settings = {