This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Tweak "provides" hover card when symbols have the same name
ClosedPublic

Authored by sammccall on May 16 2023, 8:30 AM.

Details

Summary

Previously for overloaded functions we'd show:

Provides: foo, bar bar bar bar

The symbol name is duplicated

==> only show unique names, since we're not displaying the signature

Commas are missing

==> fix the logic which was checking for "last element" by value
    (though after the above fix this bug is dead anyway)

While here, remove a redundant bounds check before take_front().

Diff Detail

Event Timeline

sammccall created this revision.May 16 2023, 8:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 8:30 AM
sammccall requested review of this revision.May 16 2023, 8:30 AM
VitaNuo added inline comments.May 16 2023, 8:51 AM
clang-tools-extra/clangd/Hover.cpp
1539

What will this do if Front has an even number of elements? AFAIU the message will end in a comma then, which is not desirable.

clang-tools-extra/clangd/unittests/HoverTests.cpp
3492

Why did you introduce this change? This is just a rendering test, and you seem to be feeding with input that should not be possible anymore (after this patch).

sammccall added inline comments.May 16 2023, 9:04 AM
clang-tools-extra/clangd/Hover.cpp
1539

llvm::interleave invokes the first callback for each element, and the second callback between subsequent elements. So this prints Front as a comma-separated list.
(It's very similar to the example in the llvm::interleave docs)

clang-tools-extra/clangd/unittests/HoverTests.cpp
3492

The rendering logic was incorrect: if (Sym != Front.back()) was intending to test whether this was the last element, but instead was testing if it had the same text as the last element.

After fixing that bug I realized we probably didn't ever want to include overloads separately anyway, independent of any rendering issues.

But the rendering logic should still be fixed! (render() doesn't know there are no duplicates!)
And when fixing it I think it makes sense to test it - but I don't feel strongly, I can revert the test if you prefer.

sammccall added inline comments.May 16 2023, 9:06 AM
clang-tools-extra/clangd/Hover.cpp
1539

Oh, the docs are confusing.

Given a list [a b c d] the relevant pairs are [a b];[b c];[c d]. Each one gets a comma in the middle, there are three commas.

VitaNuo accepted this revision.May 16 2023, 9:09 AM

Thank you!

clang-tools-extra/clangd/Hover.cpp
1539

Oh ok, I thought it was more basic, ie just applied the callbacks interchangeably. Thanks for the explanation!

This revision is now accepted and ready to land.May 16 2023, 9:09 AM
This revision was landed with ongoing or failed builds.May 17 2023, 11:25 AM
This revision was automatically updated to reflect the committed changes.