use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptRenameWithNode.
private CompletableFuture<WorkspaceEdit> actionScriptRenameWithNode(RenameParams params, IASNode offsetNode) {
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
IDefinition definition = null;
if (offsetNode instanceof IDefinitionNode) {
IDefinitionNode definitionNode = (IDefinitionNode) offsetNode;
IExpressionNode expressionNode = definitionNode.getNameExpressionNode();
definition = expressionNode.resolve(currentProject);
} else if (offsetNode instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
definition = identifierNode.resolve(currentProject);
}
if (definition == null) {
if (languageClient != null) {
MessageParams message = new MessageParams();
message.setType(MessageType.Info);
message.setMessage("You cannot rename this element.");
languageClient.showMessage(message);
}
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
WorkspaceEdit result = renameDefinition(definition, params.getNewName());
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlReferences.
private CompletableFuture<List<? extends Location>> mxmlReferences(ReferenceParams params, IMXMLTagData offsetTag) {
IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
if (definition != null) {
if (isInsideTagPrefix(offsetTag, currentOffset)) {
//ignore the tag's prefix
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Location> result = new ArrayList<>();
referencesForDefinition(definition, result);
return CompletableFuture.completedFuture(result);
}
//finally, check if we're looking for references to a tag's id
IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attributeData == null || !attributeData.getName().equals(IMXMLLanguageConstants.ATTRIBUTE_ID)) {
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
Path path = LanguageServerUtils.getPathFromLanguageServerURI(params.getTextDocument().getUri());
if (path == null) {
//this probably shouldn't happen, but check just to be safe
return CompletableFuture.completedFuture(Collections.emptyList());
}
ICompilationUnit unit = getCompilationUnit(path);
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
}
if (definitions == null || definitions.size() == 0) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
IClassDefinition classDefinition = null;
for (IDefinition currentDefinition : definitions) {
if (currentDefinition instanceof IClassDefinition) {
classDefinition = (IClassDefinition) currentDefinition;
break;
}
}
if (classDefinition == null) {
//this probably shouldn't happen, but check just to be safe
return CompletableFuture.completedFuture(Collections.emptyList());
}
IASScope scope = classDefinition.getContainedScope();
for (IDefinition currentDefinition : scope.getAllLocalDefinitions()) {
if (currentDefinition.getBaseName().equals(attributeData.getRawValue())) {
definition = currentDefinition;
break;
}
}
if (definition == null) {
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Location> result = new ArrayList<>();
referencesForDefinition(definition, result);
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.definitions.IDefinition 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.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlCompletion.
private CompletableFuture<CompletionList> mxmlCompletion(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
CompletionList result = new CompletionList();
result.setIsIncomplete(false);
result.setItems(new ArrayList<>());
if (isInXMLComment(position)) {
//if we're inside a comment, no completion!
return CompletableFuture.completedFuture(result);
}
IMXMLTagData parentTag = offsetTag.getParentTag();
//for some reason, the attributes list includes the >, but that's not
//what we want here, so check if currentOffset isn't the end of the tag!
boolean isAttribute = offsetTag.isOffsetInAttributeList(currentOffset) && currentOffset < offsetTag.getAbsoluteEnd();
if (isAttribute && offsetTag.isCloseTag()) {
return CompletableFuture.completedFuture(result);
}
//inside <fx:Declarations>
if (isDeclarationsTag(offsetTag)) {
if (!isAttribute) {
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
IDefinition offsetDefinition = getDefinitionForMXMLTag(offsetTag);
if (offsetDefinition == null) {
IDefinition parentDefinition = null;
if (parentTag != null) {
parentDefinition = getDefinitionForMXMLTag(parentTag);
}
if (parentDefinition != null) {
if (parentDefinition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) parentDefinition;
String offsetPrefix = offsetTag.getPrefix();
if (offsetPrefix.length() == 0 || parentTag.getPrefix().equals(offsetPrefix)) {
//only add members if the prefix is the same as the
//parent tag. members can't have different prefixes.
//also allow members when we don't have a prefix.
addMembersForMXMLTypeToAutoComplete(classDefinition, parentTag, offsetPrefix.length() == 0, result);
}
if (!isAttribute) {
//tags can't appear in attributes, so skip types
String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
if (defaultPropertyName != null) {
//only add types if the class defines [DefaultProperty]
//metadata
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
}
}
} else {
//the parent is something like a property, so matching the
//prefix is not required
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
}
return CompletableFuture.completedFuture(result);
} else if (isDeclarationsTag(parentTag)) {
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
return CompletableFuture.completedFuture(result);
}
return CompletableFuture.completedFuture(result);
}
if (offsetDefinition instanceof IClassDefinition) {
IMXMLTagAttributeData attribute = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attribute != null) {
return mxmlAttributeCompletion(offsetTag, result);
}
IClassDefinition classDefinition = (IClassDefinition) offsetDefinition;
addMembersForMXMLTypeToAutoComplete(classDefinition, offsetTag, !isAttribute, result);
String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
if (defaultPropertyName != null && !isAttribute) {
//if [DefaultProperty] is set, then we can instantiate
//types as child elements
//but we don't want to do that when in an attribute
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
if (offsetDefinition instanceof IVariableDefinition || offsetDefinition instanceof IEventDefinition || offsetDefinition instanceof IStyleDefinition) {
if (!isAttribute) {
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
System.err.println("Unknown definition for MXML completion: " + offsetDefinition.getClass());
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.definitions.IDefinition 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);
}
}
}
}
Aggregations