Convert Figma logo to code with AI

neovim logonvim-lspconfig

Quickstart configs for Nvim LSP

10,896
2,102
10,896
54

Top Related Projects

165,325

Visual Studio Code

34,302

:hibiscus: Minimalist Vim Plugin Manager

37,268

The official Vim repository

13,602

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

3,160

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

165,325

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
34,302

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

37,268

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,602

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,160

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

nvim-lspconfig is a "data only" repo, providing basic, default Nvim LSP client configurations for various LSP servers.

View the documentation for all configs or :help lspconfig-all from Nvim.

Important ⚠️

  • If you found a bug in the Nvim LSP functionality (:help lsp), report it to Neovim core.
    • Do not report it here. Only configuration data lives here.
  • These configs are best-effort and supported by the community. See contributions.
  • Note: This repo only provides configurations. Its programmatic API is deprecated and should not be used externally.
    • Work is planned to selectively upstream the "framework" parts (not the configs) of nvim-lspconfig, to Nvim core, and deprecate them in nvim-lspconfig.

Install

LuaRocks

  • Requires Nvim 0.9 above. Update 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 use a 3rd-party plugin manager (consult the documentation for your plugin manager).

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. Ensure your project/workspace contains a root marker which matches the server requirements specified in :help lspconfig-all.
  4. Open a code file in Nvim. LSP will attach and provide diagnostics.
    nvim main.py
    
  5. Run :checkhealth lsp to see the status or to troubleshoot.

Read :help lspconfig for details. Read :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 when calling setup().

Configuration

Nvim sets some default options and mappings when a buffer attaches to LSP (see :help lsp-config). In particular:

  • 'tagfunc'
  • 'omnifunc'
    • Enables (manual) omni mode completion with <C-X><C-O> in Insert mode. For autocompletion, an autocompletion plugin is required.
  • 'formatexpr'
    • Enables LSP formatting with gq.
  • K maps to vim.lsp.buf.hover() in Normal mode.
  • [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

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

  1. 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/Nvim 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 doc/configs.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.

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 :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 (deprecated alias to :che lspconfig) 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_or_name> ...] Stops the given server(s). Defaults to stopping all servers active on the current buffer. To force stop add ++force
  • :LspRestart [<client_id_or_name> ...] Restarts the given client(s), and attempts to reattach to all previously attached buffers.

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:

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