if there are two existing import statements that import from the same file, don't show two same items in import popup (PY-9138)

This commit is contained in:
Dmitry Jemerov
2013-11-04 18:55:29 +01:00
parent 363b5a6fe9
commit 7b29990a99
@@ -183,10 +183,27 @@ public class PythonReferenceImporter implements ReferenceImporter {
PsiElement source) {
PsiElement sourceFile = PyUtil.turnDirIntoInit(source);
if (sourceFile instanceof PyFileImpl) {
PyReferenceExpression importReferenceExpression = importElement.getImportReferenceExpression();
if (importReferenceExpression != null) {
seenFileNames.add(importReferenceExpression.getReferencedName());
PyStatement importStatement = importElement.getContainingImportStatement();
String refName = null;
if (importStatement instanceof PyFromImportStatement) {
QualifiedName qName = ((PyFromImportStatement)importStatement).getImportSourceQName();
if (qName != null) {
refName = qName.toString();
}
}
else {
QualifiedName importReferenceQName = importElement.getImportedQName();
if (importReferenceQName != null) {
refName = importReferenceQName.toString();
}
}
if (refName != null) {
if (seenFileNames.contains(refName)) {
return existingImportFile;
}
seenFileNames.add(refName);
}
PyFileImpl importSourceFile = (PyFileImpl)sourceFile;
PsiElement res = importSourceFile.findExportedName(refText);
// allow importing from this source if it either declares the name itself or represents a higher-level package that reexports the name