Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should capabilities be added? #316

Open
magnusriga opened this issue Nov 27, 2024 · 0 comments
Open

How should capabilities be added? #316

magnusriga opened this issue Nov 27, 2024 · 0 comments

Comments

@magnusriga
Copy link

magnusriga commented Nov 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant