Search in sources :

Example 41 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class RenameTest3 method testRenameAutoQuoteRef.

@Test
public void testRenameAutoQuoteRef() throws Exception {
    String model = "type Foo {\n" + "}\n" + "\n" + "type Bar extends Foo {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(3, 18);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("Foo", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "type");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]\n" + "    ^type [[3, 17] .. [3, 20]]\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 42 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class RenameTest3 method testRenameQuoted.

@Test
public void testRenameQuoted() throws Exception {
    String model = "type ^type {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(0, 6);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("^type", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "Foo");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]\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 43 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class PrepareRenameTest method testPrepareRenameFqn_start_ok.

@Test
public void testPrepareRenameFqn_start_ok() throws Exception {
    String model = "package foo.bar {\n" + "  type A {\n" + "    foo.bar.MyType bar\n" + "  }\n" + "  type MyType { }\n" + "}\n";
    initializeWithPrepareSupport();
    String uri = writeFile("my-type-valid.testlang", model);
    PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 12));
    Range range = languageServer.prepareRename(params).get().getLeft();
    assertEquals("MyType", new Document(0, model).getSubstring(range));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Range(org.eclipse.lsp4j.Range) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 44 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class PrepareRenameTest method testPrepareRenameFqn_end_ok.

@Test
public void testPrepareRenameFqn_end_ok() throws Exception {
    String model = "package foo.bar {\n" + "  type A {\n" + "    foo.bar.MyType bar\n" + "  }\n" + "  type MyType { }\n" + "}\n";
    initializeWithPrepareSupport();
    String uri = writeFile("my-type-valid.testlang", model);
    PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18));
    Range range = languageServer.prepareRename(params).get().getLeft();
    assertEquals("MyType", new Document(0, model).getSubstring(range));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Range(org.eclipse.lsp4j.Range) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 45 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)

Aggregations

Range (org.eclipse.lsp4j.Range)293 Test (org.junit.Test)178 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)153 Position (org.eclipse.lsp4j.Position)111 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)105 AbstractSelectionTest (org.eclipse.jdt.ls.core.internal.correction.AbstractSelectionTest)54 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)47 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)47 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)41 ArrayList (java.util.ArrayList)39 Command (org.eclipse.lsp4j.Command)34 List (java.util.List)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)31 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)30 Diagnostic (org.eclipse.lsp4j.Diagnostic)29 TextEdit (org.eclipse.lsp4j.TextEdit)29 CodeAction (org.eclipse.lsp4j.CodeAction)28 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)27 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)25 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)21