Search in sources :

Example 6 with DocumentSymbol

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

the class AbstractLanguageServerTest method testDocumentSymbol.

protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
    try {
        @Extension final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
        DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
        final CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
        final List<Either<SymbolInformation, DocumentSymbol>> symbols = symbolsFuture.get();
        Procedure1<? super List<Either<SymbolInformation, DocumentSymbol>>> _assertSymbols = configuration.getAssertSymbols();
        boolean _tripleNotEquals = (_assertSymbols != null);
        if (_tripleNotEquals) {
            configuration.getAssertSymbols().apply(symbols);
        } else {
            final Function1<Either<SymbolInformation, DocumentSymbol>, Object> _function = (Either<SymbolInformation, DocumentSymbol> it) -> {
                Object _xifexpression = null;
                if (this.hierarchicalDocumentSymbolSupport) {
                    _xifexpression = it.getRight();
                } else {
                    _xifexpression = it.getLeft();
                }
                return _xifexpression;
            };
            final List<Object> unwrappedSymbols = ListExtensions.<Either<SymbolInformation, DocumentSymbol>, Object>map(symbols, _function);
            final String actualSymbols = this.toExpectation(unwrappedSymbols);
            this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Extension(org.eclipse.xtext.xbase.lib.Extension) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol)

Example 7 with DocumentSymbol

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

the class AbstractLanguageServerTest method _toExpectation.

/**
 * @since 2.16
 */
protected String _toExpectation(final DocumentSymbol it) {
    String _xblockexpression = null;
    {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("selectionRange must be contained in the range: ");
        _builder.append(it);
        Assert.assertTrue(_builder.toString(), Ranges.containsRange(it.getRange(), it.getSelectionRange()));
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("symbol \"");
        String _name = it.getName();
        _builder_1.append(_name);
        _builder_1.append("\" {");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("kind: ");
        int _value = it.getKind().getValue();
        _builder_1.append(_value, "    ");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("range: ");
        String _expectation = this.toExpectation(it.getRange());
        _builder_1.append(_expectation, "    ");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("selectionRange: ");
        String _expectation_1 = this.toExpectation(it.getSelectionRange());
        _builder_1.append(_expectation_1, "    ");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("details: ");
        String _detail = it.getDetail();
        _builder_1.append(_detail, "    ");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("deprecated: ");
        Boolean _deprecated = it.getDeprecated();
        _builder_1.append(_deprecated, "    ");
        _builder_1.newLineIfNotEmpty();
        {
            boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getChildren());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder_1.append("    ");
                _builder_1.append("children: [");
                _builder_1.newLine();
                _builder_1.append("    ");
                _builder_1.append("\t");
                {
                    List<DocumentSymbol> _children = it.getChildren();
                    boolean _hasElements = false;
                    for (final DocumentSymbol child : _children) {
                        if (!_hasElements) {
                            _hasElements = true;
                        } else {
                            _builder_1.appendImmediate("\n", "    \t");
                        }
                        String _expectation_2 = this.toExpectation(child);
                        _builder_1.append(_expectation_2, "    \t");
                    }
                }
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("    ");
                _builder_1.append("]");
                _builder_1.newLine();
            }
        }
        _builder_1.append("}");
        _xblockexpression = _builder_1.toString();
    }
    return _xblockexpression;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol)

Example 8 with DocumentSymbol

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

the class SyntaxServerTest method testDocumentSymbol.

@Test
public void testDocumentSymbol() throws Exception {
    when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(Boolean.TRUE);
    URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
    DocumentSymbolParams params = new DocumentSymbolParams(identifier);
    List<Either<SymbolInformation, DocumentSymbol>> result = server.documentSymbol(params).join();
    assertNotNull(result);
    assertEquals(2, result.size());
    Either<SymbolInformation, DocumentSymbol> symbol = result.get(0);
    assertTrue(symbol.isRight());
    assertEquals("java", symbol.getRight().getName());
    assertEquals(SymbolKind.Package, symbol.getRight().getKind());
    symbol = result.get(1);
    assertTrue(symbol.isRight());
    assertEquals("Foo", symbol.getRight().getName());
    assertEquals(SymbolKind.Class, symbol.getRight().getKind());
    List<DocumentSymbol> children = symbol.getRight().getChildren();
    assertNotNull(children);
    assertEquals(1, children.size());
    assertEquals("main(String[])", children.get(0).getName());
    assertEquals(SymbolKind.Method, children.get(0).getKind());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) URI(java.net.URI) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Test(org.junit.Test)

Example 9 with DocumentSymbol

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

the class DocumentSymbolHandlerTest method testClass.

private void testClass(String className, boolean hierarchical) throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
    if (!hierarchical) {
        List<? extends SymbolInformation> symbols = getSymbols(className);
        for (SymbolInformation symbol : symbols) {
            Location loc = symbol.getLocation();
            assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", loc != null && isValid(loc.getRange()));
        }
    } else {
        List<? extends DocumentSymbol> hierarchicalSymbols = getHierarchicalSymbols(className);
        for (DocumentSymbol symbol : hierarchicalSymbols) {
            Range fullRange = symbol.getRange();
            Range selectionRange = symbol.getSelectionRange();
            assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", fullRange != null && isValid(fullRange) && selectionRange != null && isValid(selectionRange));
        }
    }
}
Also used : DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 10 with DocumentSymbol

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

the class DocumentSymbolHandlerTest method testSyntheticMember_hierarchical.

@Test
public void testSyntheticMember_hierarchical() throws Exception {
    String className = "org.apache.commons.lang3.text.StrTokenizer";
    List<? extends DocumentSymbol> symbols = asStream(getHierarchicalSymbols(className)).collect(Collectors.toList());
    boolean overloadedMethod1Found = false;
    boolean overloadedMethod2Found = false;
    String overloadedMethod1 = "getCSVInstance(String) : StrTokenizer";
    String overloadedMethod2 = "reset() : StrTokenizer";
    for (DocumentSymbol symbol : symbols) {
        Range fullRange = symbol.getRange();
        Range selectionRange = symbol.getSelectionRange();
        assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", fullRange != null && isValid(fullRange) && selectionRange != null && isValid(selectionRange));
        assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid name", symbol.getName().startsWith("access$"));
        assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + "- invalid name", symbol.getName().equals("<clinit>"));
        if (overloadedMethod1.equals(symbol.getName() + symbol.getDetail())) {
            overloadedMethod1Found = true;
        }
        if (overloadedMethod2.equals(symbol.getName() + symbol.getDetail())) {
            overloadedMethod2Found = true;
        }
    }
    assertTrue("The " + overloadedMethod1 + " method hasn't been found", overloadedMethod1Found);
    assertTrue("The " + overloadedMethod2 + " method hasn't been found", overloadedMethod2Found);
}
Also used : DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Range(org.eclipse.lsp4j.Range) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

DocumentSymbol (org.eclipse.lsp4j.DocumentSymbol)10 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)6 DocumentSymbolParams (org.eclipse.lsp4j.DocumentSymbolParams)5 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)5 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Range (org.eclipse.lsp4j.Range)3 Collectors (java.util.stream.Collectors)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 Exceptions (org.eclipse.xtext.xbase.lib.Exceptions)2 Test (org.junit.Test)2 Beta (com.google.common.annotations.Beta)1 Optional (com.google.common.base.Optional)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1