use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method getEmbeddedActionScriptNodeInMXMLTag.
private IASNode getEmbeddedActionScriptNodeInMXMLTag(IMXMLTagData tag, int offset, TextDocumentPositionParams position) {
IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(tag, currentOffset);
if (attributeData != null) {
//some attributes can have ActionScript completion, such as
//events and properties with data binding
IClassDefinition tagDefinition = (IClassDefinition) currentProject.resolveXMLNameToDefinition(tag.getXMLName(), tag.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) {
return containingNode;
}
}
return eventNode;
} else {
IASNode offsetNode = getOffsetNode(position);
if (offsetNode instanceof IMXMLInstanceNode) {
IMXMLInstanceNode instanceNode = (IMXMLInstanceNode) offsetNode;
IMXMLPropertySpecifierNode propertyNode = instanceNode.getPropertySpecifierNode(attributeData.getShortName());
if (propertyNode != null) {
for (int i = 0, count = propertyNode.getChildCount(); i < count; i++) {
IMXMLNode propertyChild = (IMXMLNode) propertyNode.getChild(i);
if (propertyChild instanceof IMXMLConcatenatedDataBindingNode) {
IMXMLConcatenatedDataBindingNode dataBinding = (IMXMLConcatenatedDataBindingNode) propertyChild;
for (int j = 0, childCount = dataBinding.getChildCount(); j < childCount; j++) {
IASNode dataBindingChild = dataBinding.getChild(i);
if (dataBindingChild.contains(currentOffset) && dataBindingChild instanceof IMXMLSingleDataBindingNode) {
//we'll parse this in a moment, as if it were
//a direct child of the property specifier
propertyChild = (IMXMLSingleDataBindingNode) dataBindingChild;
break;
}
}
}
if (propertyChild instanceof IMXMLSingleDataBindingNode) {
IMXMLSingleDataBindingNode dataBinding = (IMXMLSingleDataBindingNode) propertyChild;
IASNode containingNode = dataBinding.getExpressionNode().getContainingNode(currentOffset);
//we found the correct expression, but due to a bug
//in the compiler its line and column positions
//will be wrong. the resulting completion is too
//quirky, so this feature will be completed later.
//return containingNode;
}
}
}
}
//nothing possible for this attribute
}
}
return null;
}
use of org.apache.flex.compiler.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlHover.
private CompletableFuture<Hover> mxmlHover(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
if (definition == null) {
return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
}
if (isInsideTagPrefix(offsetTag, currentOffset)) {
//inside the prefix
String prefix = offsetTag.getPrefix();
Hover result = new Hover();
List<String> contents = new ArrayList<>();
StringBuilder detailBuilder = new StringBuilder();
detailBuilder.append(MARKDOWN_CODE_BLOCK_MXML_START);
if (prefix.length() > 0) {
detailBuilder.append("xmlns:" + prefix + "=\"" + offsetTag.getURI() + "\"");
} else {
detailBuilder.append("xmlns=\"" + offsetTag.getURI() + "\"");
}
detailBuilder.append(MARKDOWN_CODE_BLOCK_END);
contents.add(detailBuilder.toString());
result.setContents(contents);
return CompletableFuture.completedFuture(result);
}
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.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method addStyleMetadataToAutoCompleteMXML.
private void addStyleMetadataToAutoCompleteMXML(TypeScope typeScope, String prefix, CompletionList result) {
ArrayList<String> styleNames = new ArrayList<>();
IDefinition definition = typeScope.getDefinition();
List<CompletionItem> items = result.getItems();
while (definition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) definition;
IMetaTag[] styleMetaTags = typeScope.getDefinition().getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_STYLE);
for (IMetaTag styleMetaTag : styleMetaTags) {
String styleName = styleMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_STYLE_NAME);
if (styleNames.contains(styleName)) {
//avoid duplicates!
continue;
}
styleNames.add(styleName);
IDefinition styleDefinition = currentProject.resolveSpecifier(classDefinition, styleName);
if (styleDefinition == null) {
continue;
}
boolean foundExisting = false;
for (CompletionItem item : items) {
if (item.getLabel().equals(styleName)) {
//we want to avoid adding a duplicate item with the same
//name. if there's a conflict, the compiler will know
//how to handle it.
foundExisting = true;
break;
}
}
if (foundExisting) {
break;
}
CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Field);
item.setLabel(styleName);
if (prefix != null) {
item.setInsertText(prefix + IMXMLCoreConstants.colon + styleName);
}
item.setDetail(getDefinitionDetail(styleDefinition));
items.add(item);
}
definition = classDefinition.resolveBaseClass(currentProject);
}
}
use of org.apache.flex.compiler.definitions.IDefinition 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.definitions.IDefinition in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlRename.
private CompletableFuture<WorkspaceEdit> mxmlRename(RenameParams params, IMXMLTagData offsetTag) {
IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
if (definition != null) {
if (isInsideTagPrefix(offsetTag, currentOffset)) {
//ignore the tag's prefix
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
WorkspaceEdit result = renameDefinition(definition, params.getNewName());
return CompletableFuture.completedFuture(result);
}
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<>()));
}
Aggregations