Search in sources :

Example 51 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class ReferencesHandlerTest method testPotentialMatch.

// https://github.com/redhat-developer/vscode-java/issues/2227
@Test
public void testPotentialMatch() throws Exception {
    when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(true);
    importProjects("eclipse/reference");
    IProject referenceProject = WorkspaceHelper.getProject("reference");
    URI uri = referenceProject.getFile("src/org/reference/User.java").getRawLocationURI();
    String fileURI = ResourceUtils.fixURI(uri);
    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(1, 15));
    param.setContext(new ReferenceContext(true));
    param.setTextDocument(new TextDocumentIdentifier(fileURI));
    List<Location> references = handler.findReferences(param, monitor);
    assertEquals(0, references.size());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(org.eclipse.lsp4j.Location) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 52 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class ReferencesHandlerTest method testEmpty.

@Test
public void testEmpty() {
    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(1, 1));
    param.setContext(new ReferenceContext(false));
    param.setTextDocument(new TextDocumentIdentifier("/foo/bar"));
    List<Location> references = handler.findReferences(param, monitor);
    assertNotNull(references);
    assertTrue("references are not empty", references.isEmpty());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) Location(org.eclipse.lsp4j.Location) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 53 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class FindLinksHandlerTest method testFindSuperMethod.

@Test
public void testFindSuperMethod() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    // @formatter:off
    ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package test1;\n" + "\n" + "public class A {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    // @formatter:off
    ICompilationUnit unitB = pack1.createCompilationUnit("B.java", "package test1;\n" + "\n" + "public class B extends A {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    String uri = JDTUtils.toURI(unitB);
    List<? extends Location> response = FindLinksHandler.findLinks("superImplementation", new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(3, 14)), new NullProgressMonitor());
    assertTrue(response != null && response.size() == 1);
    LinkLocation location = (LinkLocation) response.get(0);
    assertEquals("test1.A.run", location.displayName);
    assertEquals("method", location.kind);
    assertEquals(JDTUtils.toURI(unitA), location.getUri());
    Range range = location.getRange();
    assertEquals(3, range.getStart().getLine());
    assertEquals(13, range.getStart().getCharacter());
    assertEquals(3, range.getEnd().getLine());
    assertEquals(16, range.getEnd().getCharacter());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) LinkLocation(org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 54 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class FormatterHandlerTest method testFormattingOnTypeNewLine.

// typing new_line should format the current line if previous character doesn't close a block
@Test
public void testFormattingOnTypeNewLine() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
    "package org.sample;\n" + "\n" + "    public      class     Baz {  \n" + // typed \n here
    "String          name       ;\n" + "}\n");
    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    // ident == 4 spaces
    FormattingOptions options = new FormattingOptions(4, true);
    DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(3, 28), "\n");
    params.setTextDocument(textDocument);
    params.setOptions(options);
    preferences.setJavaFormatOnTypeEnabled(true);
    List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
    assertNotNull(edits);
    // @formatter:off
    String expectedText = "package org.sample;\n" + "\n" + // this part won't be formatted
    "    public      class     Baz {  \n" + "        String name;\n" + "}\n";
    // @formatter:on
    String newText = TextEditUtil.apply(unit, edits);
    assertEquals(expectedText, newText);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FormattingOptions(org.eclipse.lsp4j.FormattingOptions) Position(org.eclipse.lsp4j.Position) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) Test(org.junit.Test)

Example 55 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class FormatterHandlerTest method testDocumentFormattingWithTabs.

@Test
public void testDocumentFormattingWithTabs() throws Exception {
    javaProject.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
    "package org.sample;\n\n" + "public class Baz {\n" + "    void foo(){\n" + "}\n" + "}\n");
    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    // ident == tab
    FormattingOptions options = new FormattingOptions(2, false);
    DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
    List<? extends TextEdit> edits = server.formatting(params).get();
    assertNotNull(edits);
    // @formatter:off
    String expectedText = "package org.sample;\n" + "\n" + "public class Baz {\n" + "\tvoid foo() {\n" + "\t}\n" + "}\n";
    // @formatter:on
    String newText = TextEditUtil.apply(unit, edits);
    assertEquals(expectedText, newText);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FormattingOptions(org.eclipse.lsp4j.FormattingOptions) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) Test(org.junit.Test)

Aggregations

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)172 Test (org.junit.Test)113 Position (org.eclipse.lsp4j.Position)102 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 Range (org.eclipse.lsp4j.Range)47 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)37 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)35 URI (java.net.URI)34 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)32 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)32 List (java.util.List)26 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Location (org.eclipse.lsp4j.Location)23 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)22 Command (org.eclipse.lsp4j.Command)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 CodeAction (org.eclipse.lsp4j.CodeAction)18