This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix highlighting for implicit ObjC property refs
ClosedPublic

Authored by dgoldman on Jun 11 2021, 7:21 AM.

Details

Summary

Objective-C lets you use the self.prop syntax as sugar for both
[self prop] and [self setProp:], but clangd previously did not
provide a semantic token for prop.

Now, we provide a semantic token, treating it like a normal property
except it's backed by a ObjCMethodDecl instead of a
ObjCPropertyDecl.

Diff Detail

Event Timeline

dgoldman created this revision.Jun 11 2021, 7:21 AM
dgoldman requested review of this revision.Jun 11 2021, 7:21 AM
kadircet added inline comments.Jun 22 2021, 11:14 PM
clang-tools-extra/clangd/SemanticHighlighting.cpp
579

is there any difference to using one or the other ? (i.e. can setter be static while getter isn't? I suppose not). maybe mention that in the comment and say that we are choosing whichever exists (and change the logic below to if followed by an else if?

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
699

we have an explicit @property here, but comments in the implementation says otherwise. did you mean not having any explicit getter/setter or @synthesize statement ?

Drive by from vacation, sorry - can this be tackled "upstream" in findExplicitReferences rather than special cased in syntax highlighting?

That would help with xrefs, rename etc. Features should really be only handled here if they're somehow not a simple token->decl reference, but this seems to be.

Drive by from vacation, sorry - can this be tackled "upstream" in findExplicitReferences rather than special cased in syntax highlighting?

That would help with xrefs, rename etc. Features should really be only handled here if they're somehow not a simple token->decl reference, but this seems to be.

There's a couple of problems with that at the moment:

  • Currently all ObjC method handling is done here since ObjC has selectors which need to be special cased
  • FindExplicitRefs right now resolves these down to their ObjCMethodDecls, losing syntactic information that they were referenced by property expressions and not method expressions. We'd have to store that somehow to note these as Field and not Method.
clang-tools-extra/clangd/SemanticHighlighting.cpp
579

Not like that - but it's technically possible you could have a getter in an SDK and a user-provided setter for it (but that would be really weird); both of them can exist.

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
699

After some testing it seems like property refs to class properties always use the implicit form like ObjCPropertyRefExpr 0x7f87cb8116f0 <col:11, col:15> '<pseudo-object type>' lvalue objcproperty Kind=MethodRef Getter="sharedInstance" Setter="(null)" Messaging=Getter

dgoldman updated this revision to Diff 353987.Jun 23 2021, 8:10 AM

Minor comment fixes

dgoldman marked 2 inline comments as done.Jun 23 2021, 8:10 AM
dgoldman updated this revision to Diff 355035.Jun 28 2021, 2:03 PM

Fix clang-tidy warning

sammccall accepted this revision.Jun 29 2021, 8:01 AM
This revision is now accepted and ready to land.Jun 29 2021, 8:01 AM