How should capabilities be added?
For those using nvim_cmp and cmp-nvim-lsp, it is common to notify the language server (LS) about additional client capabilities added by cmp-nvim-lsp (on top of what Neovim has built-in), so the LS sends all its completion options etc. to the client (I think that is the purpose, though I am not 100% certain).
How can such capabilities be added to typescript-tools?
Here is how it is normally done with other LSPs, inside the config function of nvim-lspconfig, if using lazy.nvim and cmp-nvim-lsp is included as a dependency.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
local server = servers[server_name] or {}
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
The typescript-tools README says:
The parameters passed into the setup function are also passed to the standard nvim-lspconfig server setup, allowing you to use the same settings here. But you can pass plugin-specific options through the settings parameter, which defaults to:
require("typescript-tools").setup {
on_attach = function() ... end,
handlers = { ... },
-- ....
settings = {
-- ....
}
}
As such I was thinking to do something like this (and making sure cmp_nvim_lsp is installed beforehand):
-- These two lines are added somewhere we have access to 'cmp_nvim_lsp'.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
require("typescript-tools").setup {
server = {
capabilities = capabilities
},
-- ....
settings = {
-- ....
}
}
What is the right way to do this? Perhaps I should not nest capabilities inside a server table.
Thank you.
+1 on this question!