File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -817,6 +817,7 @@ extension SourceKitLSPServer {
817
817
newName: newName
818
818
)
819
819
}
820
+ edits = edits. filter { !$0. isNoOp ( in: snapshot) }
820
821
return ( uri, edits)
821
822
} . compactMap { $0 }
822
823
for (uri, editsForUri) in urisAndEdits {
@@ -1116,7 +1117,11 @@ extension SwiftLanguageService {
1116
1117
)
1117
1118
}
1118
1119
}
1120
+ edits = edits. filter { !$0. isNoOp ( in: snapshot) }
1119
1121
1122
+ if edits. isEmpty {
1123
+ return ( edits: WorkspaceEdit ( changes: [ : ] ) , usr: usr)
1124
+ }
1120
1125
return ( edits: WorkspaceEdit ( changes: [ snapshot. uri: edits] ) , usr: usr)
1121
1126
}
1122
1127
@@ -1485,3 +1490,13 @@ fileprivate extension RelatedIdentifiersResponse {
1485
1490
}
1486
1491
}
1487
1492
}
1493
+
1494
+ fileprivate extension TextEdit {
1495
+ /// Returns `true` the replaced text is the same as the new text
1496
+ func isNoOp( in snapshot: DocumentSnapshot ) -> Bool {
1497
+ if snapshot. text [ snapshot. indexRange ( of: range) ] == newText {
1498
+ return true
1499
+ }
1500
+ return false
1501
+ }
1502
+ }
Original file line number Diff line number Diff line change @@ -1236,4 +1236,26 @@ final class RenameTests: XCTestCase {
1236
1236
"""
1237
1237
)
1238
1238
}
1239
+
1240
+ func testRenameDoesNotReportEditsIfNoActualChangeIsMade( ) async throws {
1241
+ try await SkipUnless . sourcekitdSupportsRename ( )
1242
+ let project = try await SwiftPMTestProject (
1243
+ files: [
1244
+ " FileA.swift " : """
1245
+ func 1️⃣foo(x: Int) {}
1246
+ """ ,
1247
+ " FileB.swift " : """
1248
+ func test() {
1249
+ foo(x: 1)
1250
+ }
1251
+ """ ,
1252
+ ] ,
1253
+ build: true
1254
+ )
1255
+ let ( uri, positions) = try project. openDocument ( " FileA.swift " )
1256
+ let result = try await project. testClient. send (
1257
+ RenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] , newName: " foo(x:) " )
1258
+ )
1259
+ XCTAssertEqual ( result? . changes, [ : ] )
1260
+ }
1239
1261
}
You can’t perform that action at this time.
0 commit comments