Skip to content

[SourceKit] Update related identifiers request to serve local rename #70287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Dec 7, 2023

This augments the related identifiers request to return more information that’s needed for local rename.

In particular this is:

  • Returning the compound decl name at the requested location (e.g. foo(a:)). This is needed so we can pass it to find-syntactic-rename-ranges, which will verify that the name at any given location matches this old name
  • Add an option to also return locations of non-editable base names, like init. While we don't want to return non-editable base names for Edit-All-In-Scope, we do want to return them if the related identifiers response is used as the input for find-syntactic-rename-ranges to rename initializer argument labels.
  • Return operator results in related identifiers. I don’t see a reason why we shouldn’t include them and it’s needed to rename operators
  • Don’t handle parameter labels when renaming operators. If we do try to handle operator labels, renaming of usages of the operators fails because they don’t have labels. This just ignores parameter labels of operators for the sake of rename. I think that’s alright because the labels won’t be used anywhere but in the function signature, so little point in including them in the rename refactoring.

rdar://118994821

@ahoppen
Copy link
Member Author

ahoppen commented Dec 7, 2023

@swift-ci Please smoke test

@ahoppen ahoppen changed the title [SourceKit] Update related identifiers request to serve local rename 🚥 #70255 [SourceKit] Update related identifiers request to serve local rename Dec 7, 2023
This will allow us to get syntactic rename ranges from the locations returned by related identifiers.
@ahoppen ahoppen force-pushed the ahoppen/related-identifiers-for-rename branch from 0f45f21 to 9a8e9b7 Compare December 7, 2023 17:08
RenameLocs Locs = localRenameLocs(SrcFile, Info->VD);

std::string OldName = Locs.getLocations().front().OldName.str();
for (auto loc : Locs.getLocations()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably optimized out, but I'd surround in #ifndef NDEBUG if you want this. This would be the main case for a separate request I suppose, since ideally we wouldn't need OldName on every single returned location.

@ahoppen ahoppen force-pushed the ahoppen/related-identifiers-for-rename branch from 9a8e9b7 to bdd51c3 Compare December 7, 2023 18:35
@ahoppen
Copy link
Member Author

ahoppen commented Dec 7, 2023

@swift-ci Please smoke test

Comment on lines 2573 to 2575
for (size_t index = 0; index < ResolvedLocs.size(); ++index) {
auto RenameLoc = Locs.getLocations()[index];
auto ResolvedLoc = ResolvedLocs[index];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM has a zip in STLExtras.h. Could use llvm::zip_equal which assumes they're the same size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sweet.

…d by the related identifiers request

While we don't want to return non-editable base names for Edit-All-In-Scope, we do want to return them if the related identifiers response is used as the input for find-syntactic-rename-ranges.
This allows us to at least rename the base of operators. The labels don’t matter too much since they only occur on the function definition.
@ahoppen ahoppen force-pushed the ahoppen/related-identifiers-for-rename branch from bdd51c3 to 516836c Compare December 7, 2023 21:12
@ahoppen
Copy link
Member Author

ahoppen commented Dec 7, 2023

@swift-ci Please smoke test

Comment on lines +2574 to +2575
for (auto [RenameLoc, ResolvedLoc] :
llvm::zip_equal(Locs.getLocations(), ResolvedLocs)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about structured bindings, neat!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only found them by searching for zip_equal in the LLVM repo as well

@ahoppen
Copy link
Member Author

ahoppen commented Dec 8, 2023

@swift-ci Please smoke test macOS

@ahoppen ahoppen merged commit c7f32a3 into swiftlang:main Dec 8, 2023
@ahoppen ahoppen deleted the ahoppen/related-identifiers-for-rename branch December 8, 2023 22:55
drodriguez added a commit to drodriguez/swift that referenced this pull request Dec 15, 2023
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- swiftlang#70281 modified `ASTGen/verify-parse.swift`
- swiftlang#70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- swiftlang#70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
drodriguez added a commit to drodriguez/swift that referenced this pull request Dec 15, 2023
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- swiftlang#70281 modified `ASTGen/verify-parse.swift`
- swiftlang#70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- swiftlang#70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
drodriguez added a commit that referenced this pull request Dec 15, 2023
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- #70281 modified `ASTGen/verify-parse.swift`
- #70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- #70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Dec 21, 2023
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- swiftlang#70281 modified `ASTGen/verify-parse.swift`
- swiftlang#70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- swiftlang#70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
Catfish-Man pushed a commit to Catfish-Man/swift that referenced this pull request Jan 19, 2024
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- swiftlang#70281 modified `ASTGen/verify-parse.swift`
- swiftlang#70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- swiftlang#70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants