fix incorrect path calculation in auto-import

This commit is contained in:
Dmitry Jemerov
2011-05-18 16:25:05 +02:00
parent a2465ccf22
commit b491f4dc74
6 changed files with 11 additions and 1 deletions
@@ -112,7 +112,7 @@ public class PythonReferenceImporter implements ReferenceImporter {
if (isTopLevel(symbol)) { // we only want top-level symbols
PsiFileSystemItem srcfile = symbol instanceof PsiFileSystemItem ? ((PsiFileSystemItem)symbol).getParent() : symbol.getContainingFile();
if (srcfile != null && srcfile != existing_import_file && srcfile != node.getContainingFile()) {
PyQualifiedName import_path = ResolveImportUtil.findCanonicalImportPath(symbol, node);
PyQualifiedName import_path = ResolveImportUtil.findCanonicalImportPath(srcfile, node);
if (import_path != null && !seen_file_names.contains(import_path.toString())) {
// a new, valid hit
fix.addImport(symbol, srcfile, import_path, proposeAsName(node.getContainingFile(), ref_text, import_path));
@@ -0,0 +1 @@
<warning descr="Unresolved reference 'baz'">baz</warning>.quux()
@@ -0,0 +1,3 @@
from importFromModule.foo import baz
baz.quux()
@@ -0,0 +1 @@
def quux(): pass
@@ -31,6 +31,11 @@ public class PyQuickFixTest extends PyLightFixtureTestCase {
doInspectionTest(new String[] { "AddImportDocComment.py", "ImportTarget.py" }, PyUnresolvedReferencesInspection.class, PyBundle.message("ACT.NAME.use.import"), true, true);
}
public void testImportFromModule() {
doInspectionTest(new String[] { "importFromModule/foo/bar.py", "importFromModule/foo/baz.py", "importFromModule/foo/__init__.py" },
PyUnresolvedReferencesInspection.class, PyBundle.message("ACT.NAME.use.import"), true, true);
}
public void testQualifyByImport() {
final PyCodeInsightSettings settings = PyCodeInsightSettings.getInstance();
boolean oldPreferFrom = settings.PREFER_FROM_IMPORT;