Top Related Projects
Visual Studio Code
:hibiscus: Minimalist Vim Plugin Manager
The official Vim repository
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
async language server protocol plugin for vim and neovim
Language Server Protocol (LSP) support for vim and neovim.
Quick Overview
nvim-lspconfig is a collection of common configurations for Neovim's built-in LSP client. It provides out-of-the-box configurations for various language servers, making it easier for users to set up and use Language Server Protocol (LSP) features in Neovim.
Pros
- Simplifies the setup process for many popular language servers
- Regularly updated with new language server configurations
- Integrates seamlessly with Neovim's built-in LSP client
- Provides a consistent interface for configuring different language servers
Cons
- May require additional setup for some language servers
- Documentation can be overwhelming for beginners
- Some configurations may need tweaking for specific use cases
- Depends on external language servers being installed separately
Code Examples
- Basic setup for Python using pyright:
require'lspconfig'.pyright.setup{}
- Configuring TypeScript server with custom settings:
require'lspconfig'.tsserver.setup{
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
}
}
}
- Setting up Lua language server with custom runtime path:
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
require'lspconfig'.lua_ls.setup {
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
path = runtime_path,
},
diagnostics = {
globals = {'vim'},
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
},
}
Getting Started
-
Install Neovim (0.5 or later) and nvim-lspconfig:
git clone https://github.com/neovim/nvim-lspconfig.git \ ~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig
-
Add the following to your Neovim configuration file (e.g.,
init.lua
):local lspconfig = require('lspconfig') lspconfig.pyright.setup{} lspconfig.tsserver.setup{} -- Add more language servers as needed
-
Install the required language servers (e.g., pyright, tsserver) on your system.
-
Open a file in Neovim and enjoy LSP features like auto-completion, go-to-definition, and more.
Competitor Comparisons
Visual Studio Code
Pros of vscode
- More user-friendly interface, suitable for beginners and experienced developers
- Extensive marketplace with a wide range of extensions and themes
- Built-in features like debugging, Git integration, and terminal
Cons of vscode
- Heavier resource usage, potentially slower on older hardware
- Less customizable and extensible compared to Neovim's flexibility
- Steeper learning curve for advanced customization and scripting
Code comparison
nvim-lspconfig:
require'lspconfig'.pyright.setup{}
vscode:
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}
Key differences
- nvim-lspconfig is a Neovim plugin for configuring Language Server Protocol (LSP) clients, while vscode is a full-featured IDE
- nvim-lspconfig requires more manual configuration but offers greater flexibility, whereas vscode provides a more out-of-the-box experience
- vscode has a graphical interface, while nvim-lspconfig is used within a terminal-based editor (Neovim)
Use cases
- nvim-lspconfig: Ideal for developers who prefer terminal-based workflows and extensive customization
- vscode: Better suited for those who want a feature-rich IDE with minimal setup and a graphical interface
:hibiscus: Minimalist Vim Plugin Manager
Pros of vim-plug
- Simpler setup and configuration for plugin management
- Lightweight and fast, with minimal impact on Vim startup time
- Supports a wide range of Vim versions, including older ones
Cons of vim-plug
- Limited to plugin management, lacks built-in LSP configuration capabilities
- Requires manual setup for advanced features like autocompletion and diagnostics
Code comparison
vim-plug:
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'junegunn/seoul256.vim'
call plug#end()
nvim-lspconfig:
local lspconfig = require('lspconfig')
lspconfig.pyright.setup{}
lspconfig.tsserver.setup{}
Key differences
nvim-lspconfig is specifically designed for Neovim's built-in LSP client, providing easy configuration for various language servers. It offers more advanced features for code intelligence and diagnostics out of the box.
vim-plug, on the other hand, is a general-purpose plugin manager for Vim and Neovim. It simplifies the process of installing and updating plugins but doesn't provide LSP functionality directly.
While vim-plug focuses on efficient plugin management, nvim-lspconfig is tailored for enhancing Neovim's language server capabilities. Users often use both in conjunction, with vim-plug managing plugins (including LSP-related ones) and nvim-lspconfig handling LSP configurations.
The official Vim repository
Pros of vim
- Wider compatibility across different systems and environments
- Longer history and more established user base
- Simpler setup and configuration out of the box
Cons of vim
- Limited built-in language server protocol (LSP) support
- Slower development cycle for new features and improvements
- Less extensible plugin architecture compared to Neovim
Code comparison
vim:
" Basic LSP setup in vim (requires additional plugins)
let g:lsp_servers = ['pyls', 'rls']
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> <f2> <plug>(lsp-rename)
endfunction
nvim-lspconfig:
-- LSP setup in Neovim with nvim-lspconfig
require'lspconfig'.pyright.setup{}
require'lspconfig'.rust_analyzer.setup{}
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {buffer=0})
vim.keymap.set('n', '<F2>', vim.lsp.buf.rename, {buffer=0})
The nvim-lspconfig setup is more concise and integrated with Neovim's built-in LSP client, while vim requires additional plugins and more complex configuration for similar functionality.
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
Pros of ALE
- Supports both Vim and Neovim, offering broader compatibility
- Provides linting and fixing capabilities out-of-the-box for many languages
- Can work with both LSP and non-LSP tools, offering more flexibility
Cons of ALE
- May have higher performance overhead due to its broader scope
- Configuration can be more complex, especially for LSP-specific features
- Less integrated with Neovim's built-in LSP client
Code Comparison
ALE configuration example:
let g:ale_linters = {'python': ['pylint']}
let g:ale_fixers = {'python': ['black']}
let g:ale_fix_on_save = 1
nvim-lspconfig configuration example:
require'lspconfig'.pyright.setup{}
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.py",
callback = function() vim.lsp.buf.formatting_sync(nil, 1000) end,
})
Summary
ALE is a versatile plugin that works across Vim and Neovim, offering linting and fixing for various languages. It supports both LSP and non-LSP tools, providing flexibility but potentially at the cost of performance. nvim-lspconfig, on the other hand, is Neovim-specific and focuses solely on LSP integration, offering a more streamlined experience for Neovim users who primarily work with LSP-compatible languages and tools.
async language server protocol plugin for vim and neovim
Pros of vim-lsp
- Works with both Vim and Neovim, offering broader compatibility
- Supports a wider range of language servers out of the box
- Easier setup for users who prefer Vimscript over Lua
Cons of vim-lsp
- Generally slower performance compared to nvim-lspconfig
- Less active development and community support
- Lacks some advanced features available in nvim-lspconfig
Code Comparison
vim-lsp configuration:
let g:lsp_settings = {
\ 'pyls': {'workspace_config': {'pyls': {'plugins': {'pycodestyle': {'enabled': v:false}}}}}
\}
nvim-lspconfig configuration:
require'lspconfig'.pyright.setup{
settings = {
python = {
analysis = {
typeCheckingMode = "off"
}
}
}
}
Both projects aim to provide Language Server Protocol (LSP) support for Vim/Neovim, but they differ in their approach and target audience. vim-lsp is more suitable for users who prefer traditional Vim setups and want broader compatibility, while nvim-lspconfig is tailored for Neovim users who desire better performance and more advanced features. The code comparison shows that vim-lsp uses Vimscript for configuration, while nvim-lspconfig uses Lua, reflecting their different design philosophies and target environments.
Language Server Protocol (LSP) support for vim and neovim.
Pros of LanguageClient-neovim
- Supports a wider range of language servers, including those not strictly adhering to the LSP specification
- Offers more customization options for language server configurations
- Provides built-in support for non-LSP tools like diagnostic-languageserver
Cons of LanguageClient-neovim
- Less integrated with Neovim's built-in LSP client, potentially leading to compatibility issues
- Requires more manual configuration and setup compared to nvim-lspconfig
- May have slower performance due to its implementation in Python
Code Comparison
LanguageClient-neovim configuration:
let g:LanguageClient_serverCommands = {
\ 'rust': ['rustup', 'run', 'stable', 'rls'],
\ 'javascript': ['javascript-typescript-stdio'],
\ }
nvim-lspconfig configuration:
require'lspconfig'.rust_analyzer.setup{}
require'lspconfig'.tsserver.setup{}
LanguageClient-neovim offers more verbose configuration options, while nvim-lspconfig provides a simpler, more streamlined setup process. nvim-lspconfig leverages Neovim's built-in LSP client, resulting in better integration and potentially improved performance. However, LanguageClient-neovim may be more suitable for users requiring support for non-standard language servers or extensive customization options.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
nvim-lspconfig
nvim-lspconfig is a collection of LSP server configurations for the Nvim LSP client.
View all configs, or run :help lspconfig-all
from Nvim.
Important â ï¸
require('lspconfig')
(the legacy "framework" of nvim-lspconfig) is deprecated in favor of vim.lsp.config (Nvim 0.11+).- The lspconfig.lua module will be dropped. Calls to
require('lspconfig')
will show a warning, which will later become an error.
- The lspconfig.lua module will be dropped. Calls to
- nvim-lspconfig itself is NOT deprecated. It provides server-specific configs.
- The configs live in the lsp/ directory.
vim.lsp.config
automatically finds them and merges them with any locallsp/*.lua
configs defined by you or a plugin. - The old configs in lua/lspconfig/ are deprecated and will be removed.
- The configs live in the lsp/ directory.
Migration instructions
- Upgrade to Nvim 0.11+
- (Optional) Use
vim.lsp.config('â¦')
(notrequire'lspconfig'.â¦.setup{}
) to customize or define a config. - Use
vim.lsp.enable('â¦')
(notrequire'lspconfig'.â¦.setup{}
) to enable a config, so that it activates for itsfiletypes
.
Support
These configs are best-effort and supported by the community (you). See contributions.
- Ask questions on GitHub Discussions, not the issue tracker.
- If you found a bug in Nvim LSP (
:help lsp
), report it to Neovim core.- Do not report it here. Only configuration data lives here.
Install
- Requires Nvim 0.11.3+.
- Support for Nvim 0.10 will be removed. Upgrade Nvim and nvim-lspconfig before reporting an issue.
- Install nvim-lspconfig using Vim's "packages" feature:
git clone https://github.com/neovim/nvim-lspconfig ~/.config/nvim/pack/nvim/start/nvim-lspconfig
- Or with Nvim 0.12 (nightly), you can use the builtin
vim.pack
plugin manager:vim.pack.add{ { src = 'https://github.com/neovim/nvim-lspconfig' }, }
- Or use a 3rd-party plugin manager.
Quickstart
- Install a language server, e.g. pyright
npm i -g pyright
- Enable its config in your init.lua (:help lsp-quickstart).
vim.lsp.enable('pyright')
- Ensure your project/workspace contains a root marker as specified in
:help lspconfig-all
. - Open a code file in Nvim. LSP will attach and provide diagnostics.
nvim main.py
- Run
:checkhealth vim.lsp
to see the status or to troubleshoot.
See :help lspconfig-all
for the full list of server-specific details. For
servers not on your $PATH
(e.g., jdtls
, elixirls
), you must manually set
the cmd
parameter:
vim.lsp.config('jdtls', {
cmd = { '/path/to/jdtls' },
})
Configuration
Nvim sets default options and mappings when LSP is active in a buffer:
To customize, see:
Extra settings can be specified for each LSP server. With Nvim 0.11+ you can
extend a config by calling
vim.lsp.config('â¦', {â¦})
. (You can also copy any config directly from
lsp/
and put it in a local lsp/
directory in your 'runtimepath').
vim.lsp.config('rust_analyzer', {
-- Server-specific settings. See `:help lsp-quickstart`
settings = {
['rust-analyzer'] = {},
},
})
Create a new config
To create a new config you can either (1) use vim.lsp.config
or (2) create
a file lsp/<config-name>.lua
somewhere on your 'runtimepath'.
Example: define a new config as code
- Run
:lua vim.lsp.config('foo', {cmd={'true'}})
- Run
:lua vim.lsp.enable('foo')
- Run
:checkhealth vim.lsp
, the new config is listed under "Enabled Configurations". ð
Example: define a new config as a file
- Create a file
lsp/foo.lua
somewhere on your 'runtimepath'.:exe 'edit' stdpath('config') .. '/lsp/foo.lua'
- Add this code to the file (or copy any of the examples from the lsp/ directory in this repo):
return { cmd = { 'true' }, }
- Save the file (with
++p
to ensure its parent directory is created).:write ++p
- Enable the config.
:lua vim.lsp.enable('foo')
- Run
:checkhealth vim.lsp
, the new config is listed under "Enabled Configurations". ð
Troubleshooting
Start with :checkhealth vim.lsp
to troubleshoot. The most common reasons a language server does not start or attach are:
-
Language server is not installed. nvim-lspconfig does not install language servers for you. You should be able to run the
cmd
defined in the config from the command line and see that the language server starts. If thecmd
is a name instead of an absolute path, ensure it is on your$PATH
. -
Missing filetype plugins. Some languages are not detected by Nvim because they have not yet been added to the filetype detection system. Ensure
:set filetype?
shows the filetype and not an empty value. -
Not triggering root detection. Some language servers require a "workspace", which is found by looking for an ancestor directory that contains a "root marker". The most common root marker is
.git/
, but each config defines other "root marker" names. Root markers/directories are listed in:help lspconfig-all
.You can also explicitly set a root instead of relying on automatic detection by enabling
'exrc'
and adding an.nvim.lua
at the desired root dir with the following code:vim.lsp.config('<client name>', { root_dir = vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h'), })
Note that prior to nvim 0.12
exrc
file is executed only if it's inside of a cwd where you startnvim
.
Bug reports
If you found a bug with LSP functionality, report it to Neovim core.
Before reporting a bug, check your logs and the output of :checkhealth vim.lsp
. Add this to your init.lua to enable verbose logging:
vim.lsp.set_log_level("debug")
Attempt to run the language server, then run :LspLog
to open the log.
Most of the time, the reason for failure is present in the logs.
Commands
:LspInfo
(alias to:checkhealth vim.lsp
) shows the status of active and configured language servers.:LspStart <config_name>
Start the requested server name. Will only successfully start if the command detects a root directory matching the current config.:LspStop [<client_id_or_name>]
Stops the given server. Defaults to stopping all servers active on the current buffer. To force stop add++force
:LspRestart [<client_id_or_name>]
Restarts the given client, and attempts to reattach to all previously attached buffers. Defaults to restarting all active servers.
Contributions
If a language server is missing from configs.md, contributing a new configuration for it helps others, especially if the server requires special setup. Follow these steps:
- Read CONTRIBUTING.md.
- Create a new file at
lsp/<server_name>.lua
.- Copy an existing config to get started. Most configs are simple. For an extensive example see texlab.lua.
- Ask questions on GitHub Discussions or in the Neovim Matrix room.
Release process
To publish a release:
- Create and push a new tag.
- After pushing the tag, a GitHub action will automatically package the plugin and publish the release to LuaRocks.
License
Copyright Neovim contributors. All rights reserved.
nvim-lspconfig is licensed under the terms of the Apache 2.0 license.
See LICENSE.md
Top Related Projects
Visual Studio Code
:hibiscus: Minimalist Vim Plugin Manager
The official Vim repository
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
async language server protocol plugin for vim and neovim
Language Server Protocol (LSP) support for vim and neovim.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot