Search in sources :

Example 51 with Range

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));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 52 with Range

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));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 53 with Range

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());
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 54 with Range

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());
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 55 with Range

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());
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Aggregations

Range (org.eclipse.lsp4j.Range)126 Position (org.eclipse.lsp4j.Position)59 Test (org.junit.Test)38 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)23 TextEdit (org.eclipse.lsp4j.TextEdit)23 ArrayList (java.util.ArrayList)22 List (java.util.List)17 Location (org.eclipse.lsp4j.Location)16 Document (org.eclipse.xtext.ide.server.Document)16 Diagnostic (org.eclipse.lsp4j.Diagnostic)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)13 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)12 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)12 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)9 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)9 Command (org.eclipse.lsp4j.Command)9 CompletionList (org.eclipse.lsp4j.CompletionList)9 RenameParams (org.eclipse.lsp4j.RenameParams)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)8