-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Description
Working with Position
objects is not ideal when trying to incrementally sync documents. Additionally it is impossible to compare them with each other without an unnecessary performance hit. If you want to delay and merge events to keep the number of edits down in large documents, this becomes a basic requirement.
Consider the following TextDocumentContentChangeEvent
objects:
let first = {
text: '\r\n',
rangeLength: 0,
range: {
start: { line: 1, character: 0 }
end: { line: 1, character: 0 }
}
}
let second = {
text: 'a',
rangeLength: 0,
range: {
start: { line: 2, character: 0 }
end: { line: 2, character: 0 }
}
}
In this text document:
b
cd
Individually, they are both accurate, but since the start/end ranges have changed, the language server cannot determine the precise location of the second event without either applying the first event or parsing it to count the number of line breaks and the new character offset. Things only get worse if the changes overlap, since you would need to keep track of every newline.
All of this can be avoided if instead of the relative range location, an absolute location such as the offset into the document is provided.