void (PsiFile existingImportFile) { Project project = myNode.getProject(); GlobalSearchScope scope = PySearchUtilBase.defaultSuggestionScope(myNode); List<PsiNamedElement> symbols = new ArrayList<>(PyClassNameIndex.find(myRefText, project, scope)); if (!isQualifier()) { symbols.addAll(PyFunctionNameIndex.find(myRefText, project, scope)); } symbols.addAll(PyVariableNameIndex.find(myRefText, project, scope)); if (isPossibleModuleReference()) { symbols.addAll(findImportableModules(myRefText, false, scope)); String packageQName = PyPackageAliasesProvider.commonImportAliases.get(myRefText); if (packageQName != null) { symbols.addAll(findImportableModules(packageQName, true, scope)); } } for (PsiNamedElement symbol : symbols) { if (isIndexableTopLevel(symbol)) { // we only want top-level symbols PsiFileSystemItem srcfile = symbol instanceof PsiFileSystemItem ? ((PsiFileSystemItem)symbol).getParent() : symbol.getContainingFile(); if (srcfile != null && isAcceptableForImport(existingImportFile, srcfile)) { QualifiedName importPath = QualifiedNameFinder.findCanonicalImportPath(symbol, myNode); if (importPath == null) { continue; } if (symbol instanceof PsiFileSystemItem) { importPath = importPath.removeTail(1); } String name = PyUtil.getElementNameWithoutExtension(symbol); final String symbolImportQName = importPath.append(name).toString(); if (seenCandidateNames.add(symbolImportQName)) { String alias = name.equals(myRefText) ? null : myRefText; fix.addImport(symbol, srcfile, importPath, alias); } } } } }