3

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.

C. Binair
  • 419
  • 4
  • 14
  • Some years ago I decided to turn intellisense off because of numerous problems. I don't miss it. – john Jul 19 '22 at 08:28

1 Answers1

2

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.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • Thanks for your detailed comments, I'm trying your steps but so far unsuccessful. For your first point bullet 3 you say "Follow the steps in the readme to build the client plugin", but I don't see any steps in the readme to build the plugin. Can you help? – C. Binair Jul 21 '22 at 10:23
  • I wish this was just as easy as in eclipse were I could just go to Preferences>C/C++>File Types and add the *.inl as C++ Header File there. I'm starting to doubt whether vs is actually better. – C. Binair Jul 21 '22 at 10:25
  • @C.Binair My bad, the instructions are in the DEVELOPING.md document: https://github.com/clangd/vscode-clangd/blob/master/DEVELOPING.md. Also, they don't seem to mention the command to package the extension into a `.vsix` file, which is `npm run package`. – HighCommander4 Jul 21 '22 at 18:26
  • Oke I think I'm stupid. It doesn't look like I can make the change listed [here](https://github.com/llvm-mirror/clang-tools-extra/blob/fd2d6d99444e790680fbfec823f16e7a45a6d1b3/clangd/clients/clangd-vscode/src/extension.ts#L34) because the extension.ts from [here](https://github.com/clangd/vscode-clangd/blob/master/src/extension.ts) looks completely different and doesn't have that line. – C. Binair Jul 22 '22 at 07:22
  • @C.Binair You're not stupid, codebases just change over time :) In this case, it looks like the code in question was refactored in [this commit](https://github.com/clangd/vscode-clangd/commit/9e7156747e7cb4cf61e69a6dfd600128b85f6ace) to not list individual extensions, but instead rely on vscode's file associations. This means there's actually a way to solve the first part in a way that's more like Eclipse: go to vscode settings, filter for "Files: Associations", and in the section that comes up, add an item mapping `*.inl` to `c++`. – HighCommander4 Jul 22 '22 at 08:25