File tree Expand file tree Collapse file tree 3 files changed +20
-10
lines changed
Tests/SwiftDiagnosticsTest Expand file tree Collapse file tree 3 files changed +20
-10
lines changed Original file line number Diff line number Diff line change 1
1
# Swift Syntax 511 Release Notes
2
2
3
3
## 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
4
13
5
14
## API Behavior Changes
6
15
Original file line number Diff line number Diff line change @@ -47,11 +47,12 @@ public struct FixIt {
47
47
}
48
48
}
49
49
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 ] {
52
53
var existingEdits = [ SourceEdit] ( )
53
54
for change in changes {
54
- let edit = SourceEdit . edit ( from : change )
55
+ let edit = change . edit
55
56
let isOverlapping = existingEdits. contains { edit. range. overlaps ( $0. range) }
56
57
if !isOverlapping {
57
58
// The edit overlaps with the previous edit. We can't apply both
@@ -64,9 +65,9 @@ public extension FixIt {
64
65
}
65
66
}
66
67
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 {
70
71
case . replace( let oldNode, let newNode) :
71
72
return SourceEdit (
72
73
range: oldNode. position..< oldNode. endPosition,
Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ import _SwiftSyntaxTestSupport
18
18
19
19
final class FixItTests : XCTestCase {
20
20
func testEditsForFixIt( ) throws {
21
- let markedSource = " protocol 0️⃣Multi 1️⃣ident 2️⃣ {} "
21
+ let markedSource = " protocol 1️⃣Multi 2️⃣ident 3️⃣ {} "
22
22
let ( markers, source) = extractMarkers ( markedSource)
23
- let positions = [ " 0️⃣ " , " 1️⃣ " , " 2️⃣ " ] . compactMap { markers [ $0 ] }
23
+ let positions = markers . mapValues { AbsolutePosition ( utf8Offset : $0 ) }
24
24
XCTAssertEqual ( positions. count, 3 )
25
25
26
26
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: " " )
29
29
]
30
30
let tree = Parser . parse ( source: source)
31
31
let diags = ParseDiagnosticsGenerator . diagnostics ( for: tree)
You can’t perform that action at this time.
0 commit comments