Search in sources :

Example 11 with IASNode

use of org.apache.flex.compiler.tree.as.IASNode in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method checkFilePathForAllProblems.

private boolean checkFilePathForAllProblems(Path path, Boolean quick) {
    ICompilationUnit mainUnit = getCompilationUnit(path);
    if (mainUnit == null) {
        return false;
    }
    CompilerProject project = (CompilerProject) mainUnit.getProject();
    Collection<ICompilerProblem> fatalProblems = project.getFatalProblems();
    if (fatalProblems == null || fatalProblems.size() == 0) {
        fatalProblems = project.getProblems();
    }
    if (fatalProblems != null && fatalProblems.size() > 0) {
        URI uri = path.toUri();
        PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
        publish.setDiagnostics(new ArrayList<>());
        publish.setUri(uri.toString());
        codeProblemTracker.trackFileWithProblems(uri);
        for (ICompilerProblem problem : fatalProblems) {
            addCompilerProblem(problem, publish);
        }
        codeProblemTracker.cleanUpStaleProblems();
        if (languageClient != null) {
            languageClient.publishDiagnostics(publish);
        }
        return true;
    }
    IASNode ast = null;
    try {
        ast = mainUnit.getSyntaxTreeRequest().get().getAST();
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        return false;
    }
    if (ast == null) {
        return false;
    }
    Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
    try {
        if (quick) {
            PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(mainUnit);
            URI uri = Paths.get(mainUnit.getAbsoluteFilename()).toUri();
            files.put(uri, params);
        } else {
            boolean continueCheckingForErrors = true;
            while (continueCheckingForErrors) {
                try {
                    for (ICompilationUnit unit : compilationUnits) {
                        if (unit == null || unit instanceof SWCCompilationUnit) {
                            //compiled compilation units won't have problems
                            continue;
                        }
                        PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(unit);
                        URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
                        files.put(uri, params);
                    }
                    continueCheckingForErrors = false;
                } catch (ConcurrentModificationException e) {
                //when we finished building one of the compilation
                //units, more were added to the collection, so we need
                //to start over because we can't iterate over a modified
                //collection.
                }
            }
            //only clean up stale errors on a full check
            codeProblemTracker.cleanUpStaleProblems();
        }
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        e.printStackTrace();
        return false;
    }
    if (languageClient != null) {
        files.values().forEach(languageClient::publishDiagnostics);
    }
    return true;
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) ConcurrentModificationException(java.util.ConcurrentModificationException) HashMap(java.util.HashMap) CompilerProject(org.apache.flex.compiler.internal.projects.CompilerProject) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASNode(org.apache.flex.compiler.tree.as.IASNode) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Example 12 with IASNode

use of org.apache.flex.compiler.tree.as.IASNode in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method autoCompleteTypes.

private void autoCompleteTypes(IASNode withNode, CompletionList result) {
    //start by getting the types in scope
    IASNode node = withNode;
    do {
        //nodes to check
        if (node instanceof IScopedNode) {
            IScopedNode scopedNode = (IScopedNode) node;
            //include all members and local things that are in scope
            autoCompleteScope(scopedNode, true, result);
            break;
        }
        node = node.getParent();
    } while (node != null);
    autoCompleteDefinitions(result, false, true, null, null);
}
Also used : IScopedNode(org.apache.flex.compiler.tree.as.IScopedNode) IASNode(org.apache.flex.compiler.tree.as.IASNode)

Example 13 with IASNode

use of org.apache.flex.compiler.tree.as.IASNode in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getCompilationUnit.

private ICompilationUnit getCompilationUnit(Path path) {
    String absolutePath = path.toAbsolutePath().toString();
    currentUnit = null;
    currentProject = getProject();
    if (currentProject == null) {
        return null;
    }
    currentWorkspace = currentProject.getWorkspace();
    //we're going to start with the files passed into the compiler
    String[] files = currentProjectOptions.files;
    if (files != null) {
        for (int i = files.length - 1; i >= 0; i--) {
            String file = files[i];
            //a previous file may have created a compilation unit for the
            //current file, so use that, if available
            ICompilationUnit existingUnit = findCompilationUnit(file);
            if (existingUnit != null) {
                if (file.equals(absolutePath)) {
                    currentUnit = existingUnit;
                }
                continue;
            }
            IInvisibleCompilationUnit unit = currentProject.createInvisibleCompilationUnit(file, fileSpecGetter);
            if (unit == null) {
                System.err.println("Could not create compilation unit for file: " + file);
                continue;
            }
            invisibleUnits.add(unit);
            if (file.equals(absolutePath)) {
                currentUnit = unit;
            }
        }
    }
    compilationUnits = currentProject.getCompilationUnits();
    //if we didn't find the unit already, search the complete set of units
    if (currentUnit == null) {
        //might already be created
        for (ICompilationUnit unit : compilationUnits) {
            if (unit != null && unit.getAbsoluteFilename().equals(absolutePath)) {
                currentUnit = unit;
                break;
            }
        }
    }
    //if we still haven't found it, create it manually
    if (currentUnit == null) {
        //if all else fails, create the compilation unit manually
        IInvisibleCompilationUnit unit = currentProject.createInvisibleCompilationUnit(absolutePath, fileSpecGetter);
        if (unit == null) {
            System.err.println("Could not create compilation unit for file: " + absolutePath);
            return null;
        }
        invisibleUnits.add(unit);
        currentUnit = unit;
    }
    //for some reason, function nodes may not always be populated, but we
    //can force them to be populated
    IASNode ast = null;
    try {
        ast = currentUnit.getSyntaxTreeRequest().get().getAST();
    } catch (InterruptedException e) {
        System.err.println("Interrupted while getting AST");
    }
    if (ast instanceof IFileNode) {
        IFileNode fileNode = (IFileNode) ast;
        fileNode.populateFunctionNodes();
    }
    return currentUnit;
}
Also used : IInvisibleCompilationUnit(org.apache.flex.compiler.units.IInvisibleCompilationUnit) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IFileNode(org.apache.flex.compiler.tree.as.IFileNode) IASNode(org.apache.flex.compiler.tree.as.IASNode)

Example 14 with IASNode

use of org.apache.flex.compiler.tree.as.IASNode in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method rename.

/**
     * Renames a symbol at the specified document position.
     */
@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
    String textDocumentUri = params.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
    }
    IMXMLTagData offsetTag = getOffsetMXMLTag(params.getTextDocument(), params.getPosition());
    if (offsetTag != null) {
        IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, params.getTextDocument(), params.getPosition());
        if (embeddedNode != null) {
            return actionScriptRenameWithNode(params, embeddedNode);
        }
        //so that's why we call isMXMLTagValidForCompletion()
        if (isMXMLTagValidForCompletion(offsetTag)) {
            return mxmlRename(params, offsetTag);
        }
    }
    return actionScriptRename(params);
}
Also used : HashMap(java.util.HashMap) IASNode(org.apache.flex.compiler.tree.as.IASNode) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData)

Example 15 with IASNode

use of org.apache.flex.compiler.tree.as.IASNode in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method references.

/**
     * Finds all references of the definition referenced at the current position
     * in a text document. Does not necessarily get called where a definition is
     * defined, but may be at one of the references.
     */
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
    String textDocumentUri = params.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    IMXMLTagData offsetTag = getOffsetMXMLTag(params);
    if (offsetTag != null) {
        IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, params.getTextDocument(), params.getPosition());
        if (embeddedNode != null) {
            return actionScriptReferencesWithNode(params, embeddedNode);
        }
        //so that's why we call isMXMLTagValidForCompletion()
        if (isMXMLTagValidForCompletion(offsetTag)) {
            return mxmlReferences(params, offsetTag);
        }
    }
    return actionScriptReferences(params);
}
Also used : IASNode(org.apache.flex.compiler.tree.as.IASNode) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData)

Aggregations

IASNode (org.apache.flex.compiler.tree.as.IASNode)16 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)8 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)5 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)5 IDefinition (org.apache.flex.compiler.definitions.IDefinition)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ConcurrentModificationException (java.util.ConcurrentModificationException)3 HashMap (java.util.HashMap)3 SWCCompilationUnit (org.apache.flex.compiler.internal.units.SWCCompilationUnit)3 CompletionList (org.eclipse.lsp4j.CompletionList)3 URI (java.net.URI)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)2 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)2 MXMLData (org.apache.flex.compiler.internal.mxml.MXMLData)2 IMXMLDataManager (org.apache.flex.compiler.mxml.IMXMLDataManager)2 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)2 IExpressionNode (org.apache.flex.compiler.tree.as.IExpressionNode)2