Skip to content

Commit b38cb8a

Browse files
committed
Update unit tests to align the convention and update release noten
Finetune the code Update release note
1 parent 83aeca0 commit b38cb8a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Release Notes/511.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Swift Syntax 511 Release Notes
22

33
## New APIs
4+
- FixIt now has a new computed propery named edits
5+
- Description: the edits represent the non-overlapping textual edits that need to be performed when the Fix-It is applied.
6+
- Issue: https://github.com/apple/sourcekit-lsp/issues/909
7+
- Pull Request: https://github.com/apple/swift-syntax/pull/2314
8+
9+
- SourceEdit
10+
- Description: SourceEdit has been moved from SwiftRefactor to SwiftSyntax
11+
- Issue: https://github.com/apple/sourcekit-lsp/issues/909
12+
- Pull Request: https://github.com/apple/swift-syntax/pull/2314
413

514
## API Behavior Changes
615

Sources/SwiftDiagnostics/FixIt.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ public struct FixIt {
4747
}
4848
}
4949

50-
public extension FixIt {
51-
var edits: [SourceEdit] {
50+
extension FixIt {
51+
/// The edits represent the non-overlapping textual edits that need to be performed when the Fix-It is applied.
52+
public var edits: [SourceEdit] {
5253
var existingEdits = [SourceEdit]()
5354
for change in changes {
54-
let edit = SourceEdit.edit(from: change)
55+
let edit = change.edit
5556
let isOverlapping = existingEdits.contains { edit.range.overlaps($0.range) }
5657
if !isOverlapping {
5758
// The edit overlaps with the previous edit. We can't apply both
@@ -64,9 +65,9 @@ public extension FixIt {
6465
}
6566
}
6667

67-
private extension SourceEdit {
68-
static func edit(from change: FixIt.Change) -> SourceEdit {
69-
switch change {
68+
private extension FixIt.Change {
69+
var edit: SourceEdit {
70+
switch self {
7071
case .replace(let oldNode, let newNode):
7172
return SourceEdit(
7273
range: oldNode.position..<oldNode.endPosition,

Tests/SwiftDiagnosticsTest/FixItTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import _SwiftSyntaxTestSupport
1818

1919
final class FixItTests: XCTestCase {
2020
func testEditsForFixIt() throws {
21-
let markedSource = "protocol 0️⃣Multi 1️⃣ident 2️⃣{}"
21+
let markedSource = "protocol 1️⃣Multi 2️⃣ident 3️⃣{}"
2222
let (markers, source) = extractMarkers(markedSource)
23-
let positions = ["0️⃣", "1️⃣", "2️⃣"].compactMap { markers[$0] }
23+
let positions = markers.mapValues { AbsolutePosition(utf8Offset: $0) }
2424
XCTAssertEqual(positions.count, 3)
2525

2626
let expectedEdits = [
27-
SourceEdit(range: AbsolutePosition(utf8Offset: positions[0]) ..< AbsolutePosition(utf8Offset: positions[1]), replacement: "Multiident "),
28-
SourceEdit(range: AbsolutePosition(utf8Offset: positions[1]) ..< AbsolutePosition(utf8Offset: positions[2]), replacement: "")
27+
SourceEdit(range: positions["1️⃣"]! ..< positions["2️⃣"]!, replacement: "Multiident "),
28+
SourceEdit(range: positions["2️⃣"]! ..< positions["3️⃣"]!, replacement: "")
2929
]
3030
let tree = Parser.parse(source: source)
3131
let diags = ParseDiagnosticsGenerator.diagnostics(for: tree)

0 commit comments

Comments
 (0)