Skip to content

Add offset-len version of range in TextDocumentContentChangeEvent  #2811

@mattacosta

Description

@mattacosta

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apifeature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions