File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-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 {
@@ -1089,7 +1090,11 @@ extension SwiftLanguageService {
1089
1090
)
1090
1091
}
1091
1092
}
1093
+ edits = edits. filter { !$0. isNoOp ( in: snapshot) }
1092
1094
1095
+ if edits. isEmpty {
1096
+ return ( edits: WorkspaceEdit ( changes: [ : ] ) , usr: usr)
1097
+ }
1093
1098
return ( edits: WorkspaceEdit ( changes: [ snapshot. uri: edits] ) , usr: usr)
1094
1099
}
1095
1100
@@ -1451,3 +1456,13 @@ fileprivate extension RelatedIdentifiersResponse {
1451
1456
}
1452
1457
}
1453
1458
}
1459
+
1460
+ fileprivate extension TextEdit {
1461
+ /// Returns `true` the replaced text is the same as the new text
1462
+ func isNoOp( in snapshot: DocumentSnapshot ) -> Bool {
1463
+ if snapshot. text [ snapshot. indexRange ( of: range) ] == newText {
1464
+ return true
1465
+ }
1466
+ return false
1467
+ }
1468
+ }
Original file line number Diff line number Diff line change @@ -1181,4 +1181,25 @@ final class RenameTests: XCTestCase {
1181
1181
)
1182
1182
)
1183
1183
}
1184
+
1185
+ func testRenameDoesNotReportEditsIfNoActualChangeIsMade( ) async throws {
1186
+ let project = try await SwiftPMTestProject (
1187
+ files: [
1188
+ " FileA.swift " : """
1189
+ func 1️⃣foo(x: Int) {}
1190
+ """ ,
1191
+ " FileB.swift " : """
1192
+ func test() {
1193
+ foo(x: 1)
1194
+ }
1195
+ """ ,
1196
+ ] ,
1197
+ build: true
1198
+ )
1199
+ let ( uri, positions) = try project. openDocument ( " FileA.swift " )
1200
+ let result = try await project. testClient. send (
1201
+ RenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] , newName: " foo(x:) " )
1202
+ )
1203
+ XCTAssertEqual ( result? . changes, [ : ] )
1204
+ }
1184
1205
}
You can’t perform that action at this time.
0 commit comments