How do you setup clangd as an lsp when using a project not built with clang?

It's giving really basic lint errors like unknown type name 'uint8_t' because it's failing to process my precompiled headers. And completion mostly doesn't work.

  • Using different toolchains for linting and compiling doesn't sound like a particularly good idea.
    – romainl
    Jun 11, 2023 at 10:54

1 Answer 1


clangd wants a compile_commands.json file. I found the Sourcetrail Extension for Visual Studio will generate compile_commands.json:

As a Clang based tool Sourcetrail supports the JSON Compilation Database format for simplified project setup. This extension enables you to generate a JSON Compilation Database from your Visual Studio projects and solutions.

Install that extension, restart visual studio, and then Sourcetrail > Create Compilation Database, then Select All, and click Create.

That cleared up a lot of my linting errors, and I sometimes get good completion results with omnifunc=lsp#complete. Sometimes I get nothing.

I think compile_commands.json needs to be regularly regenerated since it lists compilation commands for each file. I wish there was an easy way to automate this step.

I'm using several plugins for lsp and linting support:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.