This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Type hints for structured bindings
ClosedPublic

Authored by nridge on Jun 20 2021, 11:18 PM.

Details

Summary

Hints are shown for the individual bindings, not the aggregate.

Diff Detail

Event Timeline

nridge created this revision.Jun 20 2021, 11:18 PM
nridge requested review of this revision.Jun 20 2021, 11:18 PM
nridge added inline comments.Jun 21 2021, 12:26 AM
clang-tools-extra/clangd/InlayHints.cpp
40

While playing around with this, it did occur to me that in some cases it's more helpful to print sugared types than canonical types, for example in a case like this:

template <typename, typename, typename>
struct SomeLongType {};

using ShortType = SomeLongType<int, float, double>;

ShortType func();

auto x = func();  // would prefer "ShortType" as hint

However, it turns out that AutoType doesn't retain the sugared type to begin with (there's a FIXME about that here), so setting PrintCanonicalTypes=true doesn't actually regress cases like this (they were already printing the canonical type).

sammccall accepted this revision.Jun 29 2021, 8:24 AM

Cool!

clang-tools-extra/clangd/InlayHints.cpp
40

This makes sense - can you add a comment with a short version of this?
// Often we'd prefer sugar types for auto, but the AST doesn't retain them anyway.

clang-tools-extra/clangd/unittests/InlayHintTests.cpp
468–469

since we have the handy assertTypeHints function, can we split this into several separate tests?
(Or one table-driven test so at least the test code + corresponding assertions are next to each other)

This revision is now accepted and ready to land.Jun 29 2021, 8:24 AM
nridge updated this revision to Diff 356418.Jul 4 2021, 6:52 PM
nridge marked 2 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Jul 4 2021, 6:54 PM
This revision was automatically updated to reflect the committed changes.