Skip to content

Commit 25c4dde

Browse files
committed
Removes extension on SourceEdit since the issue was fixed in swift-syntax & updates documentations
1 parent 4ffa628 commit 25c4dde

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

Sources/SourceKitLSP/DocumentManager.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ public final class DocumentManager {
141141
/// - newVersion: The new version of the document. Must be greater than the
142142
/// latest version of the document.
143143
/// - edits: The edits to apply to the document
144-
/// - requiresUpcomingEdits: Flag to return upcoming editst. Will be
145-
/// calling ``willEditDocument`` for each edit made
146-
/// - Returns: The snapshot of the document before the edit and the snapshot
147-
/// of the document after the edit, including all edits that were made.
144+
/// - Returns: The snapshot of the document before the edit, the snapshot, and edits.
145+
/// The edits are sequential, ie. the edits are
146+
/// expected to be applied in order and later values in this array assume that
147+
/// previous edits are already applied.
148148
@discardableResult
149149
public func edit(
150150
_ uri: DocumentURI,
@@ -157,9 +157,9 @@ public final class DocumentManager {
157157
}
158158
let preEditSnapshot = document.latestSnapshot
159159

160-
var upcomingEdits: [SourceEdit] = []
160+
var sourceEdits: [SourceEdit] = []
161161
for edit in edits {
162-
upcomingEdits.append(SourceEdit(edit: edit, lineTableBeforeEdit: document.latestLineTable))
162+
sourceEdits.append(SourceEdit(edit: edit, lineTableBeforeEdit: document.latestLineTable))
163163

164164
if let range = edit.range {
165165
document.latestLineTable.replace(
@@ -179,7 +179,7 @@ public final class DocumentManager {
179179
logger.error("Document version did not increase on edit from \(document.latestVersion) to \(newVersion)")
180180
}
181181
document.latestVersion = newVersion
182-
return (preEditSnapshot, document.latestSnapshot, upcomingEdits)
182+
return (preEditSnapshot, document.latestSnapshot, sourceEdits)
183183
}
184184
}
185185

@@ -191,7 +191,6 @@ public final class DocumentManager {
191191
return document.latestSnapshot
192192
}
193193
}
194-
195194
}
196195

197196
extension DocumentManager {
@@ -214,7 +213,7 @@ extension DocumentManager {
214213
}
215214
}
216215

217-
/// Convenience wrapper for `edit(_:newVersion:edits:requiresUpcomingEdits:updateDocumentTokens:)`
216+
/// Convenience wrapper for `edit(_:newVersion:edits:updateDocumentTokens:)`
218217
/// that logs on failure.
219218
@discardableResult
220219
func edit(
@@ -231,7 +230,6 @@ extension DocumentManager {
231230
}
232231

233232
fileprivate extension SourceEdit {
234-
235233
init(edit: TextDocumentContentChangeEvent, lineTableBeforeEdit: LineTable) {
236234
if let range = edit.range {
237235
guard let offset = lineTableBeforeEdit.utf8OffsetOf(line: range.lowerBound.line, utf16Column: range.lowerBound.utf16index),
@@ -249,5 +247,4 @@ fileprivate extension SourceEdit {
249247
)
250248
}
251249
}
252-
253250
}

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ extension SwiftLanguageServer {
510510
keys.enableDiagnostics: 0,
511511
keys.syntacticOnly: 1,
512512
keys.offset: edit.range.lowerBound.utf8Offset,
513-
keys.length: edit.positiveLength,
513+
keys.length: edit.length.utf8Length,
514514
keys.sourceText: edit.replacement,
515515
])
516516
do {
@@ -524,7 +524,7 @@ extension SwiftLanguageServer {
524524
fromSequential: edits.map {
525525
IncrementalEdit(
526526
offset: $0.range.lowerBound.utf8Offset,
527-
length: $0.positiveLength,
527+
length: $0.length.utf8Length,
528528
replacementLength: $0.replacement.utf8.count
529529
)
530530
}
@@ -1107,10 +1107,3 @@ extension sourcekitd_api_uid_t {
11071107
}
11081108
}
11091109
}
1110-
1111-
extension SourceEdit {
1112-
var positiveLength: Int {
1113-
// Required since SourceEdit returns a negative length
1114-
-length.utf8Length
1115-
}
1116-
}

0 commit comments

Comments
 (0)