@Override protected boolean accept(String s) { return emptyPrefix || matcher.prefixMatches(s) || packagesWithAliases.contains(substringBefore(s, '.')); } }, scope, idFilter);
@Override public boolean process(@NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { GoFunctionDeclaration function = (GoFunctionDeclaration)element; double priority = importData.exists ? GoCompletionUtil.FUNCTION_PRIORITY : GoCompletionUtil.NOT_IMPORTED_FUNCTION_PRIORITY; result.addElement(GoCompletionUtil.createFunctionOrMethodLookupElement(function, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.FUNCTION_INSERT_HANDLER, priority)); return true; }
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet result) { PsiElement position = completionParameters.getPosition(); if (!AppEngineExtension.isAppEngineContext(position)) { return; } } }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { GoImportString importString = PsiTreeUtil.getParentOfType(parameters.getPosition(), GoImportString.class); if (importString == null) return; String path = importString.getPath(); if (path.startsWith("./") || path.startsWith("../")) return; TextRange pathRange = importString.getPathTextRange().shiftRight(importString.getTextRange().getStartOffset()); String newPrefix = parameters.getEditor().getDocument().getText(TextRange.create(pathRange.getStartOffset(), parameters.getOffset())); result = result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(newPrefix)); Module module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile()); if (module != null) { addCompletions(result, module, parameters.getOriginalFile(), GoUtil.goPathResolveScope(module, parameters.getOriginalFile()), false); } }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet set) { GoReferenceExpressionBase expression = PsiTreeUtil.getParentOfType(parameters.getPosition(), GoReferenceExpressionBase.class); PsiFile originalFile = parameters.getOriginalFile(); if (expression != null) { fillVariantsByReference(expression.getReference(), originalFile, set.withPrefixMatcher(createPrefixMatcher(set.getPrefixMatcher()))); } PsiElement parent = parameters.getPosition().getParent(); if (parent != null) { fillVariantsByReference(parent.getReference(), originalFile, set.withPrefixMatcher(createPrefixMatcher(set.getPrefixMatcher()))); } }
@Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { super.fillCompletionVariants(parameters, result); PsiElement position = parameters.getPosition(); if (insideGoOrDeferStatements().accepts(position) || anonymousFunction().accepts(position)) { InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_func"); result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("func", CONTEXT_KEYWORD_PRIORITY, insertHandler)); } if (referenceExpression().accepts(position)) { InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_struct"); result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("struct", CONTEXT_KEYWORD_PRIORITY, insertHandler)); } }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { PsiElement current = parameters.getPosition(); if (current.getParent() instanceof IgnoreSyntax && current.getPrevSibling() != null) { result.addAllElements(SYNTAX_ELEMENTS); } } }
private static void addLookupElement(@NotNull String lookupString, int initialPriority, @NotNull Set<String> allTestFunctionNames, @NotNull CompletionResultSet result) { int priority = initialPriority; if (allTestFunctionNames.contains(lookupString)) { priority -= 5; lookupString = UniqueNameGenerator.generateUniqueName(lookupString, allTestFunctionNames); } result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(lookupString) .withInsertHandler(GenerateTestInsertHandler.INSTANCE), priority)); }
private CompletionResultSet adjustMatcher(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, @NotNull PsiElement parent) { int startOffset = parent.getTextRange().getStartOffset(); String newPrefix = parameters.getEditor().getDocument().getText(TextRange.create(startOffset, parameters.getOffset())); return result.withPrefixMatcher(createPrefixMatcher(newPrefix)); } });
private void doInsert(InsertionContext context, @NotNull LookupElement item, @Nullable GoSignature signature) { int paramsCount = signature != null ? signature.getParameters().getParameterDeclarationList().size() : 0; InsertHandler<LookupElement> handler = paramsCount == 0 ? ParenthesesInsertHandler.NO_PARAMETERS : ParenthesesInsertHandler.WITH_PARAMETERS; handler.handleInsert(context, item); if (signature != null) { AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null); } } };
@NotNull public static LookupElement createLabelLookupElement(@NotNull GoLabelDefinition l, @NotNull String lookupString) { return PrioritizedLookupElement.withPriority(LookupElementBuilder.createWithSmartPointer(lookupString, l).withIcon(GoIcons.LABEL), LABEL_PRIORITY); }
@NotNull public static CamelHumpMatcher createPrefixMatcher(@NotNull PrefixMatcher original) { return createPrefixMatcher(original.getPrefix()); }
@Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { PsiElement element = item.getPsiElement(); if (element instanceof GoNamedElement) { if (myClass != null && myDelegate != null && myClass.isInstance(element)) { myDelegate.handleInsert(context, item); } autoImport(context, (GoNamedElement)element); } }
@Nullable private PsiDirectory getDirectory() { PsiElement originalElement = CompletionUtil.getOriginalElement(getElement()); PsiFile file = originalElement != null ? originalElement.getContainingFile() : getElement().getContainingFile(); return file.getParent(); } }
@Override public boolean process(@NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { double priority = importData.exists ? GoCompletionUtil.VAR_PRIORITY : GoCompletionUtil.NOT_IMPORTED_VAR_PRIORITY; result.addElement(GoCompletionUtil.createVariableLikeLookupElement(element, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.SIMPLE_INSERT_HANDLER, priority)); return true; }
@NotNull private static LookupElement packageLookup(@NotNull String packageName, int priority) { LookupElement element = withPriority(LookupElementBuilder.create(packageName), priority); return AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(element); }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { for (String keyword : myKeywords) { result.addElement(createKeywordLookupElement(keyword)); } }
@NotNull public static LookupElement createVariableLikeLookupElement(@NotNull GoNamedElement v, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> insertHandler, double priority) { return PrioritizedLookupElement.withPriority(LookupElementBuilder.createWithSmartPointer(lookupString, v) .withRenderer(Lazy.VARIABLE_RENDERER) .withInsertHandler(insertHandler), priority); }
@NotNull public static LookupElement createFunctionOrMethodLookupElement(@NotNull GoNamedSignatureOwner f, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> h, double priority) { return PrioritizedLookupElement.withPriority(LookupElementBuilder .createWithSmartPointer(lookupString, f) .withRenderer(Lazy.FUNCTION_RENDERER) .withInsertHandler(h != null ? h : Lazy.VARIABLE_OR_FUNCTION_INSERT_HANDLER), priority); }
public static LookupElement createKeywordLookupElement(@NotNull String keyword, int priority, @Nullable InsertHandler<LookupElement> insertHandler) { LookupElementBuilder builder = LookupElementBuilder.create(keyword).withBoldness(true).withInsertHandler(insertHandler); return PrioritizedLookupElement.withPriority(builder, priority); }