DidChangeTextDocument - delete line case ignores end range?

Correct me if I'm wrong here. Let's consider an example of file with 2 lines:

ABC
DEFG

now I delete newline between C and D so it looks like:

ABCDEFG

that means the character at index 3 of line index 0 is replaced with empty string. It looks like proper values for this operation (according to a discussion in https://github.com/Microsoft/language-server-protocol/issues/53) are:

{
    'range': {
        'start': {'line': 0, 'character': 3},
        'end': {'line': 1, 'character': 0}
    },
  'rangeLength': 1,
  'text': ''
}

it is less intuitive and harder to calculate.

Now... the sourcekit-lsp will accept these values:

{
    'range': {
        'start': {'line': 0, 'character': 3},
        'end': {'line': 0, 'character': 4}
    },
  'rangeLength': 1,
  'text': ''
}

and will work just fine. I'm ok with that tbh, however, the question is... is this accidental behavior or not? Some servers declare that it just ignore an end range value - it looks to me that this is the case (didn't check the sources) for sourcekit-lsp as well.

Unless the specification is amended to disallow it, I think we should accept both. If it's not already tested it should be,

On the subject of that protocol issue: we currently ignore the rangeLength and always use the range. I don't know that there is a better answer to this unless the spec allows dropping the range.end, because otherwise you have no way to know which one is wrong.

Terms of Service

Privacy Policy

Cookie Policy