use of org.eclipse.lsp4j.CompletionItem 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.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteImport.
private void autoCompleteImport(String importName, CompletionList result) {
List<CompletionItem> items = result.getItems();
for (ICompilationUnit unit : compilationUnits) {
if (unit == null) {
continue;
}
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
continue;
}
for (IDefinition definition : definitions) {
if (definition instanceof ITypeDefinition) {
String qualifiedName = definition.getQualifiedName();
if (qualifiedName.equals(definition.getBaseName())) {
//this definition is top-level. no import required.
continue;
}
if (qualifiedName.startsWith(importName)) {
int index = importName.lastIndexOf(".");
if (index != -1) {
qualifiedName = qualifiedName.substring(index + 1);
}
index = qualifiedName.indexOf(".");
if (index > 0) {
qualifiedName = qualifiedName.substring(0, index);
}
CompletionItem item = new CompletionItem();
item.setLabel(qualifiedName);
if (definition.getBaseName().equals(qualifiedName)) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
if (typeDefinition instanceof IInterfaceDefinition) {
item.setKind(CompletionItemKind.Interface);
} else if (typeDefinition instanceof IClassDefinition) {
item.setKind(CompletionItemKind.Class);
} else {
item.setKind(CompletionItemKind.Text);
}
} else {
item.setKind(CompletionItemKind.Text);
}
if (!items.contains(item)) {
items.add(item);
}
}
}
}
}
}
use of org.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompletePackageBlock.
private void autoCompletePackageBlock(CompletionList result) {
String expectedPackage = getExpectedPackage(currentUnit);
StringBuilder builder = new StringBuilder();
builder.append("package");
if (expectedPackage.length() > 0) {
builder.append(" ");
builder.append(expectedPackage);
}
builder.append("\n{\n\t\n}");
CompletionItem packageItem = new CompletionItem();
packageItem.setLabel(builder.toString());
result.getItems().add(packageItem);
}
use of org.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method autoCompleteDefinitions.
private void autoCompleteDefinitions(CompletionList result, boolean forMXML, boolean typesOnly, String packageName, IDefinition definitionToSkip) {
String skipQualifiedName = null;
if (definitionToSkip != null) {
skipQualifiedName = definitionToSkip.getQualifiedName();
}
for (ICompilationUnit unit : compilationUnits) {
if (unit == null) {
continue;
}
Collection<IDefinition> definitions = null;
try {
definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
} catch (Exception e) {
//safe to ignore
continue;
}
for (IDefinition definition : definitions) {
boolean isType = definition instanceof ITypeDefinition;
if (!typesOnly || isType) {
if (packageName == null || definition.getPackageName().equals(packageName)) {
if (skipQualifiedName != null && skipQualifiedName.equals(definition.getQualifiedName())) {
continue;
}
if (isType) {
IMetaTag excludeClassMetaTag = definition.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDECLASS);
if (excludeClassMetaTag != null) {
//skip types with [ExcludeClass] metadata
continue;
}
}
if (forMXML && isType) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
addMXMLTypeDefinitionAutoComplete(typeDefinition, result);
} else {
addDefinitionAutoCompleteActionScript(definition, result);
}
}
}
}
}
if (packageName == null || packageName.equals("")) {
CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Class);
item.setLabel(IASKeywordConstants.VOID);
result.getItems().add(item);
}
}
use of org.eclipse.lsp4j.CompletionItem in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method addDefinitionAutoCompleteActionScript.
private void addDefinitionAutoCompleteActionScript(IDefinition definition, CompletionList result) {
if (definition.getBaseName().startsWith(VECTOR_HIDDEN_PREFIX)) {
return;
}
CompletionItem item = new CompletionItem();
item.setKind(getDefinitionKind(definition));
item.setDetail(getDefinitionDetail(definition));
item.setLabel(definition.getBaseName());
boolean isInPackage = !definition.getQualifiedName().equals(definition.getBaseName());
if (isInPackage) {
Command command = createImportCommand(definition);
if (command != null) {
item.setCommand(command);
}
}
result.getItems().add(item);
}
Aggregations