use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class RenameTest2 method testRenameContainer.
@Test
public void testRenameContainer() throws Exception {
String model = "package foo\n" + "\n" + "element Foo {\n" + " element Bar {\n" + " }\n" + " ref foo.Foo.Bar\n" + " ref Foo.Bar\n" + " ref Bar\n" + "}\n";
String file = writeFile("foo/Foo.fileawaretestlanguage", model);
initialize();
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
Position position = new Position(2, 9);
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
assertEquals("Foo", new Document(0, model).getSubstring(range));
RenameParams params = new RenameParams(identifier, position, "Baz");
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
String expectation = "changes :\n" + "documentChanges : \n" + " Foo.fileawaretestlanguage <1> : Baz [[2, 8] .. [2, 11]]\n" + " Bar [[5, 5] .. [5, 16]]\n" + " Bar [[6, 5] .. [6, 12]]\n";
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class RenameTest2 method testRenameSelfRef.
@Test
public void testRenameSelfRef() throws Exception {
String model = "package foo\n" + "\n" + "element Foo {\n" + " ref Foo\n" + "}\n";
String file = writeFile("foo/Foo.fileawaretestlanguage", model);
initialize();
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
Position position = new Position(2, 9);
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
assertEquals("Foo", new Document(0, model).getSubstring(range));
RenameParams params = new RenameParams(identifier, position, "Bar");
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
String expectation = "changes :\n" + "documentChanges : \n" + " Foo.fileawaretestlanguage <1> : Bar [[2, 8] .. [2, 11]]\n" + " Bar [[3, 5] .. [3, 8]]\n";
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ValidatorTest method testDiagnosticAtEndOfLineExcludingNewline.
@Test
public void testDiagnosticAtEndOfLineExcludingNewline() {
String model = "type lowercase\n" + "{\n" + "}\n";
writeFile("MyType1.testlang", model);
initialize();
List<Diagnostic> problems = problems();
Assert.assertEquals("problems found:\n" + Joiner.on("\n").join(problems), 1, problems.size());
Diagnostic problem = Iterables.getFirst(problems, null);
assertEquals("Name should start with a capital", problem.getMessage());
Assert.assertEquals(TestLanguageValidator.INVALID_NAME, problem.getCode().get());
Range range = problem.getRange();
Assert.assertEquals(0, range.getStart().getLine());
Assert.assertEquals(5, range.getStart().getCharacter());
Assert.assertEquals(0, range.getEnd().getLine());
Assert.assertEquals(14, range.getEnd().getCharacter());
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ValidatorTest method testDiagnosticAtEndOfLineIncludingNewline.
@Test
public void testDiagnosticAtEndOfLineIncludingNewline() {
String model = "type\n";
writeFile("MyType1.testlang", model);
initialize();
List<Diagnostic> problems = problems();
Assert.assertEquals("problems found:\n" + Joiner.on("\n").join(problems), 1, problems.size());
Diagnostic problem = Iterables.getFirst(problems, null);
assertEquals("mismatched input '<EOF>' expecting RULE_ID", problem.getMessage());
Assert.assertEquals(org.eclipse.xtext.diagnostics.Diagnostic.SYNTAX_DIAGNOSTIC, problem.getCode().get());
Range range = problem.getRange();
Assert.assertEquals(0, range.getStart().getLine());
Assert.assertEquals(4, range.getStart().getCharacter());
Assert.assertEquals(1, range.getEnd().getLine());
Assert.assertEquals(0, range.getEnd().getCharacter());
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ValidatorTest method testMultilineDiagnostic_02.
@Test
public void testMultilineDiagnostic_02() {
String model = "type Multiline_Demo2 {\n" + "string sample}\n";
writeFile("MyType1.testlang", model);
initialize();
List<Diagnostic> problems = problems();
Assert.assertEquals("problems found:\n" + Joiner.on("\n").join(problems), 1, problems.size());
Diagnostic problem = Iterables.getFirst(problems, null);
assertEquals("Test Validation to mark the whole type", problem.getMessage());
Assert.assertEquals(TestLanguageValidator.MULTILINE_PROBLEM, problem.getCode().get());
Range range = problem.getRange();
Assert.assertEquals(0, range.getStart().getLine());
Assert.assertEquals(0, range.getStart().getCharacter());
Assert.assertEquals(1, range.getEnd().getLine());
Assert.assertEquals(14, range.getEnd().getCharacter());
}
Aggregations