Search in sources :

Example 6 with IDefinition

use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getEmbeddedActionScriptNodeInMXMLTag.

private IASNode getEmbeddedActionScriptNodeInMXMLTag(IMXMLTagData tag, int offset, TextDocumentPositionParams position) {
    IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(tag, currentOffset);
    if (attributeData != null) {
        //some attributes can have ActionScript completion, such as
        //events and properties with data binding
        IClassDefinition tagDefinition = (IClassDefinition) currentProject.resolveXMLNameToDefinition(tag.getXMLName(), tag.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) {
                    return containingNode;
                }
            }
            return eventNode;
        } else {
            IASNode offsetNode = getOffsetNode(position);
            if (offsetNode instanceof IMXMLInstanceNode) {
                IMXMLInstanceNode instanceNode = (IMXMLInstanceNode) offsetNode;
                IMXMLPropertySpecifierNode propertyNode = instanceNode.getPropertySpecifierNode(attributeData.getShortName());
                if (propertyNode != null) {
                    for (int i = 0, count = propertyNode.getChildCount(); i < count; i++) {
                        IMXMLNode propertyChild = (IMXMLNode) propertyNode.getChild(i);
                        if (propertyChild instanceof IMXMLConcatenatedDataBindingNode) {
                            IMXMLConcatenatedDataBindingNode dataBinding = (IMXMLConcatenatedDataBindingNode) propertyChild;
                            for (int j = 0, childCount = dataBinding.getChildCount(); j < childCount; j++) {
                                IASNode dataBindingChild = dataBinding.getChild(i);
                                if (dataBindingChild.contains(currentOffset) && dataBindingChild instanceof IMXMLSingleDataBindingNode) {
                                    //we'll parse this in a moment, as if it were
                                    //a direct child of the property specifier
                                    propertyChild = (IMXMLSingleDataBindingNode) dataBindingChild;
                                    break;
                                }
                            }
                        }
                        if (propertyChild instanceof IMXMLSingleDataBindingNode) {
                            IMXMLSingleDataBindingNode dataBinding = (IMXMLSingleDataBindingNode) propertyChild;
                            IASNode containingNode = dataBinding.getExpressionNode().getContainingNode(currentOffset);
                        //we found the correct expression, but due to a bug
                        //in the compiler its line and column positions
                        //will be wrong. the resulting completion is too
                        //quirky, so this feature will be completed later.
                        //return containingNode;
                        }
                    }
                }
            }
        //nothing possible for this attribute
        }
    }
    return null;
}
Also used : IMXMLConcatenatedDataBindingNode(org.apache.flex.compiler.tree.mxml.IMXMLConcatenatedDataBindingNode) IMXMLEventSpecifierNode(org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMXMLInstanceNode(org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode) IASNode(org.apache.flex.compiler.tree.as.IASNode) IMXMLSingleDataBindingNode(org.apache.flex.compiler.tree.mxml.IMXMLSingleDataBindingNode) IMXMLPropertySpecifierNode(org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode) IEventDefinition(org.apache.flex.compiler.definitions.IEventDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IMXMLNode(org.apache.flex.compiler.tree.mxml.IMXMLNode) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Example 7 with IDefinition

use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method mxmlHover.

private CompletableFuture<Hover> mxmlHover(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
    IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
    if (definition == null) {
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    if (isInsideTagPrefix(offsetTag, currentOffset)) {
        //inside the prefix
        String prefix = offsetTag.getPrefix();
        Hover result = new Hover();
        List<String> contents = new ArrayList<>();
        StringBuilder detailBuilder = new StringBuilder();
        detailBuilder.append(MARKDOWN_CODE_BLOCK_MXML_START);
        if (prefix.length() > 0) {
            detailBuilder.append("xmlns:" + prefix + "=\"" + offsetTag.getURI() + "\"");
        } else {
            detailBuilder.append("xmlns=\"" + offsetTag.getURI() + "\"");
        }
        detailBuilder.append(MARKDOWN_CODE_BLOCK_END);
        contents.add(detailBuilder.toString());
        result.setContents(contents);
        return CompletableFuture.completedFuture(result);
    }
    Hover result = new Hover();
    String detail = getDefinitionDetail(definition);
    List<String> contents = new ArrayList<>();
    contents.add(MARKDOWN_CODE_BLOCK_NEXTGENAS_START + detail + MARKDOWN_CODE_BLOCK_END);
    result.setContents(contents);
    return CompletableFuture.completedFuture(result);
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 8 with IDefinition

use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method addStyleMetadataToAutoCompleteMXML.

private void addStyleMetadataToAutoCompleteMXML(TypeScope typeScope, String prefix, CompletionList result) {
    ArrayList<String> styleNames = new ArrayList<>();
    IDefinition definition = typeScope.getDefinition();
    List<CompletionItem> items = result.getItems();
    while (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        IMetaTag[] styleMetaTags = typeScope.getDefinition().getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_STYLE);
        for (IMetaTag styleMetaTag : styleMetaTags) {
            String styleName = styleMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_STYLE_NAME);
            if (styleNames.contains(styleName)) {
                //avoid duplicates!
                continue;
            }
            styleNames.add(styleName);
            IDefinition styleDefinition = currentProject.resolveSpecifier(classDefinition, styleName);
            if (styleDefinition == null) {
                continue;
            }
            boolean foundExisting = false;
            for (CompletionItem item : items) {
                if (item.getLabel().equals(styleName)) {
                    //we want to avoid adding a duplicate item with the same
                    //name. if there's a conflict, the compiler will know
                    //how to handle it.
                    foundExisting = true;
                    break;
                }
            }
            if (foundExisting) {
                break;
            }
            CompletionItem item = new CompletionItem();
            item.setKind(CompletionItemKind.Field);
            item.setLabel(styleName);
            if (prefix != null) {
                item.setInsertText(prefix + IMXMLCoreConstants.colon + styleName);
            }
            item.setDetail(getDefinitionDetail(styleDefinition));
            items.add(item);
        }
        definition = classDefinition.resolveBaseClass(currentProject);
    }
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 9 with IDefinition

use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method actionScriptHoverWithNode.

private CompletableFuture<Hover> actionScriptHoverWithNode(TextDocumentPositionParams position, IASNode offsetNode) {
    IDefinition definition = null;
    if (offsetNode == null) {
        //we couldn't find a node at the specified location
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    //any hover information for it.
    if (definition == null && offsetNode instanceof IIdentifierNode && !(offsetNode instanceof INamespaceDecorationNode)) {
        IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
        definition = identifierNode.resolve(currentUnit.getProject());
    }
    if (definition == null) {
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    Hover result = new Hover();
    String detail = getDefinitionDetail(definition);
    List<String> contents = new ArrayList<>();
    contents.add(MARKDOWN_CODE_BLOCK_NEXTGENAS_START + detail + MARKDOWN_CODE_BLOCK_END);
    result.setContents(contents);
    return CompletableFuture.completedFuture(result);
}
Also used : INamespaceDecorationNode(org.apache.flex.compiler.tree.as.INamespaceDecorationNode) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 10 with IDefinition

use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method mxmlRename.

private CompletableFuture<WorkspaceEdit> mxmlRename(RenameParams params, IMXMLTagData offsetTag) {
    IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
    if (definition != null) {
        if (isInsideTagPrefix(offsetTag, currentOffset)) {
            //ignore the tag's prefix
            return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
        }
        WorkspaceEdit result = renameDefinition(definition, params.getNewName());
        return CompletableFuture.completedFuture(result);
    }
    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<>()));
}
Also used : HashMap(java.util.HashMap) MessageParams(org.eclipse.lsp4j.MessageParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Aggregations

IDefinition (org.apache.flex.compiler.definitions.IDefinition)30 ArrayList (java.util.ArrayList)12 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)12 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)10 IASScope (org.apache.flex.compiler.scopes.IASScope)7 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)6 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)6 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)6 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)5 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)5 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)4 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)4 IASNode (org.apache.flex.compiler.tree.as.IASNode)4 IExpressionNode (org.apache.flex.compiler.tree.as.IExpressionNode)4