Search in sources :

Example 1 with SuggestionService

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)));
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) Optional.ofNullable(java.util.Optional.ofNullable) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) SuggestionService(org.talend.sdk.component.intellij.service.SuggestionService) PropertyKeyImpl(com.intellij.lang.properties.psi.impl.PropertyKeyImpl) PsiUtil.truncateIdeaDummyIdentifier(org.talend.sdk.component.intellij.util.PsiUtil.truncateIdeaDummyIdentifier) Objects(java.util.Objects) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PropertyValueImpl(com.intellij.lang.properties.psi.impl.PropertyValueImpl) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) IProperty(com.intellij.lang.properties.IProperty) ServiceManager(com.intellij.openapi.components.ServiceManager) PsiUtil.findModule(org.talend.sdk.component.intellij.util.PsiUtil.findModule) CompletionProvider(com.intellij.codeInsight.completion.CompletionProvider) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) PropertiesFileImpl(com.intellij.lang.properties.psi.impl.PropertiesFileImpl) Project(com.intellij.openapi.project.Project) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) IProperty(com.intellij.lang.properties.IProperty) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SuggestionService(org.talend.sdk.component.intellij.service.SuggestionService) PsiUtil.findModule(org.talend.sdk.component.intellij.util.PsiUtil.findModule) Module(com.intellij.openapi.module.Module) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement) PropertyValueImpl(com.intellij.lang.properties.psi.impl.PropertyValueImpl) PropertyKeyImpl(com.intellij.lang.properties.psi.impl.PropertyKeyImpl)

Aggregations

CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionProvider (com.intellij.codeInsight.completion.CompletionProvider)1 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFileImpl (com.intellij.lang.properties.psi.impl.PropertiesFileImpl)1 PropertyKeyImpl (com.intellij.lang.properties.psi.impl.PropertyKeyImpl)1 PropertyValueImpl (com.intellij.lang.properties.psi.impl.PropertyValueImpl)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 ProcessingContext (com.intellij.util.ProcessingContext)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors.toList (java.util.stream.Collectors.toList)1 SuggestionService (org.talend.sdk.component.intellij.service.SuggestionService)1 PsiUtil.findModule (org.talend.sdk.component.intellij.util.PsiUtil.findModule)1 PsiUtil.truncateIdeaDummyIdentifier (org.talend.sdk.component.intellij.util.PsiUtil.truncateIdeaDummyIdentifier)1