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);
}
}
Aggregations