use of org.apache.flex.compiler.definitions.ITypeDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteImport.
private void autoCompleteImport(String importName, CompletionList result) {
List<CompletionItem> items = result.getItems();
for (ICompilationUnit unit : compilationUnits) {
if (unit == null) {
continue;
}
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
continue;
}
for (IDefinition definition : definitions) {
if (definition instanceof ITypeDefinition) {
String qualifiedName = definition.getQualifiedName();
if (qualifiedName.equals(definition.getBaseName())) {
//this definition is top-level. no import required.
continue;
}
if (qualifiedName.startsWith(importName)) {
int index = importName.lastIndexOf(".");
if (index != -1) {
qualifiedName = qualifiedName.substring(index + 1);
}
index = qualifiedName.indexOf(".");
if (index > 0) {
qualifiedName = qualifiedName.substring(0, index);
}
CompletionItem item = new CompletionItem();
item.setLabel(qualifiedName);
if (definition.getBaseName().equals(qualifiedName)) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
if (typeDefinition instanceof IInterfaceDefinition) {
item.setKind(CompletionItemKind.Interface);
} else if (typeDefinition instanceof IClassDefinition) {
item.setKind(CompletionItemKind.Class);
} else {
item.setKind(CompletionItemKind.Text);
}
} else {
item.setKind(CompletionItemKind.Text);
}
if (!items.contains(item)) {
items.add(item);
}
}
}
}
}
}
use of org.apache.flex.compiler.definitions.ITypeDefinition 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.apache.flex.compiler.definitions.ITypeDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteDefinitions.
private void autoCompleteDefinitions(CompletionList result, boolean forMXML, boolean typesOnly, String packageName, IDefinition definitionToSkip) {
String skipQualifiedName = null;
if (definitionToSkip != null) {
skipQualifiedName = definitionToSkip.getQualifiedName();
}
for (ICompilationUnit unit : compilationUnits) {
if (unit == null) {
continue;
}
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
continue;
}
for (IDefinition definition : definitions) {
boolean isType = definition instanceof ITypeDefinition;
if (!typesOnly || isType) {
if (packageName == null || definition.getPackageName().equals(packageName)) {
if (skipQualifiedName != null && skipQualifiedName.equals(definition.getQualifiedName())) {
continue;
}
if (isType) {
IMetaTag excludeClassMetaTag = definition.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDECLASS);
if (excludeClassMetaTag != null) {
//skip types with [ExcludeClass] metadata
continue;
}
}
if (forMXML && isType) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
addMXMLTypeDefinitionAutoComplete(typeDefinition, result);
} else {
addDefinitionAutoCompleteActionScript(definition, result);
}
}
}
}
}
if (packageName == null || packageName.equals("")) {
CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Class);
item.setLabel(IASKeywordConstants.VOID);
result.getItems().add(item);
}
}
use of org.apache.flex.compiler.definitions.ITypeDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method signatureHelp.
/**
* Displays a function's parameters, including which one is currently
* active. Called automatically by VSCode any time that the user types "(",
* so be sure to check that a function call is actually happening at the
* current position.
*/
@Override
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams position) {
String textDocumentUri = position.getTextDocument().getUri();
if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
IASNode offsetNode = null;
IMXMLTagData offsetTag = getOffsetMXMLTag(position);
if (offsetTag != null) {
IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attributeData != null) {
//some attributes can have ActionScript completion, such as
//events and properties with data binding
IClassDefinition tagDefinition = (IClassDefinition) currentProject.resolveXMLNameToDefinition(offsetTag.getXMLName(), offsetTag.getMXMLDialect());
IDefinition attributeDefinition = currentProject.resolveSpecifier(tagDefinition, attributeData.getShortName());
if (attributeDefinition instanceof IEventDefinition) {
IMXMLInstanceNode mxmlNode = (IMXMLInstanceNode) getOffsetNode(position);
IMXMLEventSpecifierNode eventNode = mxmlNode.getEventSpecifierNode(attributeData.getShortName());
for (IASNode asNode : eventNode.getASNodes()) {
IASNode containingNode = getContainingNodeIncludingStart(asNode, currentOffset);
if (containingNode != null) {
offsetNode = containingNode;
}
}
if (offsetNode == null) {
offsetNode = eventNode;
}
}
}
}
if (offsetNode == null) {
offsetNode = getOffsetNode(position);
}
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
IFunctionCallNode functionCallNode = getAncestorFunctionCallNode(offsetNode);
IFunctionDefinition functionDefinition = null;
if (functionCallNode != null) {
IExpressionNode nameNode = functionCallNode.getNameNode();
IDefinition definition = nameNode.resolve(currentUnit.getProject());
if (definition instanceof IFunctionDefinition) {
functionDefinition = (IFunctionDefinition) definition;
} else if (definition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) definition;
functionDefinition = classDefinition.getConstructor();
} else if (nameNode instanceof IIdentifierNode) {
//special case for super()
IIdentifierNode identifierNode = (IIdentifierNode) nameNode;
if (identifierNode.getName().equals(IASKeywordConstants.SUPER)) {
ITypeDefinition typeDefinition = nameNode.resolveType(currentProject);
if (typeDefinition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) typeDefinition;
functionDefinition = classDefinitionToConstructor(classDefinition);
}
}
}
}
if (functionDefinition != null) {
SignatureHelp result = new SignatureHelp();
List<SignatureInformation> signatures = new ArrayList<>();
SignatureInformation signatureInfo = new SignatureInformation();
signatureInfo.setLabel(getSignatureLabel(functionDefinition));
List<ParameterInformation> parameters = new ArrayList<>();
for (IParameterDefinition param : functionDefinition.getParameters()) {
ParameterInformation paramInfo = new ParameterInformation();
paramInfo.setLabel(param.getBaseName());
parameters.add(paramInfo);
}
signatureInfo.setParameters(parameters);
signatures.add(signatureInfo);
result.setSignatures(signatures);
result.setActiveSignature(0);
int index = getFunctionCallNodeArgumentIndex(functionCallNode, offsetNode);
IParameterDefinition[] params = functionDefinition.getParameters();
int paramCount = params.length;
if (paramCount > 0 && index >= paramCount) {
if (index >= paramCount) {
IParameterDefinition lastParam = params[paramCount - 1];
if (lastParam.isRest()) {
//functions with rest parameters may accept any
//number of arguments, so continue to make the rest
//parameter active
index = paramCount - 1;
} else {
//if there's no rest parameter, and we're beyond the
//final parameter, none should be active
index = -1;
}
}
}
if (index != -1) {
result.setActiveParameter(index);
}
return CompletableFuture.completedFuture(result);
}
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
use of org.apache.flex.compiler.definitions.ITypeDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteMemberAccess.
private void autoCompleteMemberAccess(IMemberAccessExpressionNode node, CompletionList result) {
ASScope scope = (ASScope) node.getContainingScope().getScope();
IExpressionNode leftOperand = node.getLeftOperandNode();
IDefinition leftDefinition = leftOperand.resolve(currentProject);
if (leftDefinition != null && leftDefinition instanceof ITypeDefinition) {
ITypeDefinition typeDefinition = (ITypeDefinition) leftDefinition;
TypeScope typeScope = (TypeScope) typeDefinition.getContainedScope();
addDefinitionsInTypeScopeToAutoCompleteActionScript(typeScope, scope, true, result);
return;
}
ITypeDefinition leftType = leftOperand.resolveType(currentProject);
if (leftType != null) {
TypeScope typeScope = (TypeScope) leftType.getContainedScope();
addDefinitionsInTypeScopeToAutoCompleteActionScript(typeScope, scope, false, result);
return;
}
if (leftOperand instanceof IMemberAccessExpressionNode) {
IMemberAccessExpressionNode memberAccess = (IMemberAccessExpressionNode) leftOperand;
String packageName = memberAccessToPackageName(memberAccess);
if (packageName != null) {
autoCompleteDefinitions(result, false, false, packageName, null);
return;
}
}
}
Aggregations