Skip to content
Bonsthie edited this page Dec 30, 2024 · 1 revision

LSP Setup for Neovim

Neovim's LSP support is powerful and flexible, and this guide will help you get started with setting up LSPs in your environment. Below are the steps to install, configure, and troubleshoot LSPs.

Installing LSPs

  1. Install an LSP: While editing a file, use the command:

    :LspInstall
    

    This will install the appropriate LSP for the current file type.

  2. List available LSPs: You can see a list of available LSPs using:

    :Mason
    

Configuring Clangd for C/C++

For C and C++ development, the configuration uses the clangd language server. However, clangd requires a compile_commands.json file to function properly.

Generating compile_commands.json

The compile_commands.json file helps clangd index your project correctly. If this file is missing, you might encounter errors related to header files or other project components. Follow the steps below to generate it:

  1. Using Bear:

    • Install Bear using your package manager (e.g., apt, brew, or pacman).
    • Prepend your build command with bear. For example:
      bear -- make
      
  2. Using compiledb:

    • Install compiledb using your package manager.
    • Run your build command with compiledb. For example:
      compiledb make
      

Notes

  • If your make process fails, Bear will not generate the compile_commands.json file, as it depends on a successful build.
  • Ensure that your build system and compile_commands.json file are properly set up to allow clangd to recognize your project's structure.

Once the compile_commands.json file is generated and placed in the root directory of your project, clangd will index your project without issues.

Clone this wiki locally