Convert Figma logo to code with AI

neovim logonvim-lspconfig

Quickstart configs for Nvim LSP

10,302
2,041
10,302
62

Top Related Projects

162,288

Visual Studio Code

33,891

:hibiscus: Minimalist Vim Plugin Manager

36,047

The official Vim repository

13,476

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support

3,103

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

  1. Basic setup for Python using pyright:
require'lspconfig'.pyright.setup{}
  1. 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,
      }
    }
  }
}
  1. 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

  1. 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
    
  2. 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
    
  3. Install the required language servers (e.g., pyright, tsserver) on your system.

  4. Open a file in Neovim and enjoy LSP features like auto-completion, go-to-definition, and more.

Competitor Comparisons

162,288

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
33,891

: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.

36,047

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.

13,476

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.

3,103

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

nvim-lspconfig

Configs for the Nvim LSP client (:help lsp).

  • Do not file Nvim LSP client issues here. The Nvim LSP client does not live here. This is only a collection of LSP configs.
  • If you found a bug in the Nvim LSP client, report it at the Nvim core repo.
  • These configs are best-effort and supported by the community. See contributions.

See also :help lspconfig.

Install

LuaRocks

  • Requires neovim version 0.8 above. Update Nvim and nvim-lspconfig before reporting an issue.

  • Install nvim-lspconfig using builtin packages:

    git clone https://github.com/neovim/nvim-lspconfig ~/.config/nvim/pack/nvim/start/nvim-lspconfig
    
  • Alternatively, nvim-lspconfig can be installed using a 3rd party plugin manager (consult the documentation for your plugin manager for details).

Quickstart

  1. Install a language server, e.g. pyright
    npm i -g pyright
    
  2. Add the language server setup to your init.lua.
    require'lspconfig'.pyright.setup{}
    
  3. Launch Nvim, the language server will attach and provide diagnostics.
    nvim main.py
    
  4. Run :checkhealth lsp to see the status or to troubleshoot.

See server_configurations.md (:help lspconfig-all from Nvim) for the full list of configs, including installation instructions and additional, optional, customization suggestions for each language server. For servers that are not on your system path (e.g., jdtls, elixirls), you must manually add cmd to the setup parameter. Most language servers can be installed in less than a minute.

Configuration

Nvim sets some default options whenever a buffer attaches to an LSP client. See :h lsp-config for more details. In particular, the following options are set:

Nvim also maps K to vim.lsp.buf.hover() in Normal mode.

Nvim 0.10 and newer creates the following default maps unconditionally:

  • [d and ]d map to vim.diagnostic.goto_prev() and vim.diagnostic.goto_next() (respectively)
  • <C-W>d maps to vim.diagnostic.open_float()

Further customization can be achieved using the LspAttach autocommand event. The LspDetach autocommand event can be used to "cleanup" mappings if a buffer becomes detached from an LSP server. See :h LspAttach and :h LspDetach for details and examples. See :h lsp-buf for details on other LSP functions.

Additional configuration options can be provided for each LSP server by passing arguments to the setup function. See :h lspconfig-setup for details. Example:

local lspconfig = require('lspconfig')
lspconfig.rust_analyzer.setup {
  -- Server-specific settings. See `:help lspconfig-setup`
  settings = {
    ['rust-analyzer'] = {},
  },
}

Troubleshooting

If you have an issue, the first step is to reproduce with a minimal configuration.

The most common reasons a language server does not start or attach are:

  1. The language server is not installed. nvim-lspconfig does not install language servers for you. You should be able to run the cmd defined in each server's Lua module from the command line and see that the language server starts. If the cmd is an executable name instead of an absolute path to the executable, ensure it is on your path.
  2. Missing filetype plugins. Certain languages are not detecting by vim/neovim because they have not yet been added to the filetype detection system. Ensure :set ft? shows the filetype and not an empty value.
  3. Not triggering root detection. Some language servers will only start if it is opened in a directory, or child directory, containing a file which signals the root of the project. Most of the time, this is a .git folder, but each server defines the root config in the lua file. See server_configurations.md or the source for the list of root directories.
  4. You must pass capabilities for each setup {} if you want these to take effect.
  5. Do not call setup {} twice for the same server. The second call to setup {} will overwrite the first.

Before reporting a bug, check your logs and the output of :LspInfo. Add the following to your init.vim to enable logging:

vim.lsp.set_log_level("debug")

Attempt to run the language server, and open the log with:

:LspLog

Most of the time, the reason for failure is present in the logs.

Commands

  • :LspInfo 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. Pass autostart = false to your .setup{} call for a language server if you would like to launch clients solely with this command. Defaults to all servers matching current buffer filetype.
  • :LspStop <client_id> Defaults to stopping all buffer clients.
  • :LspRestart <client_id> Defaults to restarting all buffer clients.

Wiki

See the wiki for additional topics, including:

Contributions

If you are missing a language server on the list in server_configurations.md, contributing a new configuration for it helps others, especially if the server requires special setup. Follow these steps:

  1. Read CONTRIBUTING.md.
  2. Create a new file at lua/lspconfig/server_configurations/SERVER_NAME.lua.
  3. 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