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;
}
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));
}
}
}
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());
}
Aggregations