Highlighting on Extensionless Headers
See original GitHub issueC++ Headers without extensions aren’t automatically highlighted or processed by clangd. It’d be awesome to have clangd’s help when browsing those files. I assume this is because they aren’t seen as c-family language files by the extension and/or vscode.
More details:
- I just ran into this with Eigen, a popular linear algebra library. An example header would be “Eigen/Dense”
- Others have run into this with standard libraries in the past, since many of those headers have no extensions.
- Issues with extensionless standard library headers (e.g.
#include <iostream>
) discussed in https://github.com/clangd/clangd/issues/57. There’s great discussion there. But we can’t count on every third-party library having a magic comment at the top. - As mentioned in there, clangd-vscode.activate doesn’t fix the issue. Nor does adding the file to compile_commands.json
- However, manually telling VSCode to mark the file as C++ by clicking in the lower right does seem to fix the issue. I then see syntax highlighting and a clang error, since it’s having trouble with the relative include paths.
- Issues with extensionless standard library headers (e.g.
- It seems like there are some simple heuristics that would mostly detect correctly whether an extensionless file should be picked up by clangd: Is the file listed in compile_commands.json? Do lines start with #include or #import? A more complex heuristic would be to see if it’s included by files in the compile_commands.json, perhaps as part of a more general solution to the header issues people have been discussing in https://github.com/clangd/clangd/issues/519.
Thanks so, so much!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:8 (5 by maintainers)
Top Results From Across the Web
syntax highlighting for files without extensions - Stack Overflow
I am working an some library headers that do not have a .h or .hpp extension. Visual Studio does not give me syntax...
Read more >Forcing highlights on extensionless c++ header files? : r/neovim
Basically, was trying to look at the definition of some function with goto definition, but in c++ a lot of the standard header...
Read more >Header files with no file type? (no .h)
The reason I ask is because it seems that Visual Studio won't highlight any syntax, ... You can enable syntax highlighting for extensionless...
Read more >Syntax highlighting for extensionless files - Code::Blocks Forums
Hello, I was wondering if it's possible to associate individual extensionless files with the appropriate syntax highlighter.
Read more >https://fossies.org/linux/misc/OpenSceneGraph-Open...
Mapping extensionless header files to C++ in Visual Studio ... files which enabled syntax highlighting for OSG's extensionless headers in Visual Studio.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
VSCode has fixed this one after all, with an ML model. It’s on by default as of the August release, so I’m going to close this issue!
Their release notes, issue.
I hear ya, i-ky, and I think it’d definitely an unfortunate language convention. Happy to talk to the Eigen folks, but we’re not going to win this by modlining all the libraries, right? There have got to be lots more that copied this convention from the standard library.
It seems like an area where we’ve already implemented some heuristics. And while they don’t catch some of the cases that come up in normal usage, we’ve got the information to make things better easily. We’ve got the include paths, along with the compilation language, and we know that when the user jumps into an extensionless file via clangd it’s in that same language… (though the #include or #ifdef heuristics are probably better and more general?)
Some intel about other editors or plugins that came up in my dig through: Sounds like the Microsoft C++ plugin handles this by marking extensionless files that the user CTRL+clicks through to an extensionless file, it marks it as the right language. Platform specific-editors (Android Studio, Xcode) pick this up without modlines via some heuristic.