use of org.eclipse.lsp4j.SymbolInformation in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method querySymbolsInScope.
private void querySymbolsInScope(String query, IASScope scope, List<SymbolInformation> result) {
String lowerCaseQuery = query.toLowerCase();
Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
for (IDefinition definition : definitions) {
if (definition instanceof IPackageDefinition) {
IPackageDefinition packageDefinition = (IPackageDefinition) definition;
IASScope packageScope = packageDefinition.getContainedScope();
querySymbolsInScope(query, packageScope, result);
} else if (definition instanceof ITypeDefinition) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
if (!definition.isImplicit() && typeDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
SymbolInformation symbol = definitionToSymbol(typeDefinition);
result.add(symbol);
}
IASScope typeScope = typeDefinition.getContainedScope();
querySymbolsInScope(query, typeScope, result);
} else if (definition instanceof IFunctionDefinition) {
if (definition.isImplicit()) {
continue;
}
IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
if (functionDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
SymbolInformation symbol = definitionToSymbol(functionDefinition);
result.add(symbol);
}
IASScope functionScope = functionDefinition.getContainedScope();
querySymbolsInScope(query, functionScope, result);
} else if (definition instanceof IVariableDefinition) {
if (definition.isImplicit()) {
continue;
}
IVariableDefinition variableDefinition = (IVariableDefinition) definition;
if (variableDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
SymbolInformation symbol = definitionToSymbol(variableDefinition);
result.add(symbol);
}
}
}
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandler method documentSymbol.
public List<? extends SymbolInformation> documentSymbol(DocumentSymbolParams params, IProgressMonitor monitor) {
ITypeRoot unit = JDTUtils.resolveTypeRoot(params.getTextDocument().getUri());
if (unit == null) {
return Collections.emptyList();
}
SymbolInformation[] elements = this.getOutline(unit, monitor);
return Arrays.asList(elements);
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class WorkspaceSymbolHandler method search.
public List<SymbolInformation> search(String query, IProgressMonitor monitor) {
if (query == null || query.trim().isEmpty()) {
return Collections.emptyList();
}
try {
ArrayList<SymbolInformation> symbols = new ArrayList<>();
new SearchEngine().searchAllTypeNames(null, SearchPattern.R_PATTERN_MATCH, query.toCharArray(), SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.TYPE, createSearchScope(), new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
SymbolInformation symbolInformation = new SymbolInformation();
symbolInformation.setContainerName(match.getTypeContainerName());
symbolInformation.setName(match.getSimpleTypeName());
symbolInformation.setKind(mapKind(match));
Location location;
try {
if (match.getType().isBinary()) {
location = JDTUtils.toLocation(match.getType().getClassFile());
} else {
location = JDTUtils.toLocation(match.getType());
}
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Unable to determine location for " + match.getSimpleTypeName(), e);
return;
}
symbolInformation.setLocation(location);
symbols.add(symbolInformation);
}
private SymbolKind mapKind(TypeNameMatch match) {
int flags = match.getModifiers();
if (Flags.isInterface(flags)) {
return SymbolKind.Interface;
}
if (Flags.isAnnotation(flags)) {
return SymbolKind.Property;
}
if (Flags.isEnum(flags)) {
return SymbolKind.Enum;
}
return SymbolKind.Class;
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
return symbols;
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Problem getting search for" + query, e);
}
return Collections.emptyList();
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class WorkspaceSymbolHandlerTest method testWorkspaceSearch.
@Test
public void testWorkspaceSearch() {
String query = "Array";
List<SymbolInformation> results = handler.search(query, monitor);
assertNotNull(results);
assertEquals("Unexpected results", 11, results.size());
Range defaultRange = JDTUtils.newRange();
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();
assertEquals(defaultRange, location.getRange());
// No class in the workspace project starts with Array, so everything comes from the JDK
assertTrue("Unexpected uri " + location.getUri(), location.getUri().startsWith("jdt://"));
}
}
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 = handler.search(query, monitor);
assertNotNull(results);
assertEquals("Unexpected results", 2, results.size());
Range defaultRange = JDTUtils.newRange();
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