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
1 changed files with 27 additions and 24 deletions

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 = {
@ -160,10 +156,11 @@ function M.gopls_config()
local root_directory = get_root_directory(root_files)
return {
name = "gopls",
cmd = { "gopls" },
root_dir = root_directory,
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
name = "gopls",
cmd = { "gopls" },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
}
end
@ -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,
@ -186,10 +184,11 @@ function M.jedi_config()
local root_directory = get_root_directory(root_files)
return {
name = "jedi-language-server",
cmd = { "jedi-language-server" },
filetypes = { 'python' },
root_dir = root_directory,
name = "jedi-language-server",
cmd = { "jedi-language-server" },
capabilities = default_capabilities,
filetypes = { 'python' },
root_dir = root_directory,
init_options = {
completion = {
resolveEagerly = true,
@ -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,
@ -229,9 +229,10 @@ function M.ra_config()
local root_directory = get_root_directory(root_files)
return {
name = "rust-analyzer",
cmd = { "rust-analyzer" },
root_dir = root_directory,
name = "rust-analyzer",
cmd = { "rust-analyzer" },
capabilities = default_capabilities,
root_dir = root_directory,
settings = {
["rust-analyzer"] = {
procMacro = {
@ -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,
@ -264,10 +266,11 @@ function M.tsserver_config()
local root_directory = get_root_directory(root_files)
return {
name = "tsserver",
cmd = { "typescript-language-server", "--stdio" },
root_dir = root_directory,
filetypes = file_types,
name = "tsserver",
cmd = { "typescript-language-server", "--stdio" },
capabilities = default_capabilities,
root_dir = root_directory,
filetypes = file_types,
settings = {
typescript = {
inlayHints = {