From 7b29990a99d803ffc688e02557648d34c69b6d41 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 4 Nov 2013 13:17:06 +0100 Subject: [PATCH] if there are two existing import statements that import from the same file, don't show two same items in import popup (PY-9138) --- .../imports/PythonReferenceImporter.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java b/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java index da6a6ab54981..06e4f8962c1e 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java @@ -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