Search in sources :

Example 16 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-community by JetBrains.

the class PythonCompletionWeigher method weigh.

@Override
public Comparable weigh(@NotNull final LookupElement element, @NotNull final CompletionLocation location) {
    if (!PsiUtilCore.findLanguageFromElement(location.getCompletionParameters().getPosition()).isKindOf(PythonLanguage.getInstance())) {
        return 0;
    }
    final String name = element.getLookupString();
    final LookupElementPresentation presentation = LookupElementPresentation.renderElement(element);
    // move dict keys to the top
    if ("dict key".equals(presentation.getTypeText())) {
        return element.getLookupString().length();
    }
    if (name.startsWith(DOUBLE_UNDER)) {
        if (// __foo__ is lowest
        name.endsWith(DOUBLE_UNDER))
            // __foo__ is lowest
            return -10;
        else
            // __foo is lower than normal
            return -5;
    }
    // default
    return 0;
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation)

Example 17 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-community by JetBrains.

the class ZenCodingTemplate method addCompletions.

@Override
public void addCompletions(CompletionParameters parameters, CompletionResultSet result) {
    if (!parameters.isAutoPopup()) {
        return;
    }
    PsiFile file = parameters.getPosition().getContainingFile();
    int offset = parameters.getOffset();
    Editor editor = parameters.getEditor();
    ZenCodingGenerator generator = findApplicableDefaultGenerator(CustomTemplateCallback.getContext(file, offset), false);
    if (generator != null && generator.hasCompletionItem()) {
        final CollectCustomTemplateCallback callback = new CollectCustomTemplateCallback(editor, file);
        final String templatePrefix = computeTemplateKeyWithoutContextChecking(callback);
        if (templatePrefix != null) {
            List<TemplateImpl> regularTemplates = TemplateManagerImpl.listApplicableTemplates(file, offset, false);
            boolean regularTemplateWithSamePrefixExists = !ContainerUtil.filter(regularTemplates, template -> templatePrefix.equals(template.getKey())).isEmpty();
            result = result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(templatePrefix));
            result.restartCompletionOnPrefixChange(StandardPatterns.string().startsWith(templatePrefix));
            if (!regularTemplateWithSamePrefixExists) {
                // exclude perfect matches with existing templates because LiveTemplateCompletionContributor handles it
                final Collection<SingleLineEmmetFilter> extraFilters = ContainerUtil.newLinkedList(new SingleLineEmmetFilter());
                try {
                    expand(templatePrefix, callback, generator, extraFilters, false, 0);
                } catch (EmmetException ignore) {
                }
                final TemplateImpl template = callback.getGeneratedTemplate();
                if (template != null) {
                    template.setKey(templatePrefix);
                    template.setDescription(template.getTemplateText());
                    final CustomLiveTemplateLookupElement lookupElement = new CustomLiveTemplateLookupElement(this, template.getKey(), template.getKey(), template.getDescription(), !LiveTemplateCompletionContributor.shouldShowAllTemplates(), true) {

                        @Override
                        public void renderElement(LookupElementPresentation presentation) {
                            super.renderElement(presentation);
                            presentation.setTailText("\t Emmet abbreviation", true);
                        }
                    };
                    result.addElement(lookupElement);
                }
            }
        } else if (result.getPrefixMatcher().getPrefix().isEmpty()) {
            result.restartCompletionOnPrefixChange(StandardPatterns.string().longerThan(0));
        }
    }
}
Also used : SingleLineEmmetFilter(com.intellij.codeInsight.template.emmet.filters.SingleLineEmmetFilter) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) PsiFile(com.intellij.psi.PsiFile) XmlZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator) ZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator) Editor(com.intellij.openapi.editor.Editor)

Example 18 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-elixir by KronicDeth.

the class CallDefinitionClauseTest method testIssue457EqualName.

public void testIssue457EqualName() {
    String name = "foo";
    LookupElement lookupElement = lookupElement(name);
    LookupElementPresentation lookupElementPresentation = new LookupElementPresentation();
    lookupElement.renderElement(lookupElementPresentation);
    assertEquals(name, lookupElementPresentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)18 LookupElement (com.intellij.codeInsight.lookup.LookupElement)10 LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)2 RealLookupElementPresentation (com.intellij.codeInsight.lookup.RealLookupElementPresentation)2 SingleLineEmmetFilter (com.intellij.codeInsight.template.emmet.filters.SingleLineEmmetFilter)1 XmlZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator)1 ZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)1 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Editor (com.intellij.openapi.editor.Editor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 JBList (com.intellij.ui.components.JBList)1 ThrowableRunnable (com.intellij.util.ThrowableRunnable)1 HashSet (com.intellij.util.containers.HashSet)1