Search in sources :

Example 6 with CompletionItem

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

the class ActionScriptTextDocumentService method mxmlAttributeCompletion.

private CompletableFuture<CompletionList> mxmlAttributeCompletion(IMXMLTagData offsetTag, CompletionList result) {
    List<CompletionItem> items = result.getItems();
    IDefinition attributeDefinition = getDefinitionForMXMLTagAttribute(offsetTag, currentOffset, true);
    if (attributeDefinition instanceof IVariableDefinition) {
        IVariableDefinition variableDefinition = (IVariableDefinition) attributeDefinition;
        if (variableDefinition.getTypeAsDisplayString().equals(IASLanguageConstants.Boolean)) {
            CompletionItem falseItem = new CompletionItem();
            falseItem.setKind(CompletionItemKind.Value);
            falseItem.setLabel(IASLanguageConstants.FALSE);
            items.add(falseItem);
            CompletionItem trueItem = new CompletionItem();
            trueItem.setKind(CompletionItemKind.Value);
            trueItem.setLabel(IASLanguageConstants.TRUE);
            items.add(trueItem);
            return CompletableFuture.completedFuture(result);
        }
    }
    return CompletableFuture.completedFuture(result);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 7 with CompletionItem

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

the class ActionScriptTextDocumentService method autoCompletePackageName.

private void autoCompletePackageName(String partialPackageName, CompletionList result) {
    String expectedPackage = getExpectedPackage(currentUnit);
    if (expectedPackage.length() == 0) {
        //it's the top level package
        return;
    }
    if (partialPackageName.startsWith(expectedPackage)) {
        //we already have the correct package, maybe with some extra
        return;
    }
    if (partialPackageName.contains(".") && expectedPackage.startsWith(partialPackageName)) {
        int lastDot = partialPackageName.lastIndexOf('.');
        expectedPackage = expectedPackage.substring(lastDot + 1);
    }
    CompletionItem item = new CompletionItem();
    item.setKind(CompletionItemKind.Module);
    item.setLabel(expectedPackage);
    result.getItems().add(item);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem)

Example 8 with CompletionItem

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

the class ActionScriptTextDocumentService method addDefinitionAutoCompleteMXML.

private void addDefinitionAutoCompleteMXML(IDefinition definition, String prefix, String uri, 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());
    if (prefix != null) {
        item.setInsertText(prefix + IMXMLCoreConstants.colon + definition.getBaseName());
        if (definition instanceof ITypeDefinition && uri != null) {
            item.setCommand(createMXMLNamespaceCommand(definition, prefix, uri));
        }
    }
    result.getItems().add(item);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition)

Example 9 with CompletionItem

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

the class ActionScriptTextDocumentService method addEventMetadataToAutoCompleteMXML.

private void addEventMetadataToAutoCompleteMXML(TypeScope typeScope, String prefix, CompletionList result) {
    ArrayList<String> eventNames = new ArrayList<>();
    IDefinition definition = typeScope.getDefinition();
    while (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        IMetaTag[] eventMetaTags = definition.getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_EVENT);
        for (IMetaTag eventMetaTag : eventMetaTags) {
            String eventName = eventMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_EVENT_NAME);
            if (eventNames.contains(eventName)) {
                //avoid duplicates!
                continue;
            }
            eventNames.add(eventName);
            IDefinition eventDefinition = currentProject.resolveSpecifier(classDefinition, eventName);
            if (eventDefinition == null) {
                continue;
            }
            CompletionItem item = new CompletionItem();
            item.setKind(CompletionItemKind.Field);
            item.setLabel(eventName);
            if (prefix != null) {
                item.setInsertText(prefix + IMXMLCoreConstants.colon + eventName);
            }
            item.setDetail(getDefinitionDetail(eventDefinition));
            result.getItems().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)

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