vscode-clangd with .inl files

Viewed 105

I know there are many questions about this but non seem to be what I need or are not clear enough. I'm using visual studio code for my c++ project. At first I was using intellisense which worked fine except for the fact that I was missing the call hierarchy. I heard that with the visual studio clangd extension you could have this call hierarchy and I indeed do have it, but now my *.inl files are not parsed: the outline tab in vs states No symbols found in document 'name.inl', if I try ctrl+click to get to a function or variable definition it just ends up at the top of the inline file.

I found this to add to clangd to recognize an *.inl file as header file, but I don't know where to find the Types.cpp file.

I also found this which says to add the files to the compile_commands.json but that also doesn't work I would say for two reasons: 1) I'm using CMAKE_EXPORT_COMPILE_COMMANDS to generate the compile_commands.json 2) there are too many *.inl files in the project to all add them manually.

I also found this which looks like the clangd extension source code but again I don't know where to find the file extension.ts

Any help for making it such that my *.inl files are recognized is highly appreciated (and please be specific since it appears I'm a nooby and do not understand much surrounding this topic).

P.S. I'm not interested in compilation that works fine, as far as I understood we are not using clangd for that but gcc via CMake.

1 Answers

While I haven't tried it, I suspect you need two different things to make this work:

  1. Get your editor to understand that .inl files should be processed by clangd (as opposed to some other language server). For vscode, that means patching the vscode-clangd client in the place you linked to.

    To do this you'd need to:

    • Check out the client's source code, which now lives at https://github.com/clangd/vscode-clangd
    • Make the code change
    • Follow the steps in the vscode-clangd project's README to build the client plugin (this will produce a .vsix file)
    • Install the locally built plugin with vscode's Extensions: Install from VSIX... command

    UPDATE: There's an easier way to do this which doesn't require patching the client:

    • Open vscode settings
    • Filter for Files: Associations
    • In the section that comes up, add an item associating *.inl with the language c++
  2. Get clangd to understand that it should process the .inl file as if it was a C++ header. This requires either modifying your compile_commands.json to contain entries for your .inl files, or patching the clangd server with the patch you linked.

    The compile_commands.json file approach is probably easier. You don't need to modify the file manually, you can post-process the file produced by CMake with a script. In particular, have a look at the CompDB tool, which is designed to add entries for header files to a compile_commands.json. It may just work out of the box for .inl files; if not, consider filing an issue with the CompDB project, asking for .inl support to be added.

    If you want to go with patching the clangd server, that requires checking out the entire LLVM project, making the change, then building using the instructions here. You can point vscode to your locally built clangd using the "clangd.path" setting.

For additional assistance, feel free to ask questions in the #clangd channel of the LLVM Discord.


If you get this to work, consider making some contributions that would allow this to work out of the box. For example, consider submitting a pull request to the vscode-clangd project with the change you had to make.

Related