@@ -106,29 +106,19 @@ private func edits(from original: DocumentSnapshot, to edited: String) -> [TextE
106
106
switch change {
107
107
case . insert( offset: let offset, element: let element, associatedWith: _) :
108
108
let absolutePosition = AbsolutePosition ( utf8Offset: offset)
109
- return IncrementalEdit ( range: absolutePosition..< absolutePosition, replacement: [ element] )
109
+ return SourceEdit ( range: absolutePosition..< absolutePosition, replacement: [ element] )
110
110
case . remove( offset: let offset, element: _, associatedWith: _) :
111
111
let absolutePosition = AbsolutePosition ( utf8Offset: offset)
112
- return IncrementalEdit ( range: absolutePosition..< absolutePosition. advanced ( by: 1 ) , replacement: [ ] )
112
+ return SourceEdit ( range: absolutePosition..< absolutePosition. advanced ( by: 1 ) , replacement: [ ] )
113
113
}
114
114
}
115
115
116
116
let concurrentEdits = ConcurrentEdits ( fromSequential: sequentialEdits)
117
117
118
118
// Map the offset-based edits to line-column based edits to be consumed by LSP
119
119
120
- return concurrentEdits. edits. compactMap { ( edit) -> TextEdit ? in
121
- let ( startLine, startColumn) = original. lineTable. lineAndUTF16ColumnOf ( utf8Offset: edit. offset)
122
- let ( endLine, endColumn) = original. lineTable. lineAndUTF16ColumnOf ( utf8Offset: edit. endOffset)
123
- guard let newText = String ( bytes: edit. replacement, encoding: . utf8) else {
124
- logger. fault ( " Failed to get String from UTF-8 bytes \( edit. replacement) " )
125
- return nil
126
- }
127
-
128
- return TextEdit (
129
- range: Position ( line: startLine, utf16index: startColumn) ..< Position ( line: endLine, utf16index: endColumn) ,
130
- newText: newText
131
- )
120
+ return concurrentEdits. edits. compactMap {
121
+ TextEdit ( range: original. absolutePositionRange ( of: $0. range) , newText: $0. replacement)
132
122
}
133
123
}
134
124
0 commit comments