This is an archive of the discontinued LLVM Phabricator instance.

clangd: Provide hover info for include directives
ClosedPublic

Authored by ckandeler on Jul 30 2021, 1:18 AM.

Details

Summary

It's quite useful to be able to hover over an #include and see the full
path to the header file.

Diff Detail

Event Timeline

ckandeler created this revision.Jul 30 2021, 1:18 AM
ckandeler requested review of this revision.Jul 30 2021, 1:18 AM

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.
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()).

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.
Rather than making it public (and testing it!) and depending from hover->xrefs, can we just copy the needed bits into hover.cpp?

ckandeler updated this revision to Diff 363083.Jul 30 2021, 7:31 AM

Addressed comments.

ckandeler updated this revision to Diff 363442.Aug 2 2021, 4:39 AM

Addressed lint comments

ckandeler marked an inline comment as done.Aug 2 2021, 4:42 AM
sammccall accepted this revision.Aug 6 2021, 9:08 AM
This revision is now accepted and ready to land.Aug 6 2021, 9:08 AM

Thanks for the review. Can you please merge it? I don't have the permissions.

This revision was automatically updated to reflect the committed changes.

All done! Sorry for the delay.