@@ -128,7 +128,7 @@ public final class DocumentManager {
128
128
newVersion: Int ,
129
129
edits: [ TextDocumentContentChangeEvent ] ,
130
130
willEditDocument: ( ( _ before: DocumentSnapshot , TextDocumentContentChangeEvent ) -> Void ) ? = nil ,
131
- updateDocumentTokens: ( ( _ after: DocumentSnapshot ) -> DocumentTokens ? ) ? = nil
131
+ updateDocumentTokens: ( ( _ after: DocumentSnapshot ) -> DocumentTokens ) ? = nil
132
132
) throws -> DocumentSnapshot {
133
133
return try queue. sync {
134
134
guard let document = documents [ uri] else {
@@ -155,7 +155,7 @@ public final class DocumentManager {
155
155
let upperUtf16IndexAfterEdit = (
156
156
newLines. count == 1 ? range. lowerBound. utf16index : 0
157
157
) + newLines. last!. utf16. count
158
- let charDelta = upperUtf16IndexAfterEdit - range. upperBound. utf16index
158
+ let lastLineCharDelta = upperUtf16IndexAfterEdit - range. upperBound. utf16index
159
159
let lineDelta = newLines. count - replacedLineCount // may be negative
160
160
161
161
document. latestTokens. withMutableTokensOfEachKind { tokens in
@@ -169,7 +169,7 @@ public final class DocumentManager {
169
169
var token = $0
170
170
if token. start. line == range. upperBound. line
171
171
&& token. start. utf16index >= range. upperBound. utf16index {
172
- token. move ( lineDelta: lineDelta, utf16indexDelta: charDelta )
172
+ token. move ( lineDelta: lineDelta, utf16indexDelta: lastLineCharDelta )
173
173
} else if token. start. line > range. upperBound. line {
174
174
token. move ( lineDelta: lineDelta)
175
175
}
@@ -182,8 +182,8 @@ public final class DocumentManager {
182
182
document. latestTokens = DocumentTokens ( )
183
183
}
184
184
185
- if let f = updateDocumentTokens, let tokens = f ( document . latestSnapshot ) {
186
- document. latestTokens = tokens
185
+ if let f = updateDocumentTokens {
186
+ document. latestTokens = f ( document . latestSnapshot )
187
187
}
188
188
}
189
189
@@ -245,7 +245,7 @@ extension DocumentManager {
245
245
func edit(
246
246
_ note: DidChangeTextDocumentNotification ,
247
247
willEditDocument: ( ( _ before: DocumentSnapshot , TextDocumentContentChangeEvent ) -> Void ) ? = nil ,
248
- updateDocumentTokens: ( ( _ after: DocumentSnapshot ) -> DocumentTokens ? ) ? = nil
248
+ updateDocumentTokens: ( ( _ after: DocumentSnapshot ) -> DocumentTokens ) ? = nil
249
249
) -> DocumentSnapshot ? {
250
250
return orLog ( " failed to edit document " , level: . error) {
251
251
try edit (
0 commit comments