use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class DocumentSymbolService method createSymbol.
/**
* @since 2.16
*/
protected SymbolInformation createSymbol(String uri, DocumentSymbol symbol, Function1<? super DocumentSymbol, ? extends String> containerNameProvider) {
SymbolInformation symbolInformation = new SymbolInformation();
symbolInformation.setName(symbol.getName());
symbolInformation.setKind(symbol.getKind());
symbolInformation.setDeprecated(symbol.getDeprecated());
Location location = new Location();
location.setUri(uri);
location.setRange(symbol.getSelectionRange());
symbolInformation.setLocation(location);
symbolInformation.setContainerName(containerNameProvider.apply(symbol));
return symbolInformation;
}
use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class HierarchicalDocumentSymbolService method getSymbols.
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource, CancelIndicator cancelIndicator) {
HashMap<EObject, DocumentSymbol> allSymbols = new HashMap<>();
ArrayList<DocumentSymbol> rootSymbols = new ArrayList<>();
Iterator<Object> itr = getAllContents(resource);
while (itr.hasNext()) {
operationCanceledManager.checkCanceled(cancelIndicator);
Optional<EObject> next = toEObject(itr.next());
if (next.isPresent()) {
EObject object = next.get();
DocumentSymbol symbol = symbolMapper.toDocumentSymbol(object);
if (isValid(symbol)) {
allSymbols.put(object, symbol);
EObject parent = object.eContainer();
if (parent == null) {
rootSymbols.add(symbol);
} else {
DocumentSymbol parentSymbol = allSymbols.get(parent);
while (parentSymbol == null && parent != null) {
parent = parent.eContainer();
parentSymbol = allSymbols.get(parent);
}
if (parentSymbol == null) {
rootSymbols.add(symbol);
} else {
parentSymbol.getChildren().add(symbol);
}
}
}
}
}
return rootSymbols.stream().map(symbol -> Either.<SymbolInformation, DocumentSymbol>forRight(symbol)).collect(Collectors.toList());
}
use of org.eclipse.lsp4j.SymbolInformation in project xtext-core by eclipse.
the class WorkspaceSymbolService method getSymbols.
public List<? extends SymbolInformation> getSymbols(String query, IResourceAccess resourceAccess, IResourceDescriptions indexData, CancelIndicator cancelIndicator) {
List<SymbolInformation> result = new LinkedList<>();
for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) {
operationCanceledManager.checkCanceled(cancelIndicator);
IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(resourceDescription.getURI());
if (resourceServiceProvider != null) {
DocumentSymbolService documentSymbolService = resourceServiceProvider.get(DocumentSymbolService.class);
if (documentSymbolService != null) {
result.addAll(documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator));
}
}
}
return result;
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class WorkspaceSymbolHandlerTest method testSearchSourceMethodDeclarations.
@Test
public void testSearchSourceMethodDeclarations() {
preferences.setIncludeSourceMethodDeclarations(true);
List<SymbolInformation> results = WorkspaceSymbolHandler.search("deleteSomething", "hello", true, monitor);
assertNotNull(results);
assertEquals("Found " + results.size() + " result", 1, results.size());
SymbolInformation res = results.get(0);
assertEquals(SymbolKind.Method, res.getKind());
assertEquals(res.getContainerName(), "org.sample.Baz");
results = WorkspaceSymbolHandler.search("main", "hello", true, monitor);
assertNotNull(results);
assertEquals("Found " + results.size() + " result", 11, results.size());
boolean allMethods = results.stream().allMatch(s -> s.getKind() == SymbolKind.Method);
assertTrue("Found a non-method symbol", allMethods);
preferences.setIncludeSourceMethodDeclarations(false);
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class WorkspaceSymbolHandlerTest method testWorkspaceSearchOnFileInWorkspace.
@Test
public void testWorkspaceSearchOnFileInWorkspace() {
String query = "Baz";
List<SymbolInformation> results = WorkspaceSymbolHandler.search(query, monitor);
assertNotNull(results);
Range defaultRange = JDTUtils.newRange();
assertEquals("Unexpected results", 2, results.size());
for (SymbolInformation symbol : results) {
assertNotNull("Kind is missing", symbol.getKind());
assertNotNull("ContainerName is missing", symbol.getContainerName());
assertTrue(symbol.getName().startsWith(query));
Location location = symbol.getLocation();
assertNotEquals("Range should not equal the default range", defaultRange, location.getRange());
assertTrue("Unexpected uri " + location.getUri(), location.getUri().startsWith("file://"));
}
}
Aggregations