Search in sources :

Example 1 with ASParser

use of org.apache.flex.compiler.internal.parsing.as.ASParser in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method checkFilePathForSyntaxProblems.

private void checkFilePathForSyntaxProblems(Path path) {
    URI uri = path.toUri();
    PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
    ArrayList<Diagnostic> diagnostics = new ArrayList<>();
    publish.setDiagnostics(diagnostics);
    publish.setUri(uri.toString());
    codeProblemTracker.trackFileWithProblems(uri);
    ASParser parser = null;
    Reader reader = getReaderForPath(path);
    if (reader != null) {
        StreamingASTokenizer tokenizer = StreamingASTokenizer.createForRepairingASTokenizer(reader, uri.toString(), null);
        ASToken[] tokens = tokenizer.getTokens(reader);
        if (tokenizer.hasTokenizationProblems()) {
            for (ICompilerProblem problem : tokenizer.getTokenizationProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
        RepairingTokenBuffer buffer = new RepairingTokenBuffer(tokens);
        Workspace workspace = new Workspace();
        workspace.endRequest();
        parser = new ASParser(workspace, buffer);
        FileNode node = new FileNode(workspace);
        try {
            parser.file(node);
        } catch (Exception e) {
            parser = null;
            System.err.println("Failed to parse file (" + path.toString() + "): " + e);
            e.printStackTrace();
        }
        //if an error occurred above, parser will be null
        if (parser != null) {
            for (ICompilerProblem problem : parser.getSyntaxProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
    }
    Diagnostic diagnostic = createDiagnosticWithoutRange();
    diagnostic.setSeverity(DiagnosticSeverity.Information);
    if (reader == null) {
        //the file does not exist
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("File not found: " + path.toAbsolutePath().toString() + ". Error checking disabled.");
    } else if (parser == null) {
        //something terrible happened, and this is the best we can do
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("A fatal error occurred while checking for simple syntax problems.");
    } else if (currentProjectOptions == null) {
        //something went wrong while attempting to load and parse the
        //project configuration.
        diagnostic.setMessage("Failed to load project configuration options. Error checking disabled, except for simple syntax problems.");
    } else {
        //we loaded and parsed the project configuration, so something went
        //wrong while checking for errors.
        diagnostic.setMessage("A fatal error occurred while checking for errors. Error checking disabled, except for simple syntax problems.");
    }
    diagnostics.add(diagnostic);
    codeProblemTracker.cleanUpStaleProblems();
    if (languageClient != null) {
        languageClient.publishDiagnostics(publish);
    }
}
Also used : StreamingASTokenizer(org.apache.flex.compiler.internal.parsing.as.StreamingASTokenizer) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ASToken(org.apache.flex.compiler.internal.parsing.as.ASToken) RepairingTokenBuffer(org.apache.flex.compiler.internal.parsing.as.RepairingTokenBuffer) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ASParser(org.apache.flex.compiler.internal.parsing.as.ASParser) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) FileNode(org.apache.flex.compiler.internal.tree.as.FileNode) IFileNode(org.apache.flex.compiler.tree.as.IFileNode) Workspace(org.apache.flex.compiler.internal.workspaces.Workspace) IWorkspace(org.apache.flex.compiler.workspaces.IWorkspace)

Aggregations

BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 ASParser (org.apache.flex.compiler.internal.parsing.as.ASParser)1 ASToken (org.apache.flex.compiler.internal.parsing.as.ASToken)1 RepairingTokenBuffer (org.apache.flex.compiler.internal.parsing.as.RepairingTokenBuffer)1 StreamingASTokenizer (org.apache.flex.compiler.internal.parsing.as.StreamingASTokenizer)1 FileNode (org.apache.flex.compiler.internal.tree.as.FileNode)1 Workspace (org.apache.flex.compiler.internal.workspaces.Workspace)1 ICompilerProblem (org.apache.flex.compiler.problems.ICompilerProblem)1 IFileNode (org.apache.flex.compiler.tree.as.IFileNode)1 IWorkspace (org.apache.flex.compiler.workspaces.IWorkspace)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1