Add desugared type to hover when the desugared type and the pretty-printed type are different.
c++ template<typename T> struct TestHover { using Type = T; }; int main() { TestHover<int>::Type a; }
variable a
Type: TestHover<int>::Type (aka 'int')
Paths
| Differential D114522
[clangd] Add desugared type to hover ClosedPublic Authored by lh123 on Nov 24 2021, 3:21 AM.
Details Summary Add desugared type to hover when the desugared type and the pretty-printed type are different. c++ template<typename T> struct TestHover { using Type = T; }; int main() { TestHover<int>::Type a; } variable a Type: TestHover<int>::Type (aka 'int')
Diff Detail
Event TimelineHerald added subscribers: cfe-commits, MaskRay, ilya-biryukov. · View Herald TranscriptNov 24 2021, 3:21 AM Comment Actions I agree we often show the wrong amount of sugar, and with the thrust of this patch. Some pareto-improments are possible with a single type, but we can't solve this problem satisfactorily:
However I think desugaring all the way to the canonical type, and showing it whenever the strings are not exactly equal, are too blunt as policies. I'd suggest we expose that function from ASTDiagnostic.h and use it for this purpose.
lh123 retitled this revision from [clangd] Add canonical type to hover to [clangd] Add desugared type to hover. Comment Actions
lh123 changed the repository for this revision from rZORG LLVM Github Zorg to rG LLVM Github Monorepo. Comment Actions This looks pretty good in terms of behavior, some impl comments but we should land this. My main remaining concern is just that this will trigger too often when there's no confusion over types, and clutter the display.
@kadircet hopefully has thoughts on what hover should look like
Comment Actions
As discussed offline I share these concerns, and it's not the first time we're facing them. I am afraid that this might be disturbing for a good fraction of users if we don't polish it around common types.
lh123 added a child revision: D114665: [clangd] Make a.k.a printing configurable..Nov 27 2021, 4:03 AM Comment Actions Thank you! (& Sorry for the delay, have been sick) As noted below I'd suggest either disabling aka for params, or reverting to the previous version, but I don't feel strongly.
This revision is now accepted and ready to land.Dec 7 2021, 3:49 AM Comment Actions
BTW this seems hard to implement well without invasive changes to the desugar logic. Nontrivial case: the list is {std::string}, the type is std::string*. Pathological case: the list is {std::string}, and the type is pair<std::string*, size_t>. Desugar yields pair<basic_string<char>*, long long>, desired output is pair<std::string*, long long>.
Closed by commit rGec64d10340da: [clangd] Add desugared type to hover (authored by lh123). · Explain WhyDec 7 2021, 9:28 PM This revision was automatically updated to reflect the committed changes. lh123 marked 2 inline comments as done.
Revision Contents
Diff 389968 clang-tools-extra/clangd/Hover.h
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/include/clang/AST/ASTDiagnostic.hclang/lib/AST/ASTDiagnostic.cpp
|
instead of these ad-hoc pairs, I'd suggest introducing a common struct like:
that way producing function like printType and formatting functions that produce "foo (aka bar)" can more simply be shared between instances of this pattern