use of com.intellij.codeInsight.lookup.LookupElement in project Intellij-Plugin by getgauge.
the class StepCompletionProvider method addCompletions.
@Override
public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
resultSet.stopHere();
final String prefix = getPrefix(parameters);
resultSet = resultSet.withPrefixMatcher(new GaugePrefixMatcher(prefix));
Module moduleForPsiElement = GaugeUtil.moduleForPsiElement(parameters.getPosition());
if (moduleForPsiElement == null) {
return;
}
for (Type item : getStepsInModule(moduleForPsiElement)) {
LookupElementBuilder element = LookupElementBuilder.create(item.getText()).withTypeText(item.getType(), true);
element = element.withInsertHandler((InsertionContext context1, LookupElement item1) -> {
if (context1.getCompletionChar() == '\t') {
context1.getDocument().insertString(context1.getEditor().getCaretModel().getOffset(), "\n");
PsiDocumentManager.getInstance(context1.getProject()).commitDocument(context1.getDocument());
}
PsiElement stepElement = context1.getFile().findElementAt(context1.getStartOffset()).getParent();
final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(stepElement);
replaceStepParamElements(prefix, context1, stepElement, templateBuilder);
templateBuilder.run(context1.getEditor(), false);
});
resultSet.addElement(element);
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-plugins by JetBrains.
the class LanguageListCompletionContributor method doFillVariants.
private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
for (LookupElement lookupElement : lookups) {
result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
new MyInsertHandler(parameters).handleInsert(context, item);
lookupElement.handleInsert(context);
}));
}
}
for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
final Language language = entry.getValue();
final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
final LanguageFileType fileType = language1.getAssociatedFileType();
return fileType != null ? fileType.getIcon() : null;
})).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
result.addElement(lookupElementBuilder);
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoReferenceCompletionProvider method addElement.
private static void addElement(@NotNull PsiElement o, @NotNull ResolveState state, boolean forTypes, boolean vendoringEnabled, @NotNull Set<String> processedNames, @NotNull CompletionResultSet set) {
LookupElement lookup = createLookupElement(o, state, forTypes, vendoringEnabled);
if (lookup != null) {
String lookupString = lookup.getLookupString();
if (!processedNames.contains(lookupString)) {
set.addElement(lookup);
processedNames.add(lookupString);
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoKeywordCompletionProvider method createKeywordLookupElement.
@NotNull
private LookupElement createKeywordLookupElement(@NotNull String keyword) {
InsertHandler<LookupElement> insertHandler = ObjectUtils.chooseNotNull(myInsertHandler, createTemplateBasedInsertHandler("go_lang_" + keyword));
LookupElement result = createKeywordLookupElement(keyword, myPriority, insertHandler);
return myCompletionPolicy != null ? myCompletionPolicy.applyPolicy(result) : result;
}
use of com.intellij.codeInsight.lookup.LookupElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCompletionTest method testPointerSpecType.
public void testPointerSpecType() {
myFixture.configureByText("foo.go", "package main; type a struct{};" + "func main() {q1, q2:=&a{};q<caret>}");
myFixture.completeBasic();
LookupElement first = ArrayUtil.getFirstElement(myFixture.getLookupElements());
assertNotNull(first);
LookupElementPresentation presentation = new LookupElementPresentation();
first.renderElement(presentation);
assertEquals("*main.a", presentation.getTypeText());
}
Aggregations