Skip to content

Support rename across Swift files #993

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
merged 6 commits into from
Dec 15, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Dec 9, 2023

Best reviewed commit by commit.

  • Refactor rename to support index-based discovery of rename locations
    • Just shuffling code around and renaming a few variables. No functionality change
  • Support rename across Swift files
    • Actually implement global rename
  • Address stylistic review comments from Implement local rename within the current file #990
  • Increase test coverage of rename
  • Allow rename when the new name is missing the ) or if it has text after )

rdar://118995700

@ahoppen ahoppen requested a review from benlangmuir as a code owner December 9, 2023 00:44
@ahoppen ahoppen force-pushed the ahoppen/global-rename branch from acf3c74 to b8379d9 Compare December 9, 2023 00:48
@ahoppen
Copy link
Member Author

ahoppen commented Dec 9, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 9, 2023

@swift-ci Please test Windows

@ahoppen ahoppen force-pushed the ahoppen/global-rename branch from b8379d9 to 3d7c405 Compare December 9, 2023 16:36
@ahoppen
Copy link
Member Author

ahoppen commented Dec 9, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 9, 2023

@swift-ci Please test Windows

@ahoppen ahoppen changed the title Support rename across Swift files 🚥 #990 Support rename across Swift files Dec 12, 2023
@ahoppen ahoppen force-pushed the ahoppen/global-rename branch from 105adb9 to 7e3ffe5 Compare December 12, 2023 16:56
@ahoppen
Copy link
Member Author

ahoppen commented Dec 12, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 12, 2023

@swift-ci Please test Windows

Comment on lines +319 to +305
if edits.changes == nil {
// Make sure `edits.changes` is non-nil so we can force-unwrap it below.
edits.changes = [:]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, is there a meaningful difference between changes being nil and empty? Wondering why it needs to be optional in the first place

Copy link
Member Author

Choose a reason for hiding this comment

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

Effectively, there’s no difference AFAICT. It’s LSP that specifies that changes can be nil. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEdit

@ahoppen ahoppen force-pushed the ahoppen/global-rename branch from 7e3ffe5 to 215200d Compare December 12, 2023 23:35
@ahoppen
Copy link
Member Author

ahoppen commented Dec 12, 2023

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/global-rename branch from 215200d to e08f0a9 Compare December 13, 2023 22:37
@ahoppen
Copy link
Member Author

ahoppen commented Dec 13, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 13, 2023

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Dec 14, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit ca8805a into swiftlang:main Dec 15, 2023
@ahoppen ahoppen deleted the ahoppen/global-rename branch December 15, 2023 01:13
Comment on lines +97 to +98
2️⃣foo(x: 1)
_ = 3️⃣foo(x:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could check the argument locations here too

Copy link
Member Author

Choose a reason for hiding this comment

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

Renaming the argument labels currently isn’t supported. I filed rdar://119875277 to implement it in a follow-up PR because it might require some non-trivial refactoring.

let response = try await ws.testClient.send(
RenameRequest(textDocument: TextDocumentIdentifier(aUri), position: aPositions["1️⃣"], newName: "bar")
)
let changes = try XCTUnwrap(response?.changes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just apply the edits as in the single file rename? Or if not that, at least have a helper for creating a TextEdit from a file + name + two markers?

ahoppen added a commit that referenced this pull request Jan 9, 2024
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