use of org.apache.flex.compiler.problems.ICompilerProblem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method getProject.
private FlexProject getProject() {
clearInvisibleCompilationUnits();
refreshProjectOptions();
if (currentProjectOptions == null) {
cleanupCurrentProject();
return null;
}
FlexProject project = null;
if (currentProject == null) {
project = new FlexProject(new Workspace());
project.setProblems(new ArrayList<>());
currentWorkspace = project.getWorkspace();
fileSpecGetter = new LanguageServerFileSpecGetter(currentWorkspace, sourceByPath);
} else {
//clear all old problems because they won't be cleared automatically
currentProject.getProblems().clear();
return currentProject;
}
CompilerOptions compilerOptions = currentProjectOptions.compilerOptions;
Configurator configurator = null;
if (isJSConfig(currentProjectOptions)) {
configurator = new Configurator(JSGoogConfiguration.class);
} else //swf only
{
configurator = new Configurator(Configuration.class);
}
configurator.setToken(TOKEN_CONFIGNAME, currentProjectOptions.config);
ProjectType type = currentProjectOptions.type;
String[] files = currentProjectOptions.files;
String additionalOptions = currentProjectOptions.additionalOptions;
ArrayList<String> combinedOptions = new ArrayList<>();
if (compilerOptions.swfExternalLibraryPath != null) {
//this isn't available in the configurator, so add it like the additionalOptions
appendPathCompilerOptions("--swf-external-library-path+=", compilerOptions.swfExternalLibraryPath, combinedOptions);
}
if (compilerOptions.swfLibraryPath != null) {
appendPathCompilerOptions("--swf-library-path+=", compilerOptions.swfLibraryPath, combinedOptions);
}
if (compilerOptions.jsExternalLibraryPath != null) {
appendPathCompilerOptions("--js-external-library-path+=", compilerOptions.jsExternalLibraryPath, combinedOptions);
}
if (compilerOptions.jsLibraryPath != null) {
appendPathCompilerOptions("--js-library-path+=", compilerOptions.jsLibraryPath, combinedOptions);
}
if (additionalOptions != null) {
//split the additionalOptions into separate values so that we can
//pass them in as String[], as the compiler expects.
Matcher matcher = additionalOptionsPattern.matcher(additionalOptions);
while (matcher.find()) {
String option = matcher.group();
combinedOptions.add(option);
}
}
//not all framework SDKs support a theme (such as Adobe's AIR SDK), so
//we clear it for the editor to avoid a missing spark.css file.
combinedOptions.add("-theme=");
if (type.equals(ProjectType.LIB)) {
configurator.setConfiguration(combinedOptions.toArray(new String[combinedOptions.size()]), ICompilerSettingsConstants.INCLUDE_CLASSES_VAR, false);
} else // app
{
combinedOptions.addAll(Arrays.asList(files));
configurator.setConfiguration(combinedOptions.toArray(new String[combinedOptions.size()]), ICompilerSettingsConstants.FILE_SPECS_VAR);
}
//this needs to be set before applyToProject() so that it's in the
//configuration buffer before addExternalLibraryPath() is called
configurator.setExcludeNativeJSLibraries(false);
boolean result = configurator.applyToProject(project);
Collection<ICompilerProblem> problems = configurator.getConfigurationProblems();
if (problems.size() > 0) {
Map<URI, PublishDiagnosticsParams> filesMap = new HashMap<>();
for (ICompilerProblem problem : problems) {
URI uri = Paths.get(problem.getSourcePath()).toUri();
configProblemTracker.trackFileWithProblems(uri);
PublishDiagnosticsParams params = null;
if (filesMap.containsKey(uri)) {
params = filesMap.get(uri);
} else {
params = new PublishDiagnosticsParams();
params.setUri(uri.toString());
params.setDiagnostics(new ArrayList<>());
filesMap.put(uri, params);
}
addCompilerProblem(problem, params);
}
if (languageClient != null) {
filesMap.values().forEach(languageClient::publishDiagnostics);
}
//we don't return null if result is not false
}
configProblemTracker.cleanUpStaleProblems();
if (!result) {
return null;
}
//because setting some values checks the cfgbuf
if (compilerOptions.sourcePath != null) {
configurator.addSourcePath(compilerOptions.sourcePath);
}
if (compilerOptions.libraryPath != null) {
configurator.addLibraryPath(compilerOptions.libraryPath);
}
if (compilerOptions.externalLibraryPath != null) {
configurator.addExternalLibraryPath(compilerOptions.externalLibraryPath);
}
if (compilerOptions.namespaceMappings != null) {
configurator.setNamespaceMappings(compilerOptions.namespaceMappings);
}
if (compilerOptions.defines != null) {
configurator.setDefineDirectives(compilerOptions.defines);
}
if (currentProjectOptions.type.equals(ProjectType.LIB)) {
if (compilerOptions.includeClasses != null) {
configurator.setIncludeClasses(compilerOptions.includeClasses);
}
if (compilerOptions.includeNamespaces != null) {
configurator.setIncludeNamespaces(compilerOptions.includeNamespaces);
}
if (compilerOptions.includeSources != null) {
configurator.setIncludeSources(compilerOptions.includeSources);
}
}
configurator.enableDebugging(compilerOptions.debug, null);
configurator.showActionScriptWarnings(compilerOptions.warnings);
result = configurator.applyToProject(project);
if (!result) {
return null;
}
ITarget.TargetType targetType = ITarget.TargetType.SWF;
if (currentProjectOptions.type.equals(ProjectType.LIB)) {
targetType = ITarget.TargetType.SWC;
}
ITargetSettings targetSettings = configurator.getTargetSettings(targetType);
if (targetSettings == null) {
System.err.println("Failed to get compile settings for +configname=" + currentProjectOptions.config + ".");
return null;
}
project.setTargetSettings(targetSettings);
return project;
}
use of org.apache.flex.compiler.problems.ICompilerProblem 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);
}
}
use of org.apache.flex.compiler.problems.ICompilerProblem 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;
}
use of org.apache.flex.compiler.problems.ICompilerProblem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method checkCompilationUnitForAllProblems.
private PublishDiagnosticsParams checkCompilationUnitForAllProblems(ICompilationUnit unit) {
URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
publish.setDiagnostics(new ArrayList<>());
publish.setUri(uri.toString());
codeProblemTracker.trackFileWithProblems(uri);
ArrayList<ICompilerProblem> problems = new ArrayList<>();
try {
unit.waitForBuildFinish(problems, ITarget.TargetType.SWF);
for (ICompilerProblem problem : problems) {
addCompilerProblem(problem, publish);
}
} catch (Exception e) {
System.err.println("Exception during waitForBuildFinish(): " + e);
e.printStackTrace();
Diagnostic diagnostic = createDiagnosticWithoutRange();
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("A fatal error occurred while checking a file for problems: " + unit.getAbsoluteFilename());
publish.getDiagnostics().add(diagnostic);
}
return publish;
}
Aggregations