use of org.talend.sdk.component.intellij.service.SuggestionService in project component-runtime by Talend.
the class PropertiesCompletionProvider method addCompletions.
@Override
protected void addCompletions(final CompletionParameters completionParameters, final ProcessingContext processingContext, final CompletionResultSet resultSet) {
final PsiElement element = completionParameters.getPosition();
if (!LeafPsiElement.class.isInstance(element)) {
// ignore comment
return;
}
final Project project = element.getProject();
final Module module = findModule(element);
final SuggestionService service = ServiceManager.getService(project, SuggestionService.class);
if ((module == null || !service.isSupported(completionParameters))) {
// limit suggestion to Messages
return;
}
if (PropertyValueImpl.class.isInstance(element)) {
ofNullable(PropertyValueImpl.class.cast(element).getPrevSibling()).map(PsiElement::getPrevSibling).map(PsiElement::getText).ifPresent(text -> resultSet.addAllElements(service.computeValueSuggestions(text)));
} else if (PropertyKeyImpl.class.isInstance(element)) {
final List<String> containerElements = PropertiesFileImpl.class.cast(element.getContainingFile()).getProperties().stream().filter(p -> !Objects.equals(p.getKey(), element.getText())).map(IProperty::getKey).collect(toList());
resultSet.addAllElements(service.computeKeySuggestions(project, module, getPropertiesPackage(module, completionParameters), containerElements, truncateIdeaDummyIdentifier(element)));
}
}
Aggregations