public static void addCompletions(@NotNull CompletionResultSet result,
@NotNull Module module,
@Nullable PsiElement context,
@NotNull GlobalSearchScope scope,
boolean allowMain) {
Project project = module.getProject();
boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(module);
String contextImportPath = GoCompletionUtil.getContextImportPath(context, vendoringEnabled);
GoExcludedPathsSettings excludedSettings = GoExcludedPathsSettings.getInstance(project);
PsiFile contextFile = context != null ? context.getContainingFile() : null;
boolean testFileWithTestPackage = GoTestFinder.isTestFileWithTestPackage(contextFile);
for (VirtualFile file : FileTypeIndex.getFiles(GoFileType.INSTANCE, scope)) {
ProgressManager.checkCanceled();
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (!(psiFile instanceof GoFile)) continue;
PsiDirectory directory = psiFile.getContainingDirectory();
if (directory == null) continue;
GoFile goFile = (GoFile)psiFile;
if (!GoPsiImplUtil.canBeAutoImported(goFile, allowMain, module)) continue;
String importPath = goFile.getImportPath(vendoringEnabled);
if (StringUtil.isNotEmpty(importPath) && !excludedSettings.isExcluded(importPath)
&& (testFileWithTestPackage || !importPath.equals(contextImportPath))) {
result.addElement(GoCompletionUtil.createPackageLookupElement(importPath, contextImportPath, directory, false));
}
}
}
}