Search in sources :

Example 6 with IASScope

use of org.apache.flex.compiler.scopes.IASScope in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method classDefinitionToConstructor.

private IFunctionDefinition classDefinitionToConstructor(IClassDefinition definition) {
    IASScope scope = definition.getContainedScope();
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition localDefinition : definitions) {
        if (localDefinition instanceof IFunctionDefinition) {
            IFunctionDefinition functionDefinition = (IFunctionDefinition) localDefinition;
            if (functionDefinition.isConstructor()) {
                return functionDefinition;
            }
        }
    }
    return null;
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 7 with IASScope

use of org.apache.flex.compiler.scopes.IASScope in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method documentSymbol.

/**
     * Searches by name for a symbol in a specific document (not the whole
     * workspace)
     */
@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams params) {
    TextDocumentIdentifier textDocument = params.getTextDocument();
    Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
    if (path == null) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    ICompilationUnit unit = getCompilationUnit(path);
    if (unit == null) {
        //we couldn't find a compilation unit with the specified path
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    IASScope[] scopes;
    try {
        scopes = unit.getFileScopeRequest().get().getScopes();
    } catch (Exception e) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<SymbolInformation> result = new ArrayList<>();
    for (IASScope scope : scopes) {
        scopeToSymbols(scope, result);
    }
    return CompletableFuture.completedFuture(result);
}
Also used : Path(java.nio.file.Path) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IASScope(org.apache.flex.compiler.scopes.IASScope) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with IASScope

use of org.apache.flex.compiler.scopes.IASScope in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method workspaceSymbol.

/**
     * Searches by name for a symbol in the workspace.
     */
public CompletableFuture<List<? extends SymbolInformation>> workspaceSymbol(WorkspaceSymbolParams params) {
    if (compilationUnits == null) {
        //if we haven't successfully compiled the project, we can't do this
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<SymbolInformation> result = new ArrayList<>();
    String query = params.getQuery();
    for (ICompilationUnit unit : compilationUnits) {
        if (unit == null || unit instanceof SWCCompilationUnit) {
            continue;
        }
        IASScope[] scopes;
        try {
            scopes = unit.getFileScopeRequest().get().getScopes();
        } catch (Exception e) {
            return CompletableFuture.completedFuture(Collections.emptyList());
        }
        for (IASScope scope : scopes) {
            querySymbolsInScope(query, scope, result);
        }
    }
    return CompletableFuture.completedFuture(result);
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASScope(org.apache.flex.compiler.scopes.IASScope) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with IASScope

use of org.apache.flex.compiler.scopes.IASScope in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method addMembersForMXMLTypeToAutoComplete.

private void addMembersForMXMLTypeToAutoComplete(IClassDefinition definition, IMXMLTagData offsetTag, boolean includePrefix, CompletionList result) {
    ICompilationUnit unit = getCompilationUnit(Paths.get(offsetTag.getSourcePath()));
    if (unit == null) {
        return;
    }
    IASScope[] scopes;
    try {
        scopes = unit.getFileScopeRequest().get().getScopes();
    } catch (Exception e) {
        return;
    }
    if (scopes != null && scopes.length > 0) {
        String propertyElementPrefix = null;
        if (includePrefix) {
            String prefix = offsetTag.getPrefix();
            if (prefix.length() > 0) {
                propertyElementPrefix = prefix;
            }
        }
        TypeScope typeScope = (TypeScope) definition.getContainedScope();
        ASScope scope = (ASScope) scopes[0];
        addDefinitionsInTypeScopeToAutoCompleteMXML(typeScope, scope, propertyElementPrefix, result);
        addStyleMetadataToAutoCompleteMXML(typeScope, propertyElementPrefix, result);
        addEventMetadataToAutoCompleteMXML(typeScope, propertyElementPrefix, result);
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IASScope(org.apache.flex.compiler.scopes.IASScope) IASScope(org.apache.flex.compiler.scopes.IASScope) ASScope(org.apache.flex.compiler.internal.scopes.ASScope) TypeScope(org.apache.flex.compiler.internal.scopes.TypeScope) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

IASScope (org.apache.flex.compiler.scopes.IASScope)9 IDefinition (org.apache.flex.compiler.definitions.IDefinition)6 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 ConcurrentModificationException (java.util.ConcurrentModificationException)4 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)4 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)4 ArrayList (java.util.ArrayList)3 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)3 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)3 Path (java.nio.file.Path)2 IPackageDefinition (org.apache.flex.compiler.definitions.IPackageDefinition)2 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)2 ASScope (org.apache.flex.compiler.internal.scopes.ASScope)2 TypeScope (org.apache.flex.compiler.internal.scopes.TypeScope)2 IScopedNode (org.apache.flex.compiler.tree.as.IScopedNode)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)1 IGetterDefinition (org.apache.flex.compiler.definitions.IGetterDefinition)1 ISetterDefinition (org.apache.flex.compiler.definitions.ISetterDefinition)1