LLVM Discussion Forums

I want to integrate clangd with my IDE; where are the docs?

I am working on an IDE and I just discovered clangd. Sounds interesting. What do I need to do to integrate clangd with my IDE? Is there any documentation/examples/…?

Guessing from its name, I assume clangd is a daemon running in the background. How do I communicate with it?

Clangd is a language server. There’s a good overview at https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/ and a detailed protocol spec that clangd implements much of.

You integrate with it by spawning it as a subprocess and speaking LSP via stdin/stdout. (There’s also a ClangdServer C++ API, but it has no stability guarantees, and no docs beyond what you’ll find in the code)

2 Likes

It’s also worth noting that, depending on your IDE’s implementation language, there may already be LSP client libraries that do a lot of the work for you. For example, for IDE’s written in Java there is LSP4J, and for IDE’s written in Javascript/Typescript there is vscode-languageserver-node.

Is there any information about specific extension of clangd ? Like the protocol specification for passing compiler arguments via the LSP instead of compile_commands.json ?

Extensions are here: http://clangd.llvm.org/extensions.html

Possible it’s not complete, though!

1 Like