diff --git a/Sources/SKTestSupport/SkipUnless.swift b/Sources/SKTestSupport/SkipUnless.swift index 11c5ab913..f8859046c 100644 --- a/Sources/SKTestSupport/SkipUnless.swift +++ b/Sources/SKTestSupport/SkipUnless.swift @@ -156,6 +156,31 @@ public actor SkipUnless { } } + /// Checks whether the sourcekitd contains a fix to rename labels of enum cases correctly + /// (https://github.com/apple/swift/pull/74241). + public static func sourcekitdCanRenameEnumCaseLabels( + file: StaticString = #filePath, + line: UInt = #line + ) async throws { + return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) { + let testClient = try await TestSourceKitLSPClient() + let uri = DocumentURI(for: .swift) + let positions = testClient.openDocument( + """ + enum MyEnum { + case 1️⃣myCase(2️⃣String) + } + """, + uri: uri + ) + + let renameResult = try await testClient.send( + RenameRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"], newName: "myCase(label:)") + ) + return renameResult?.changes == [uri: [TextEdit(range: Range(positions["2️⃣"]), newText: "label: ")]] + } + } + /// Whether clangd has support for the `workspace/indexedRename` request. public static func clangdSupportsIndexBasedRename( file: StaticString = #filePath, diff --git a/Sources/SourceKitLSP/Rename.swift b/Sources/SourceKitLSP/Rename.swift index 91df9c773..22be0e5a6 100644 --- a/Sources/SourceKitLSP/Rename.swift +++ b/Sources/SourceKitLSP/Rename.swift @@ -1003,24 +1003,6 @@ extension SwiftLanguageService { return nil } - /// Returns `true` if the given position is inside an `EnumCaseDeclSyntax`. - fileprivate func isInsideEnumCaseDecl(position: Position, snapshot: DocumentSnapshot) async -> Bool { - let syntaxTree = await syntaxTreeManager.syntaxTree(for: snapshot) - var node = Syntax(syntaxTree.token(at: snapshot.absolutePosition(of: position))) - - while let parent = node?.parent { - if parent.is(EnumCaseDeclSyntax.self) { - return true - } - if parent.is(MemberBlockItemSyntax.self) || parent.is(CodeBlockItemSyntax.self) { - // `MemberBlockItemSyntax` and `CodeBlockItemSyntax` can't be nested inside an EnumCaseDeclSyntax. Early exit. - return false - } - node = parent - } - return false - } - /// When the user requested a rename at `position` in `snapshot`, determine the position at which the rename should be /// performed internally, the USR of the symbol to rename and the range to rename that should be returned to the /// editor. @@ -1095,17 +1077,8 @@ extension SwiftLanguageService { try Task.checkCancellation() - var requestedNewName = request.newName - if let openParenIndex = requestedNewName.firstIndex(of: "("), - await isInsideEnumCaseDecl(position: renamePosition, snapshot: snapshot) - { - // We don't support renaming enum parameter labels at the moment - // (https://github.com/apple/sourcekit-lsp/issues/1228) - requestedNewName = String(requestedNewName[..