Search in sources :

Example 1 with CompletionItem

use of org.eclipse.lsp4j.CompletionItem 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 2 with CompletionItem

use of org.eclipse.lsp4j.CompletionItem 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);
                    }
                }
            }
        }
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) CompletionItem(org.eclipse.lsp4j.CompletionItem) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with CompletionItem

use of org.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method autoCompletePackageBlock.

private void autoCompletePackageBlock(CompletionList result) {
    String expectedPackage = getExpectedPackage(currentUnit);
    StringBuilder builder = new StringBuilder();
    builder.append("package");
    if (expectedPackage.length() > 0) {
        builder.append(" ");
        builder.append(expectedPackage);
    }
    builder.append("\n{\n\t\n}");
    CompletionItem packageItem = new CompletionItem();
    packageItem.setLabel(builder.toString());
    result.getItems().add(packageItem);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem)

Example 4 with CompletionItem

use of org.eclipse.lsp4j.CompletionItem 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);
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) CompletionItem(org.eclipse.lsp4j.CompletionItem) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with CompletionItem

use of org.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method addDefinitionAutoCompleteActionScript.

private void addDefinitionAutoCompleteActionScript(IDefinition definition, CompletionList result) {
    if (definition.getBaseName().startsWith(VECTOR_HIDDEN_PREFIX)) {
        return;
    }
    CompletionItem item = new CompletionItem();
    item.setKind(getDefinitionKind(definition));
    item.setDetail(getDefinitionDetail(definition));
    item.setLabel(definition.getBaseName());
    boolean isInPackage = !definition.getQualifiedName().equals(definition.getBaseName());
    if (isInPackage) {
        Command command = createImportCommand(definition);
        if (command != null) {
            item.setCommand(command);
        }
    }
    result.getItems().add(item);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) Command(org.eclipse.lsp4j.Command)

Aggregations

CompletionItem (org.eclipse.lsp4j.CompletionItem)9 IDefinition (org.apache.flex.compiler.definitions.IDefinition)5 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)3 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)3 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)2 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)1 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)1 Command (org.eclipse.lsp4j.Command)1