Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports TextDocumentContentChangeEvent#getRangeLength with null value #1696

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void update(List<TextDocumentContentChangeEvent> changes) {
int length = 0;

if (range != null) {
length = changeEvent.getRangeLength().intValue();
length = offsetAt(range.getEnd()) - offsetAt(range.getStart());
jmatss marked this conversation as resolved.
Show resolved Hide resolved
} else {
// range is optional and if not given, the whole file content is replaced
length = buffer.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,55 @@ public void testChangeReplaceRange() {
assertEquals(expectedText, document.getText());
}

@Test
public void testRangeLengthCalculatedFromRange() {
String text = "<aaa>\r\n" + //
" <b/>\r\n" + //
"</aaa>\r\n";

String expectedText = "<aaa/>\r\n";

TextDocument document = new TextDocument(text, "uri");
document.setIncremental(true);

Range range1 = new Range(new Position(0, 4), new Position(2, 5));
TextDocumentContentChangeEvent change1 = new TextDocumentContentChangeEvent(range1, 123456, "/");

ArrayList<TextDocumentContentChangeEvent> changes = new ArrayList<>();
changes.add(change1);

document.update(changes);

assertEquals(expectedText, document.getText());
}

// https://github.com/eclipse-lemminx/lemminx/issues/1674
@Test
public void testDeprecatedRangeLengthAllowsNull() {
String text = "<zzz>\r\n" + // /// <-- inserting 'a' in tag name
" <b>\r\n" + //
" </b>\r\n" + //
"</aaa>\r\n";

String expectedText = "<aaa>\r\n" + // /// <-- inserted 'a' in tag name
" <b>\r\n" + //
" </b>\r\n" + //
"</aaa>\r\n";

TextDocument document = new TextDocument(text, "uri");
document.setIncremental(true);

Range range1 = new Range(new Position(0, 1), new Position(0, 4));
TextDocumentContentChangeEvent change1 = new TextDocumentContentChangeEvent(range1, null, "aaa");

ArrayList<TextDocumentContentChangeEvent> changes = new ArrayList<>();
changes.add(change1);

document.update(changes);

assertEquals(expectedText, document.getText());
}

@Test
public void testBasicChangeMultipleChanges() {
String text = "<>\r\n" + // // <-- inserting 'a' in tag name
Expand Down