use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class GradleArgumentsCompletionProvider method getVariants.
protected List<LookupElement> getVariants(@NotNull final DataNode<ProjectData> projectDataNode, @NotNull final String modulePath) {
final DataNode<ModuleData> moduleDataNode = findModuleDataNode(projectDataNode, modulePath);
if (moduleDataNode == null) {
return Collections.emptyList();
}
final ModuleData moduleData = moduleDataNode.getData();
final boolean isRoot = projectDataNode.getData().getLinkedExternalProjectPath().equals(moduleData.getLinkedExternalProjectPath());
final Collection<DataNode<TaskData>> tasks = ExternalSystemApiUtil.getChildren(moduleDataNode, ProjectKeys.TASK);
List<LookupElement> elements = ContainerUtil.newArrayListWithCapacity(tasks.size());
for (DataNode<TaskData> taskDataNode : tasks) {
final TaskData taskData = taskDataNode.getData();
elements.add(LookupElementBuilder.create(taskData.getName()).withIcon(ExternalSystemIcons.Task));
if (!taskData.isInherited()) {
elements.add(LookupElementBuilder.create((isRoot ? ':' : moduleData.getId() + ':') + taskData.getName()).withIcon(ExternalSystemIcons.Task));
}
}
return elements;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class CompletionResultSet method addAllElements.
public void addAllElements(@NotNull final Iterable<? extends LookupElement> elements) {
int seldomCounter = 0;
for (LookupElement element : elements) {
seldomCounter++;
addElement(element);
if (seldomCounter % 1000 == 0) {
ProgressManager.checkCanceled();
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class LegacyCompletionContributor method completeReference.
public static boolean completeReference(final CompletionParameters parameters, final CompletionResultSet result) {
final CompletionData completionData = getCompletionData(parameters);
if (completionData == null) {
return false;
}
final Ref<Boolean> hasVariants = Ref.create(false);
processReferences(parameters, result, (reference, resultSet) -> {
final Set<LookupElement> lookupSet = new LinkedHashSet<>();
completionData.completeReference(reference, lookupSet, parameters.getPosition(), parameters.getOriginalFile());
for (final LookupElement item : lookupSet) {
if (resultSet.getPrefixMatcher().prefixMatches(item)) {
if (!item.isValid()) {
LOG.error(completionData + " has returned an invalid lookup element " + item + " of " + item.getClass() + " in " + parameters.getOriginalFile() + " of " + parameters.getOriginalFile().getClass() + "; reference=" + reference + " of " + reference.getClass());
}
hasVariants.set(true);
resultSet.addElement(item);
}
}
});
return hasVariants.get().booleanValue();
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class WordCompletionContributor method addValuesFromOtherStringLiterals.
private static void addValuesFromOtherStringLiterals(CompletionResultSet result, CompletionParameters parameters, final Set<String> realExcludes, PsiElement position) {
ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(position.getLanguage());
if (definition == null) {
return;
}
final ElementPattern<PsiElement> pattern = psiElement().withElementType(definition.getStringLiteralElements());
final PsiElement localString = PsiTreeUtil.findFirstParent(position, false, element -> pattern.accepts(element));
if (localString == null) {
return;
}
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(localString);
if (manipulator == null) {
return;
}
int offset = manipulator.getRangeInElement(localString).getStartOffset();
PsiFile file = position.getContainingFile();
final CompletionResultSet fullStringResult = result.withPrefixMatcher(file.getText().substring(offset + localString.getTextRange().getStartOffset(), parameters.getOffset()));
file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element == localString) {
return;
}
if (pattern.accepts(element)) {
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement each) {
String valueText = ElementManipulators.getValueText(each);
if (StringUtil.isNotEmpty(valueText) && !realExcludes.contains(valueText)) {
final LookupElement item = LookupElementBuilder.create(valueText);
fullStringResult.addElement(item);
}
}
});
return;
}
super.visitElement(element);
}
});
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class LiftShorterItemsClassifier method addElement.
@Override
public void addElement(@NotNull LookupElement added, @NotNull ProcessingContext context) {
myCount++;
for (String string : CompletionUtil.iterateLookupStrings(added)) {
if (string.length() == 0)
continue;
myElements.putValue(string, added);
mySortedStrings.add(string);
final NavigableSet<String> after = mySortedStrings.tailSet(string, false);
for (String s : after) {
if (!s.startsWith(string)) {
break;
}
for (LookupElement longer : myElements.get(s)) {
updateLongerItem(added, longer);
}
}
}
super.addElement(added, context);
calculateToLift(added);
}
Aggregations