Search in sources :

Example 1 with CodeLensParams

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

the class CodeLensHandlerTest method testEnableImplementationsCodeLensSymbols.

@Test
public void testEnableImplementationsCodeLensSymbols() throws Exception {
    Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
    Mockito.reset(preferenceManager);
    when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
    handler = new CodeLensHandler(preferenceManager);
    String payload = createCodeLensSymbolsRequest("src/java/IFoo.java");
    CodeLensParams codeLensParams = getParams(payload);
    String uri = codeLensParams.getTextDocument().getUri();
    assertFalse(uri.isEmpty());
    // when
    List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);
    // then
    assertEquals(2, result.size());
    CodeLens lens = result.get(1);
    @SuppressWarnings("unchecked") List<Object> data = (List<Object>) lens.getData();
    String type = (String) data.get(2);
    assertEquals(type, "implementations");
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) List(java.util.List) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 2 with CodeLensParams

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

the class CodeLensHandlerTest method testIgnoreLombokCodeLensSymbols.

@Test
public void testIgnoreLombokCodeLensSymbols() throws Exception {
    String payload = createCodeLensSymbolsRequest("src/java/Bar.java");
    CodeLensParams codeLensParams = getParams(payload);
    String uri = codeLensParams.getTextDocument().getUri();
    assertFalse(uri.isEmpty());
    // when
    List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);
    // then
    assertEquals("Found " + result, 4, result.size());
    // CodeLens on constructor
    CodeLens cl = result.get(0);
    assertRange(7, 11, 14, cl.getRange());
    // CodeLens on somethingFromJPAModelGen
    cl = result.get(1);
    assertRange(16, 16, 40, cl.getRange());
    // CodeLens on foo
    cl = result.get(2);
    assertRange(22, 16, 19, cl.getRange());
    // CodeLens on Bar type
    cl = result.get(3);
    assertRange(5, 13, 16, cl.getRange());
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 3 with CodeLensParams

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

the class CodeLensHandlerTest method testGetCodeLensSymbols.

@Test
public void testGetCodeLensSymbols() throws Exception {
    String payload = createCodeLensSymbolsRequest("src/java/Foo.java");
    CodeLensParams codeLensParams = getParams(payload);
    String uri = codeLensParams.getTextDocument().getUri();
    assertFalse(uri.isEmpty());
    // when
    List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);
    // then
    assertEquals("Found " + result, 3, result.size());
    CodeLens cl = result.get(0);
    Range r = cl.getRange();
    // CodeLens on main method
    assertRange(7, 20, 24, r);
    cl = result.get(1);
    r = cl.getRange();
    // CodeLens on foo method
    assertRange(14, 13, 16, r);
    cl = result.get(2);
    r = cl.getRange();
    // CodeLens on Foo type
    assertRange(5, 13, 16, r);
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) Range(org.eclipse.lsp4j.Range) Lsp4jAssertions.assertRange(org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertRange) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 4 with CodeLensParams

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

the class AbstractLanguageServerTest method testCodeLens.

protected void testCodeLens(final Procedure1<? super AbstractLanguageServerTest.TestCodeLensConfiguration> configurator) {
    try {
        @Extension final AbstractLanguageServerTest.TestCodeLensConfiguration configuration = new AbstractLanguageServerTest.TestCodeLensConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CodeLensParams _codeLensParams = new CodeLensParams();
        final Procedure1<CodeLensParams> _function = (CodeLensParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
        };
        CodeLensParams _doubleArrow = ObjectExtensions.<CodeLensParams>operator_doubleArrow(_codeLensParams, _function);
        final CompletableFuture<List<? extends CodeLens>> codeLenses = this.languageServer.codeLens(_doubleArrow);
        final Function1<CodeLens, CodeLens> _function_1 = (CodeLens it) -> {
            try {
                return this.languageServer.resolveCodeLens(it).get();
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        final List<CodeLens> result = IterableExtensions.<CodeLens>toList(ListExtensions.map(codeLenses.get(), _function_1));
        if ((configuration.assertCodeLenses != null)) {
            configuration.assertCodeLenses.apply(result);
        } else {
            this.assertEquals(configuration.expectedCodeLensItems, this.toExpectation(result));
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 5 with CodeLensParams

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

the class CodeLensHandlerTest method testGetCodeLensSymbolsForClass.

@Test
public void testGetCodeLensSymbolsForClass() throws Exception {
    Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
    Mockito.reset(preferenceManager);
    when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
    handler = new CodeLensHandler(preferenceManager);
    String uriString = ClassFileUtil.getURI(project, "java.lang.Runnable");
    String payload = createCodeLensSymbolRequest(new URI(uriString));
    CodeLensParams codeLensParams = getParams(payload);
    String uri = codeLensParams.getTextDocument().getUri();
    assertFalse(uri.isEmpty());
    List<CodeLens> lenses = handler.getCodeLensSymbols(uri, monitor);
    assertEquals("Found " + lenses, 3, lenses.size());
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) URI(java.net.URI) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

CodeLensParams (org.eclipse.lsp4j.CodeLensParams)9 CodeLens (org.eclipse.lsp4j.CodeLens)8 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)7 Test (org.junit.Test)7 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)4 List (java.util.List)2 URI (java.net.URI)1 Lsp4jAssertions.assertRange (org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertRange)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Range (org.eclipse.lsp4j.Range)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1