use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class DocumentSymbolService method createSymbol.
protected SymbolInformation createSymbol(EObject object) {
String name = getSymbolName(object);
if (name == null) {
return null;
}
SymbolKind kind = getSymbolKind(object);
if (kind == null) {
return null;
}
Location location = getSymbolLocation(object);
if (location == null) {
return null;
}
SymbolInformation symbol = new SymbolInformation();
symbol.setName(name);
symbol.setKind(kind);
symbol.setLocation(location);
return symbol;
}
use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class DocumentSymbolService method createSymbol.
protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess, Procedure1<? super SymbolInformation> acceptor) {
String name = getSymbolName(description);
if (name == null) {
return;
}
SymbolKind kind = getSymbolKind(description);
if (kind == null) {
return;
}
getSymbolLocation(description, resourceAccess, (Location location) -> {
SymbolInformation symbol = new SymbolInformation(name, kind, location);
acceptor.apply(symbol);
});
}
use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class DocumentSymbolService method getSymbols.
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource, CancelIndicator cancelIndicator) {
String uri = uriExtensions.toUriString(resource.getURI());
ArrayList<SymbolInformation> infos = new ArrayList<>();
List<DocumentSymbol> rootSymbols = Lists.transform(hierarchicalDocumentSymbolService.getSymbols(resource, cancelIndicator), Either::getRight);
for (DocumentSymbol rootSymbol : rootSymbols) {
Iterable<DocumentSymbol> symbols = Traverser.forTree(DocumentSymbol::getChildren).depthFirstPreOrder(rootSymbol);
Function1<? super DocumentSymbol, ? extends String> containerNameProvider = (DocumentSymbol symbol) -> {
DocumentSymbol firstSymbol = IterableExtensions.findFirst(symbols, (DocumentSymbol it) -> {
return it != symbol && !IterableExtensions.isNullOrEmpty(it.getChildren()) && it.getChildren().contains(symbol);
});
if (firstSymbol != null) {
return firstSymbol.getName();
}
return null;
};
for (DocumentSymbol s : symbols) {
infos.add(createSymbol(uri, s, containerNameProvider));
}
}
return Lists.transform(infos, Either::forLeft);
}
use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class DocumentSymbolService method createSymbol.
protected SymbolInformation createSymbol(IEObjectDescription description) {
String symbolName = getSymbolName(description);
if (symbolName == null) {
return null;
}
SymbolKind symbolKind = getSymbolKind(description);
if (symbolKind == null) {
return null;
}
SymbolInformation symbol = new SymbolInformation();
symbol.setName(symbolName);
symbol.setKind(symbolKind);
return symbol;
}
use of org.eclipse.lsp4j.SymbolInformation 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);
}
}
Aggregations