use of org.eclipse.lsp4j.Location in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlReferences.
private CompletableFuture<List<? extends Location>> mxmlReferences(ReferenceParams params, IMXMLTagData offsetTag) {
IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
if (definition != null) {
if (isInsideTagPrefix(offsetTag, currentOffset)) {
//ignore the tag's prefix
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Location> result = new ArrayList<>();
referencesForDefinition(definition, result);
return CompletableFuture.completedFuture(result);
}
//finally, check if we're looking for references to a tag's id
IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attributeData == null || !attributeData.getName().equals(IMXMLLanguageConstants.ATTRIBUTE_ID)) {
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
Path path = LanguageServerUtils.getPathFromLanguageServerURI(params.getTextDocument().getUri());
if (path == null) {
//this probably shouldn't happen, but check just to be safe
return CompletableFuture.completedFuture(Collections.emptyList());
}
ICompilationUnit unit = getCompilationUnit(path);
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
}
if (definitions == null || definitions.size() == 0) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
IClassDefinition classDefinition = null;
for (IDefinition currentDefinition : definitions) {
if (currentDefinition instanceof IClassDefinition) {
classDefinition = (IClassDefinition) currentDefinition;
break;
}
}
if (classDefinition == null) {
//this probably shouldn't happen, but check just to be safe
return CompletableFuture.completedFuture(Collections.emptyList());
}
IASScope scope = classDefinition.getContainedScope();
for (IDefinition currentDefinition : scope.getAllLocalDefinitions()) {
if (currentDefinition.getBaseName().equals(attributeData.getRawValue())) {
definition = currentDefinition;
break;
}
}
if (definition == null) {
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Location> result = new ArrayList<>();
referencesForDefinition(definition, result);
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.Location in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method referencesForDefinition.
private void referencesForDefinition(IDefinition definition, List<Location> result) {
for (ICompilationUnit compilationUnit : compilationUnits) {
if (compilationUnit == null || compilationUnit instanceof SWCCompilationUnit) {
continue;
}
if (compilationUnit.getAbsoluteFilename().endsWith(MXML_EXTENSION)) {
IMXMLDataManager mxmlDataManager = currentWorkspace.getMXMLDataManager();
MXMLData mxmlData = (MXMLData) mxmlDataManager.get(fileSpecGetter.getFileSpecification(compilationUnit.getAbsoluteFilename()));
IMXMLTagData rootTag = mxmlData.getRootTag();
if (rootTag != null) {
ArrayList<ISourceLocation> units = new ArrayList<>();
findMXMLUnits(mxmlData.getRootTag(), definition, units);
for (ISourceLocation otherUnit : units) {
Location location = LanguageServerUtils.getLocationFromSourceLocation(otherUnit);
if (location == null) {
continue;
}
result.add(location);
}
}
}
IASNode ast;
try {
ast = compilationUnit.getSyntaxTreeRequest().get().getAST();
} catch (Exception e) {
continue;
}
ArrayList<IIdentifierNode> identifiers = new ArrayList<>();
findIdentifiers(ast, definition, identifiers);
for (IIdentifierNode otherNode : identifiers) {
Location location = LanguageServerUtils.getLocationFromSourceLocation(otherNode);
if (location == null) {
continue;
}
result.add(location);
}
}
}
use of org.eclipse.lsp4j.Location in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method definitionToSymbol.
private SymbolInformation definitionToSymbol(IDefinition definition) {
SymbolInformation symbol = new SymbolInformation();
if (definition instanceof IClassDefinition) {
symbol.setKind(SymbolKind.Class);
} else if (definition instanceof IInterfaceDefinition) {
symbol.setKind(SymbolKind.Interface);
} else if (definition instanceof IFunctionDefinition) {
IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
if (functionDefinition.isConstructor()) {
symbol.setKind(SymbolKind.Constructor);
} else {
symbol.setKind(SymbolKind.Function);
}
} else if (definition instanceof IFunctionDefinition) {
symbol.setKind(SymbolKind.Function);
} else if (definition instanceof IConstantDefinition) {
symbol.setKind(SymbolKind.Constant);
} else {
symbol.setKind(SymbolKind.Variable);
}
symbol.setName(definition.getQualifiedName());
Location location = new Location();
String sourcePath = definition.getSourcePath();
if (sourcePath == null) {
//I'm not sure why getSourcePath() can sometimes return null, but
//getContainingFilePath() seems to work as a fallback -JT
sourcePath = definition.getContainingFilePath();
}
Path definitionPath = Paths.get(sourcePath);
location.setUri(definitionPath.toUri().toString());
Position start = new Position();
Position end = new Position();
//getLine() and getColumn() may include things like metadata, so it
//makes more sense to jump to where the definition name starts
int line = definition.getNameLine();
int column = definition.getNameColumn();
if (line < 0 || column < 0) {
//this is not ideal, but MXML variable definitions may not have a
//node associated with them, so we need to figure this out from the
//offset instead of a pre-calculated line and column -JT
String code = sourceByPath.get(Paths.get(sourcePath));
offsetToLineAndCharacter(new StringReader(code), definition.getNameStart(), start);
end.setLine(start.getLine());
end.setCharacter(start.getCharacter());
} else {
start.setLine(line);
start.setCharacter(column);
end.setLine(line);
end.setCharacter(column);
}
Range range = new Range();
range.setStart(start);
range.setEnd(end);
location.setRange(range);
symbol.setLocation(location);
return symbol;
}
use of org.eclipse.lsp4j.Location in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptDefinitionWithNode.
private CompletableFuture<List<? extends Location>> actionScriptDefinitionWithNode(TextDocumentPositionParams position, IASNode offsetNode) {
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(Collections.emptyList());
}
IDefinition definition = null;
if (offsetNode instanceof IIdentifierNode) {
IIdentifierNode expressionNode = (IIdentifierNode) offsetNode;
definition = expressionNode.resolve(currentProject);
}
if (definition == null) {
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
List<Location> result = new ArrayList<>();
resolveDefinition(definition, result);
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.Location in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptReferencesWithNode.
private CompletableFuture<List<? extends Location>> actionScriptReferencesWithNode(ReferenceParams params, IASNode offsetNode) {
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(Collections.emptyList());
}
if (offsetNode instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
IDefinition resolved = identifierNode.resolve(currentProject);
if (resolved == null) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
List<Location> result = new ArrayList<>();
referencesForDefinition(resolved, result);
return CompletableFuture.completedFuture(result);
}
//definition referenced at the current position.
return CompletableFuture.completedFuture(Collections.emptyList());
}
Aggregations