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