This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Hover: show CalleeArgInfo for literals
ClosedPublic

Authored by tom-anders on Dec 30 2022, 2:32 AM.

Details

Summary

This is very useful when inlay hints are disabled.

Diff Detail

Event Timeline

tom-anders created this revision.Dec 30 2022, 2:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 30 2022, 2:32 AM
tom-anders requested review of this revision.Dec 30 2022, 2:32 AM
tom-anders added inline comments.Dec 30 2022, 2:36 AM
clang-tools-extra/clangd/Hover.cpp
812

(I also modified this function, so I added this forward declaration for easier review.

If this patch gets accepted, I'd move the definition up to here before landing)

831

HoverInfo::present has an assertion that the Name has to be non-empty. I'm open for other name suggestions here (Or we could of course adjust HoverInfo::present instead)

nridge added inline comments.Dec 31 2022, 1:08 AM
clang-tools-extra/clangd/Hover.cpp
782

nit: "contents" seems a bit strange now that this is no longer necessarily the entirety of the hover contents (nor is it the string literal's contents)

maybe name it addStringLiteralInfo?

827

nit: for consistency with non-literal expressions, maybe the CalleeArgInfo should come after the other contents of the hover?

831

It at least seems no worse than "expression" for other expressions.

I think the expression's value would be more useful (and despite the "not much value" comment above, I think there can be value in showing this if e.g. the expression is written as hex and the hover shows you the decimal value), but that can be left for a later change.

848

Any reason not to also add CalleeArgInfo in this branch?

I know this branch is not for literals so I'm suggesting to expand the scope of the patch, feel free to leave this for later, but conceptually I don't see why the CalleeArgInfo would be any less useful for non-literal expressions that take this branch.

tom-anders marked 4 inline comments as done.

Refactor getHoverContents to add CalleeArgInfo for all kinds of expression

tom-anders added inline comments.Dec 31 2022, 2:57 AM
clang-tools-extra/clangd/Hover.cpp
782

Changed back to the previous signature in current patch version

831

Added a FIXME for that

848

Good point, I refactored the logic here a bit, now CalleeArgInfo is added for this branch, and also the two branches above.

Do you want to add a simple test case for a non-literal expression? Something like hovering over the + in 2 + 3 should work.

Also, this is pre-existing, but I noticed that in a case like this:

void bar(int);
void func() {
  int x = 42;
  bar(x);
}

the hover for x includes a line that just says Passed -- is that useful in any way? Should we just omit the CalleeArgInfo a case like that?

Do you want to add a simple test case for a non-literal expression? Something like hovering over the + in 2 + 3 should work.

Will do!

Also, this is pre-existing, but I noticed that in a case like this:

void bar(int);
void func() {
  int x = 42;
  bar(x);
}

the hover for x includes a line that just says Passed -- is that useful in any way? Should we just omit the CalleeArgInfo a case like that?

Hmm, the thing is that if the function signature is void bar(int&), then "Passed by reference" would be useful again, so we can't just add a if (!CalleeArgInfo->Name.empty()) around the OS << "Passed "; Maybe we could instead display "Passed by value" if and only if the name is empty?

nridge added a comment.EditedJan 2 2023, 10:21 PM

Also, this is pre-existing, but I noticed that in a case like this:

void bar(int);
void func() {
  int x = 42;
  bar(x);
}

the hover for x includes a line that just says Passed -- is that useful in any way? Should we just omit the CalleeArgInfo a case like that?

Hmm, the thing is that if the function signature is void bar(int&), then "Passed by reference" would be useful again, so we can't just add a if (!CalleeArgInfo->Name.empty()) around the OS << "Passed "; Maybe we could instead display "Passed by value" if and only if the name is empty?

That sounds fine to me.

Add test for expression, improve presentation for signature with unnamed parameter

nridge accepted this revision.Jan 4 2023, 1:08 AM

Thanks!

This revision is now accepted and ready to land.Jan 4 2023, 1:08 AM