This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Highlighting auto variables as the deduced type.
ClosedPublic

Authored by jvikstrom on Aug 9 2019, 12:14 AM.

Details

Summary

Done in VisitDeclaratorDecl as the AutoTypeLoc is not deduced.
Scoped to only work for variables.
auto function return values need to be handled in a special way (separate patch for that).
auto's that are in lambdas ar enot highlighted as we don't highlight their underlying type (it's a RecordDecl, but the name is not an identifier so it returns in addToken).

Diff Detail

Repository
rL LLVM

Event Timeline

jvikstrom created this revision.Aug 9 2019, 12:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2019, 12:14 AM
jvikstrom updated this revision to Diff 214319.Aug 9 2019, 12:16 AM

Finished comment.

Harbormaster completed remote builds in B36502: Diff 214319.
hokein added inline comments.Aug 9 2019, 5:46 AM
clang-tools-extra/clangd/SemanticHighlighting.cpp
153 ↗(On Diff #214319)

The heuristic using here is fragile, (it doesn't handle decltype (auto) correctly).

I'm not quite sure we really want to highlight the inner auto, it may introduce inconsistent behavior (see we have $Primitive[[decltype]]($Variable[[Form]]) in the unittest). I think we could just leave it with the default behavior here...

154 ↗(On Diff #214319)

nit: remove the debug log

161 ↗(On Diff #214319)

assert TP cannot be null, or even move the null-ptr check into this method?

jvikstrom updated this revision to Diff 214372.Aug 9 2019, 6:53 AM
jvikstrom marked 3 inline comments as done.

Address comments.

jvikstrom updated this revision to Diff 214373.Aug 9 2019, 6:54 AM

Removed ending whitespace on a line.

hokein accepted this revision.Aug 9 2019, 7:11 AM
hokein added inline comments.
clang-tools-extra/clangd/SemanticHighlighting.cpp
143 ↗(On Diff #214373)

nit: it seems clearer to me, if we write the code like:

if (!Deduced.isNull()) {
   addType(D->getTypeSpecStartLoc(), Deduced.getTypePtr());
}
This revision is now accepted and ready to land.Aug 9 2019, 7:11 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2019, 12:44 AM