nvim-lspconfig

repository·master·Indexed 12 days ago

https://github.com/neovim/nvim-lspconfig

A collection of LSP (Language Server Protocol) configurations for the Neovim LSP client. It provides metadata such as commands, filetypes, and root markers to easily attach language servers to buffers. For Neovim 0.11+, it integrates with the built-in vim.lsp.config and vim.lsp.enable functions to customize and activate server configurations.

Tokens
45.4K
Snippets
413
Records
416
Agent score
46%

What's inside nvim-lspconfig

  1. Quickstart: Enable a language server

    master

    To get an LSP server running:

    1. Install the language server on your system (e.g., npm i -g pyright).
    2. Enable the config in your init.lua using vim.lsp.enable('server_name').
    3. Ensure your project has a valid root marker (e.g., .git/).
    4. Open a file and run :checkhealth vim.lsp to verify status.

    If the server is not in your $PATH, manually set the cmd using vim.lsp.config:

    -- Example for a server not in PATH
    vim.lsp.config('jdtls', {
      cmd = { '/path/to/jdtls' },
    })
  2. Configure atlas language server

    master

    The atlas language server supports Atlas config and schema files.

    Filetype Configuration Because Atlas uses .hcl files with specific suffixes for different databases, you should configure the filetypes in Neovim to ensure the LSP attaches correctly. You can use vim.filetype.add to map specific patterns to Atlas filetypes.

    Treesitter Integration To improve syntax highlighting, you can register Atlas filetypes as hcl in Treesitter.

    -- Configure filetypes for Atlas
    vim.filetype.add({
      filename = {
        ['atlas.hcl'] = 'atlas-config',
      },
      pattern = {
        ['.*/*.my.hcl'] = 'atlas-schema-mysql',
        ['.*/*.pg.hcl'] = 'atlas-schema-postgresql',
        ['.*/*.lt.hcl'] = 'atlas-schema-sqlite',
        ['.*/*.ch.hcl'] = 'atlas-schema-clickhouse',
        ['.*/*.ms.hcl'] = 'atlas-schema-mssql',
        ['.*/*.rs.hcl'] = 'atlas-schema-redshift',
        ['.*/*.test.hcl'] = 'atlas-test',
        ['.*/*.plan.hcl'] = 'atlas-plan',
        ['.*/*.rule.hcl'] = 'atlas-rule',
      },
    })
    
    -- Register with Treesitter for HCL highlighting
    vim.treesitter.language.register('hcl', 'atlas-config')
    -- ... repeat for other atlas filetypes
    
    -- Enable the LSP
    vim.lsp.enable('atlas')
  3. Enable the vue_ls language server

    master

    The vue_ls is the official language server for Vue. Install it via npm:

    npm install -g @vue/language-server

    Note on Vue versions: It supports Vue 3 projects by default. Vue 2 projects require additional configuration. Since v3.0.0, it no longer supports 'takeover mode'.

    Note on Hybrid Mode: It works in 'hybrid mode' managing CSS/HTML sections. For TypeScript support in .vue files, you must use vtsls with the @vue/typescript-plugin plugin.

    Default Configuration:

    • cmd: { "vue-language-server", "--stdio" }
    • filetypes: { "vue" }
    • root_markers: { "package.json" }
    vim.lsp.enable('vue_ls')
  4. Configure and use ts_ls (typescript-language-server)

    master

    Overview

    ts_ls (formerly typescript-language-server) is an LSP implementation for TypeScript that wraps tsserver. It is useful for features like ES5 support.

    Installation

    Install both typescript and typescript-language-server via npm:

    npm install -g typescript typescript-language-server

    Setup

    To configure the server, ensure a tsconfig.json or jsconfig.json exists at your project root.

    To enable the server in Neovim:

    vim.lsp.enable('ts_ls')

    Commands

    • :LspTypescriptSourceAction: Access "whole file" (source) code-actions like organizing imports or removing unused code.
    • :LspTypescriptGoToSourceDefinition: Navigate to the source definition of a symbol (jumping to the original implementation instead of type definitions).
    • editor.action.showReferences: Standard LSP reference command.
  5. Setup msbuild_project_tools_server language server

    master

    To enable the msbuild_project_tools_server, follow these steps:

    1. Install the server via the official repository.
    2. Configure the command: Since the server requires a specific DLL path, use vim.lsp.config:
      vim.lsp.config('msbuild_project_tools_server', {
        cmd = {'dotnet', '/path/to/server/MSBuildProjectTools.LanguageServer.Host.dll'}
      })
    3. Configure Filetypes: There are no built-in filetypes for MSBuild. Add aliases manually:
      vim.filetype.add({
        extension = {
          props = 'msbuild',
          tasks = 'msbuild',
          targets = 'msbuild',
        },
        pattern = {
          [ [[.*\.proj]] ] = 'msbuild',
        },
      })
    4. Optional Treesitter Integration: To get XML syntax highlighting for MSBuild files:
      vim.treesitter.language.register('xml', { 'msbuild' })
    5. Enable the LSP:
      vim.lsp.enable('msbuild_project_tools_server')
    -- Custom command configuration
    vim.lsp.config('msbuild_project_tools_server', {
      cmd = {'dotnet', '/path/to/server/MSBuildProjectTools.LanguageServer.Host.dll'}
    })
    
    -- Filetype detection
    vim.filetype.add({
      extension = {
        props = 'msbuild',
        tasks = 'msbuild',
        targets = 'msbuild',
      },
      pattern = {
        [ [[.*\.proj]] ] = 'msbuild',
      },
    })
    
    -- Enable LSP
    vim.lsp.enable('msbuild_project_tools_server')
  6. Enable veridian

    master

    To enable the Veridian SystemVerilog language server, use vim.lsp.enable('veridian').

    Installation:

    • With slang (requires C++17): cargo install --git https://github.com/vivekmalneedi/veridian.git --all-features
    • Without slang: cargo install --git https://github.com/vivekmalneedi/veridian.git

    Default Configuration:

    • cmd: { "veridian" }
    • filetypes: { "systemverilog", "verilog" }
    • root_markers: { ".git" }
    cargo install --git https://github.com/vivekmalneedi/veridian.git --all-features
    
    -- In Lua
    vim.lsp.enable('veridian')
  7. Configure and use turtle_ls

    master

    Overview

    turtle_ls provides language intelligence for W3C standard Turtle RDF syntax.

    Installation

    npm install -g turtle-language-server
    # OR
    yarn global add turtle-language-server

    Enable

    vim.lsp.enable('turtle_ls')

    Default Configuration

    • Command: node --stdio (Note: requires Node.js)
    • Filetypes: turtle, ttl
    • Root Markers: .git