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]) return vim.fs.dirname(path[1])
end end
local default_capabilities = vim.lsp.protocol.make_client_capabilities()
function M.bashls_config() function M.bashls_config()
local root_directory = vim.fn.getcwd() local root_directory = vim.fn.getcwd()
return { return {
name = "bashls", name = "bashls",
cmd = { 'bash-language-server', 'start' }, cmd = { 'bash-language-server', 'start' },
capabilities = default_capabilities,
root_dir = root_directory, root_dir = root_directory,
filetypes = { 'sh' }, filetypes = { 'sh' },
single_file_support = true, single_file_support = true,
@ -90,14 +93,6 @@ function M.bashls_config()
end end
function M.clangd_config() 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 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 clangd_cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--header-insertion=never" }
local root_directory = get_root_directory(root_files) local root_directory = get_root_directory(root_files)
@ -105,10 +100,10 @@ function M.clangd_config()
return { return {
name = "clangd", name = "clangd",
cmd = clangd_cmd, cmd = clangd_cmd,
capabilities = default_capabilities,
root_dir = root_directory, root_dir = root_directory,
filetypes = { 'c', 'cpp' }, filetypes = { 'c', 'cpp' },
single_file_support = true, single_file_support = true,
capabilities = default_capabilities,
} }
end end
@ -120,6 +115,7 @@ function M.deno_config()
return { return {
cmd = { 'deno', 'lsp' }, cmd = { 'deno', 'lsp' },
capabilities = default_capabilities,
filetypes = file_types, filetypes = file_types,
root_dir = root_directory, root_dir = root_directory,
init_options = { init_options = {
@ -160,10 +156,11 @@ function M.gopls_config()
local root_directory = get_root_directory(root_files) local root_directory = get_root_directory(root_files)
return { return {
name = "gopls", name = "gopls",
cmd = { "gopls" }, cmd = { "gopls" },
root_dir = root_directory, capabilities = default_capabilities,
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' }, root_dir = root_directory,
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
} }
end end
@ -174,6 +171,7 @@ function M.hls_config()
return { return {
name = "hls", name = "hls",
cmd = { 'haskell-language-server-wrapper', '--lsp' }, cmd = { 'haskell-language-server-wrapper', '--lsp' },
capabilities = default_capabilities,
root_dir = root_directory, root_dir = root_directory,
filetypes = { 'haskell' }, filetypes = { 'haskell' },
single_file_support = true, single_file_support = true,
@ -186,10 +184,11 @@ function M.jedi_config()
local root_directory = get_root_directory(root_files) local root_directory = get_root_directory(root_files)
return { return {
name = "jedi-language-server", name = "jedi-language-server",
cmd = { "jedi-language-server" }, cmd = { "jedi-language-server" },
filetypes = { 'python' }, capabilities = default_capabilities,
root_dir = root_directory, filetypes = { 'python' },
root_dir = root_directory,
init_options = { init_options = {
completion = { completion = {
resolveEagerly = true, resolveEagerly = true,
@ -213,6 +212,7 @@ function M.pursls_config()
return { return {
name = "purescriptls", name = "purescriptls",
cmd = { 'purescript-language-server', '--stdio' }, cmd = { 'purescript-language-server', '--stdio' },
capabilities = default_capabilities,
root_dir = root_directory, root_dir = root_directory,
filetypes = { 'purescript' }, filetypes = { 'purescript' },
single_file_support = false, single_file_support = false,
@ -229,9 +229,10 @@ function M.ra_config()
local root_directory = get_root_directory(root_files) local root_directory = get_root_directory(root_files)
return { return {
name = "rust-analyzer", name = "rust-analyzer",
cmd = { "rust-analyzer" }, cmd = { "rust-analyzer" },
root_dir = root_directory, capabilities = default_capabilities,
root_dir = root_directory,
settings = { settings = {
["rust-analyzer"] = { ["rust-analyzer"] = {
procMacro = { procMacro = {
@ -252,6 +253,7 @@ function M.scheme_config()
return { return {
name = "racket-langserver", name = "racket-langserver",
cmd = { 'racket', '--lib', 'racket-langserver' }, cmd = { 'racket', '--lib', 'racket-langserver' },
capabilities = default_capabilities,
filetypes = { 'scheme', 'racket' }, filetypes = { 'scheme', 'racket' },
root_dir = root_directory, root_dir = root_directory,
single_file_support = true, single_file_support = true,
@ -264,10 +266,11 @@ function M.tsserver_config()
local root_directory = get_root_directory(root_files) local root_directory = get_root_directory(root_files)
return { return {
name = "tsserver", name = "tsserver",
cmd = { "typescript-language-server", "--stdio" }, cmd = { "typescript-language-server", "--stdio" },
root_dir = root_directory, capabilities = default_capabilities,
filetypes = file_types, root_dir = root_directory,
filetypes = file_types,
settings = { settings = {
typescript = { typescript = {
inlayHints = { inlayHints = {