Conan & CMake & VSCode ClangD: goto definition works, but goto implementation not (and impl docs not available)

52 Views Asked by At

Problem

I installed ftxui into my CMake managed project using canon, and I'm using vscode-clangd (I'll call it clangd) as the LSP. However, I found that clangd provided "hover to view document" to be "not useful" and go to implementation "founds none".

After some research I found that the author of ftxui split their source code into hpp (declaration) and cpp (implementation) files, but the actual docs are written in the cpp files. And conan stores them in different locations: cpps are under ~/.conan2/p/b/ftxuif8e789ccd8656/b/src/src/ftxui and hpps are under ~/.conan2/p/b/ftxuif8e789ccd8656/b/src/include/ftxui. However, clangd used ~/.conan2/p/b/ftxuif8e789ccd8656/p/include/ftxui to provide docs and completions and all I found under this dir are hpps. But I noticed that ~/.conan2/p/b/ftxuif8e789ccd8656/p/lib stores some compiled libraries with .a as their file extension.

I assumed the string after ftxui to be hash, because I downloaded the library several times and found several different dirs with same prefix.

Expectation

I would like clangd to provide the actual documentation written in the cpp files when I hover over an item, and it being able to perform "go to implementation". Or, if this it not possible, understand why and knows where to open an issue (or accept the fact).

Supplementary

As far as I know, clangd uses the compile_commands.json generated by CMake to provide IntelliSense, do I need to set some CMake build flags?

Misc

I'm unsure if this is a problem of mine, or clangd (or vscode-clangd), or conan, or the library author. So any guidance, help and clarification would be greatly appreciated.

1

There are 1 best solutions below

0
HighCommander4 On

Two things would be needed to get this to work:

  1. Clangd needs to know where the source files of the library are. This basically means, the compile_commands.json file for your project needs to have entries for files such as, for example, ftxui/src/ftxui/dom /linear_gradient.cpp. This probably doesn't happen by default, but you could make it happen with a bit of work:

    • Use ftxui's own build system to generate a compile_commands.json for the ftxui sources.
    • Use a json manipulation tool like jq to merge ftxui's compile_commands.json into your project's compile_commands.json (or just copy the entries from one to the other manually).
  2. Clangd needs to show hover information from comments in implementation files. This is currently a missing feature of clangd, however there is an open PR for it: https://github.com/llvm/llvm-project/pull/67802. So it could get this feature soon.