1

After getting the deprecation warning from the neovim/nvim-lspconfig plugin that the require('lspconfig').setup() function was being deprecated in favor of the vim.lsp.config() and vim.lsp.enable() pattern, I tried to migrate over as suggested.

The code change worked fine, but to my surprise, I still needed to have the Plug "neovim/nvim-lspconfig" (I use vim-plug) at the top of my .vimrc/init.vim! Without it, LSP functionality was deactivated completely!

If I'm no longer calling into the lspconfig plugin at all (no more require('lspconfig') anywhere), and the vim.lsp.{enable,config} functions are both native (seems like they are based on the helpfile they show up in from e.g. :h vim.lsp.config), then

Why does LSP stop working entirely when I delete the Plug "neovim/nvim-lspconfig" line?

1 Answer 1

0

The goal of the introduction of vim.lsp.config is to provide an API to ease the configuration of the LSP servers.

If you don't have the nvim-lspconfig plugin you still need to configure your LSP server.

The new API and the underlying infrastructure make it simpler allowing a step by step retiring of the nvim-lspconfig plugin on the long run.

More information in: Simpler LSP setup and configuration

e.g.: If you add the following lines to your init.lua file the clang LSP server should be available for c and cpp files without the need of nvim-lspconfig

vim.lsp.config.clangd = { cmd = { 'clangd', '--background-index' }, root_markers = { 'compile_commands.json', 'compile_flags.txt' }, filetypes = { 'c', 'cpp' }, on_attach = function(client, bufnr) vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true, }) end, } vim.lsp.enable({'clangd'}) 

e.g.: If you add the following lines to your init.lua file the pyright LSP server should be available for python files:

vim.lsp.config.pyright = { cmd = {"pyright-langserver", "--stdio"}, filetypes = { "python" }, root_markers = { "pyproject.toml", "setup.py", "setup.cfg", "requirements.txt", "Pipfile", "pyrightconfig.json", }, settings = { python = { analysis = { autoSearchPaths = true, useLibraryCodeForTypes = true, }, }, }, on_attach = function(client, bufnr) vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true, }) end, } 

The nvim-lspconfig provides in the lsp plugin subfolder default lsp configuration for a large number of LSP server (e.g. clangd, pyright, ts_ls, ...)

4
  • 1
    the plugin downloads default configs and puts them in folders that neovim automatically looks for? Commented Nov 13 at 22:15
  • The plugin includes default config indeed. I understand that on the long run the plugin will provide the default config and make them available to Neovim (I didn't cross check the current implementation yet). I suppose backward compatibility makes that it will be progressive. Commented Nov 14 at 3:53
  • 1
    I really appreciate your time answering me, but unfortunately I feel that the correct answer to my question "why does uninstalling a seemingly unused plugin de-activate my LSP", is just "because that plugin puts default LSP configs into an lsp/ folder on your runtimepath that neovim now knows to automatically look for". Commented Nov 14 at 19:45
  • You are right :-) I'm learning with you diving into the code of nvim-lspconfig ;-) Commented Nov 15 at 9:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.