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);
}
}
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;
}
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());
}
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));
}
}
}
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);
}
Aggregations