It's quite useful to be able to hover over an #include and see the full
path to the header file.
Details
- Reviewers
sammccall - Commits
- rGf9c8602b53fd: clangd: Provide hover info for include directives
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks, this is great! I think we need to hold the line a bit on keeping different hovers uniform though.
clang-tools-extra/clangd/Hover.cpp | ||
---|---|---|
928 | A HoverInfo with no name and no kind is a bit of a problem. For the markdown rendering you're bailing out with a special case, which works but makes the layout inconsistent with other hovers. It's also harder to reason about the code when many kinds of symbols take different codepaths, which is one of the reasons we'd unified it. What about making Name the basename e.g. foo.h for #include "project/foo.h" For Kind, there's no perfect Kind (using Module seems too confusing) and we can't easily extend the enum since we don't own it (we should fix this sometime...). Maybe just a FIXME there. For the full path, it would be more consistent to store this in Definition if we can. | |
clang-tools-extra/clangd/XRefs.cpp | ||
537 ↗ | (On Diff #362987) | This function is pretty simple and we don't use most of the result for hover. |
A HoverInfo with no name and no kind is a bit of a problem.
For the markdown rendering you're bailing out with a special case, which works but makes the layout inconsistent with other hovers. It's also harder to reason about the code when many kinds of symbols take different codepaths, which is one of the reasons we'd unified it.
We also have other clients of the C++ API that rely on name and preferably kind being present.
What about making Name the basename e.g. foo.h for #include "project/foo.h"
For Kind, there's no perfect Kind (using Module seems too confusing) and we can't easily extend the enum since we don't own it (we should fix this sometime...). Maybe just a FIXME there.
For the full path, it would be more consistent to store this in Definition if we can.
Only problem is Definition is a code block syntax-highlighted as C++. Quoting it will cause problems on windows (ugly escaped backslashes).
So I'd suggest adding const char* DefinitionLanguage = "cpp" to HoverInfo, and overriding it here. (And passing it through to codeBlock in present()).