This is an archive of the discontinued LLVM Phabricator instance.

[clangd][ObjC] Support ObjC class rename from implementation decls
ClosedPublic

Authored by dgoldman on Jun 12 2023, 9:11 AM.

Diff Detail

Event Timeline

dgoldman created this revision.Jun 12 2023, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 9:11 AM
Herald added a subscriber: arphaman. · View Herald Transcript
dgoldman requested review of this revision.Jun 12 2023, 9:11 AM
dgoldman updated this revision to Diff 530665.Jun 12 2023, 2:16 PM

Run clang format

dgoldman updated this revision to Diff 531439.Jun 14 2023, 11:33 AM
  • Implement discussed fixes + category support
kadircet added inline comments.Jun 16 2023, 7:04 AM
clang-tools-extra/clangd/FindTarget.cpp
719

can you also add tests for these into FindTargetTests?

720

we don't have the null check in other places, what's the significance here?

clang-tools-extra/clangd/SemanticHighlighting.cpp
131

let's do this in a separate change, with some tests

clang-tools-extra/clangd/refactor/Rename.cpp
175–181

sorry i don't follow what's the logic doing here and we're likely doing these in the wrong layer.

we should either:

  • Fix selection tree to pick the correct ASTNode, if it's picking the wrong one due to not having special cases for these locations here
  • Fix the targetDecl logic to make sure it emits all the declarations that might be referenced by this ast node, if it's missing ClassInterface.
  • Fix the canonicalRenameDecl, if we should always prefer ClassInterface in these cases.
dgoldman added inline comments.Jun 20 2023, 7:13 AM
clang-tools-extra/clangd/SemanticHighlighting.cpp
131

Given the other changes, this is needed otherwise the semantic highlighting test fails.

clang-tools-extra/clangd/refactor/Rename.cpp
175–181

Replied to you in chat, LMK what you think.

dgoldman updated this revision to Diff 533640.Jun 22 2023, 9:05 AM

Disable renaming categories

dgoldman updated this revision to Diff 533769.Jun 22 2023, 1:29 PM
dgoldman marked an inline comment as done.

Add more FindTarget tests

dgoldman marked an inline comment as done.Jun 22 2023, 1:29 PM
dgoldman added inline comments.
clang-tools-extra/clangd/FindTarget.cpp
720

Removed, doesn't look like it's needed.

kadircet added inline comments.Jun 23 2023, 1:39 AM
clang-tools-extra/clangd/refactor/Rename.cpp
173

before calling canonicalRenameDecl here we can do a D = pickInterestingTarget(D); and map it to interface decl once (we'll probably need something similar for propertydecls?), rather than canonicalizing all ObjcCategoryDecls. that way we'll still get to rename proper references that target ObjcInterfaceDecls.

297

i am afraid we're doing this at the wrong layer. the discrepancy is actually arising from the fact that findExplicitReferences will report name locations for an entity whose primary location contains a different name (e.g. @interface ^Foo (^Bar) saying that there's a reference to objccategorydecl at Bar, but canonicalizing it to Foo).

so i think what we really want is not to canonicalize objccategory(impl)decls to objcinterfacedecl, but rather pick rename target as objcinterfacedecl when the user is trying to rename a categorydecl inside locatelDeclAt (put more comments near that part of the code).

sorry for the extra round trip here :/

792

this special casing should no longer be needed if we just map CategoryDecls to InterfaceDecls in locateDeclAt rather than at canonicalization time

clang-tools-extra/clangd/unittests/FindTargetTests.cpp
2063

can you move this into a separate test case?

dgoldman updated this revision to Diff 533993.Jun 23 2023, 9:48 AM
dgoldman marked 4 inline comments as done.

Fixes for review

clang-tools-extra/clangd/refactor/Rename.cpp
792

Yep, no longer needed since the Check the rename-triggering location is actually being renamed check catches this although the error is no symbol found instead of unsupported symbol.

kadircet accepted this revision.Jun 26 2023, 6:44 AM

thanks!

clang-tools-extra/clangd/refactor/Rename.cpp
144

can you put a function level comment like:

Some AST nodes can reference multiple declarations. We try to pick the relevant one to rename here.
clang-tools-extra/clangd/unittests/RenameTests.cpp
1709

can you drop the ^ in here. we only iterate over points in the header file.

This revision is now accepted and ready to land.Jun 26 2023, 6:44 AM
dgoldman updated this revision to Diff 534618.Jun 26 2023, 9:47 AM
dgoldman marked an inline comment as done.

Fixes for review + rebase

dgoldman marked an inline comment as done.Jun 26 2023, 9:47 AM