use of org.apache.flex.compiler.tree.as.IIdentifierNode in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptRenameWithNode.
private CompletableFuture<WorkspaceEdit> actionScriptRenameWithNode(RenameParams params, IASNode offsetNode) {
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
IDefinition definition = null;
if (offsetNode instanceof IDefinitionNode) {
IDefinitionNode definitionNode = (IDefinitionNode) offsetNode;
IExpressionNode expressionNode = definitionNode.getNameExpressionNode();
definition = expressionNode.resolve(currentProject);
} else if (offsetNode instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
definition = identifierNode.resolve(currentProject);
}
if (definition == null) {
if (languageClient != null) {
MessageParams message = new MessageParams();
message.setType(MessageType.Info);
message.setMessage("You cannot rename this element.");
languageClient.showMessage(message);
}
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
WorkspaceEdit result = renameDefinition(definition, params.getNewName());
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.tree.as.IIdentifierNode in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method memberAccessToPackageName.
private String memberAccessToPackageName(IMemberAccessExpressionNode memberAccess) {
String result = null;
IExpressionNode rightOperand = memberAccess.getRightOperandNode();
if (!(rightOperand instanceof IIdentifierNode)) {
return null;
}
IExpressionNode leftOperand = memberAccess.getLeftOperandNode();
if (leftOperand instanceof IMemberAccessExpressionNode) {
result = memberAccessToPackageName((IMemberAccessExpressionNode) leftOperand);
} else if (leftOperand instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) leftOperand;
result = identifierNode.getName();
} else {
return null;
}
IIdentifierNode identifierNode = (IIdentifierNode) rightOperand;
return result + "." + identifierNode.getName();
}
use of org.apache.flex.compiler.tree.as.IIdentifierNode in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method findIdentifiers.
private void findIdentifiers(IASNode node, IDefinition definition, List<IIdentifierNode> result) {
if (node.isTerminal()) {
if (node instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) node;
if (identifierNode.resolve(currentProject) == definition) {
result.add(identifierNode);
}
}
return;
}
for (int i = 0, count = node.getChildCount(); i < count; i++) {
IASNode childNode = node.getChild(i);
findIdentifiers(childNode, definition, result);
}
}
use of org.apache.flex.compiler.tree.as.IIdentifierNode in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptHoverWithNode.
private CompletableFuture<Hover> actionScriptHoverWithNode(TextDocumentPositionParams position, IASNode offsetNode) {
IDefinition definition = null;
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
}
//any hover information for it.
if (definition == null && offsetNode instanceof IIdentifierNode && !(offsetNode instanceof INamespaceDecorationNode)) {
IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
definition = identifierNode.resolve(currentUnit.getProject());
}
if (definition == null) {
return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
}
Hover result = new Hover();
String detail = getDefinitionDetail(definition);
List<String> contents = new ArrayList<>();
contents.add(MARKDOWN_CODE_BLOCK_NEXTGENAS_START + detail + MARKDOWN_CODE_BLOCK_END);
result.setContents(contents);
return CompletableFuture.completedFuture(result);
}
use of org.apache.flex.compiler.tree.as.IIdentifierNode in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method signatureHelp.
/**
* Displays a function's parameters, including which one is currently
* active. Called automatically by VSCode any time that the user types "(",
* so be sure to check that a function call is actually happening at the
* current position.
*/
@Override
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams position) {
String textDocumentUri = position.getTextDocument().getUri();
if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
IASNode offsetNode = null;
IMXMLTagData offsetTag = getOffsetMXMLTag(position);
if (offsetTag != null) {
IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attributeData != null) {
//some attributes can have ActionScript completion, such as
//events and properties with data binding
IClassDefinition tagDefinition = (IClassDefinition) currentProject.resolveXMLNameToDefinition(offsetTag.getXMLName(), offsetTag.getMXMLDialect());
IDefinition attributeDefinition = currentProject.resolveSpecifier(tagDefinition, attributeData.getShortName());
if (attributeDefinition instanceof IEventDefinition) {
IMXMLInstanceNode mxmlNode = (IMXMLInstanceNode) getOffsetNode(position);
IMXMLEventSpecifierNode eventNode = mxmlNode.getEventSpecifierNode(attributeData.getShortName());
for (IASNode asNode : eventNode.getASNodes()) {
IASNode containingNode = getContainingNodeIncludingStart(asNode, currentOffset);
if (containingNode != null) {
offsetNode = containingNode;
}
}
if (offsetNode == null) {
offsetNode = eventNode;
}
}
}
}
if (offsetNode == null) {
offsetNode = getOffsetNode(position);
}
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
IFunctionCallNode functionCallNode = getAncestorFunctionCallNode(offsetNode);
IFunctionDefinition functionDefinition = null;
if (functionCallNode != null) {
IExpressionNode nameNode = functionCallNode.getNameNode();
IDefinition definition = nameNode.resolve(currentUnit.getProject());
if (definition instanceof IFunctionDefinition) {
functionDefinition = (IFunctionDefinition) definition;
} else if (definition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) definition;
functionDefinition = classDefinition.getConstructor();
} else if (nameNode instanceof IIdentifierNode) {
//special case for super()
IIdentifierNode identifierNode = (IIdentifierNode) nameNode;
if (identifierNode.getName().equals(IASKeywordConstants.SUPER)) {
ITypeDefinition typeDefinition = nameNode.resolveType(currentProject);
if (typeDefinition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) typeDefinition;
functionDefinition = classDefinitionToConstructor(classDefinition);
}
}
}
}
if (functionDefinition != null) {
SignatureHelp result = new SignatureHelp();
List<SignatureInformation> signatures = new ArrayList<>();
SignatureInformation signatureInfo = new SignatureInformation();
signatureInfo.setLabel(getSignatureLabel(functionDefinition));
List<ParameterInformation> parameters = new ArrayList<>();
for (IParameterDefinition param : functionDefinition.getParameters()) {
ParameterInformation paramInfo = new ParameterInformation();
paramInfo.setLabel(param.getBaseName());
parameters.add(paramInfo);
}
signatureInfo.setParameters(parameters);
signatures.add(signatureInfo);
result.setSignatures(signatures);
result.setActiveSignature(0);
int index = getFunctionCallNodeArgumentIndex(functionCallNode, offsetNode);
IParameterDefinition[] params = functionDefinition.getParameters();
int paramCount = params.length;
if (paramCount > 0 && index >= paramCount) {
if (index >= paramCount) {
IParameterDefinition lastParam = params[paramCount - 1];
if (lastParam.isRest()) {
//functions with rest parameters may accept any
//number of arguments, so continue to make the rest
//parameter active
index = paramCount - 1;
} else {
//if there's no rest parameter, and we're beyond the
//final parameter, none should be active
index = -1;
}
}
}
if (index != -1) {
result.setActiveParameter(index);
}
return CompletableFuture.completedFuture(result);
}
return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
Aggregations