@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 public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { PsiElement position = parameters.getPosition(); PsiFile file = parameters.getOriginalFile(); ASTNode node = position.getNode(); if (file instanceof GoFile && position.getParent() instanceof GoPackageClause && node.getElementType() == GoTypes.IDENTIFIER) { boolean isTestFile = GoTestFinder.isTestFile(file); PsiDirectory directory = file.getParent(); String currentPackageName = ((GoFile)file).getPackageName(); Collection<String> packagesInDirectory = GoPackageUtil.getAllPackagesInDirectory(directory, null, true); for (String packageName : packagesInDirectory) { if (!packageName.equals(currentPackageName)) { result.addElement(packageLookup(packageName, GoCompletionUtil.PACKAGE_PRIORITY - 1)); } if (isTestFile) { result.addElement(packageLookup(packageName + GoConstants.TEST_SUFFIX, GoCompletionUtil.PACKAGE_PRIORITY)); } } if (directory != null && ContainerUtil.filter(directory.getFiles(), Conditions.instanceOf(GoFile.class)).size() == 1) { String packageFromDirectory = GoPsiImplUtil.getLocalPackageName(directory.getName()); if (!packageFromDirectory.isEmpty()) { result.addElement(packageLookup(packageFromDirectory, GoCompletionUtil.PACKAGE_PRIORITY - 1)); } } result.addElement(packageLookup(GoConstants.MAIN, GoCompletionUtil.PACKAGE_PRIORITY - 2)); } super.fillCompletionVariants(parameters, result); }
/** * Run all contributors until any of them returns false or the list is exhausted. If from parameter is not null, contributors * will be run starting from the next one after that. */ public static void getVariantsFromContributors(final CompletionParameters parameters, final String prefix, final CompletionContributor from, final Consumer<CompletionResult> consumer) { final List<CompletionContributor> contributors = CompletionContributor.forParameters(parameters); for (int i = contributors.indexOf(from) + 1; i < contributors.size(); i++) { final CompletionContributor contributor = contributors.get(i); CompletionResultSet result = createResultSet(parameters, prefix, consumer, contributor); contributor.fillCompletionVariants(parameters, result); if (result.isStopped()) { return; } } }