clangd

The details below describe how to install and configure the clangd language server.

Installing the Language Server

Details regarding the clangd server can be found here with instruction on downloading and installing the server found here. Another option is downloading the GitHub stable release found here.
In this case, the clangd-windows-18.1.3.zip package was download from the GitHub stable releases page and the installation was as simple as unzipping the files into the following directory:
c:\clangd\clangd_18.1.3
With the software installed test the installation by running clangd.exe -help at the command line prompt, which should result in the following output:
OVERVIEW: clangd is a language server that provides IDE-like features to editors.

It should be used via an editor plugin rather than invoked directly. For more information, see:
        https://clang.llvm.org/extra/clangd.html
        https://microsoft.github.io/language-server-protocol/
USAGE: clangd.exe [options]

OPTIONS:

Color Options:

  -color                         - Use colors in output (default=autodetect)

General options:

  -all-scopes-completion         - If set to true, code completion will include index symbols that are not defined in the scopes (e.g. namespaces) visible
                                    from the code completion point. Such completions can insert scope qualifiers.
  -compile-commands-dir=<string> - Specify a path to look for compile_commands.json. If path is invalid, clangd will look in the current directory and parent
                                    paths of each source file.
  -completion-style              - Granularity of code completion suggestions
    =detailed                    -   One completion item for each semantically distinct completion, with full type information.
    =bundled                     -   Similar completion items (e.g. function overloads) are combined. Type information shown where possible.
  -function-arg-placeholders     - When disabled, completions contain only parentheses for function calls. When enabled, completions also contain
                                    placeholders for method parameters.
  -header-insertion-decorators   - Prepend a circular dot or space before the completion label, depending on whether an include line will be inserted or not.
  -input-style                   - Input JSON stream encoding
    =standard                    -   usual LSP protocol
    =delimited                   -   messages delimited by --- lines, with # comment support
  -j=<uint>                      - Number of async workers used by clangd
  -limit-results=<int>           - Limit the number of results returned by clangd. 0 means no limit.
  -log                           - Verbosity of log messages written to stderr
    =error                       -   Error messages only
    =info                        -   High level execution tracing
    =verbose                     -   Low level details
  -pch-storage                   - Storing PCHs in memory increases memory usages, but may improve performance
    =disk                        -   store PCHs on disk
    =memory                      -   store PCHs in memory
  -pretty                        - Pretty-print JSON output

Generic Options:

  -help                          - Display available options (-help-hidden for more)
  -help-list                     - Display list of available options (-help-list-hidden for more)
  -version                       - Display the version of this program
If that output is not produced check the installation and also check to make sure the executuble installation folder has been added to the system PATH environment variable.

Configuration

Start Zeus and use the Options, Document Types menu to edit the C/C++ document type and in the Language Server panel apply the following configuration settings:
Program Type: Executable
     Program: c:\clangd\clangd_18.1.3\bin\clangd.exe
NOTE: In the example above the clangd.exe was fully qualified. The executable directory can be omitted provided the executable folder is found in the system PATH environment variable.

JSON Compilation Database Format Specification

The clangd tool uses a JSON Compilation Database file to describe the files that make up the project. More details on the specification of this file and tools that can be used to create this file can be found here.
The resulting compile_commands.json database file should be placed in the root folder location, which if left blank defaults to the directory of the currently open workspace.
NOTE: Zeus provides a compile_commands_json.py macro which can create a poor man's version of this datbase file. The macro creates the file using details found in the Zeus workspace. While the resulting database file does work to some extent, better results can be achieved by using a database file created with a tool designed to create these files, for example CMake.
To use the macro open a Zeus workspace, open a file from that workspace and use the Macros, Tools, Create compile_commands.json file menu to create the file.

Using the Language Server

To test the configuration create a simple test.cpp file and fire off an auto-complete request:
lsp clangd

If the following output is display in the Language Server output window it means the clangd.exe executable has not been installed correctly or the executable folder is not location in the system PATH environment variable.
Error: Cannot launch process: clangd.exe


Latest Version: Zeus 3.99b
Released: 29th January 2024