fix off-by-one error in counting target directory for relative imports (part of PY-2816)

This commit is contained in:
Dmitry Jemerov
2011-02-22 19:18:37 +01:00
parent 288072a3cd
commit 14626e2e8e
7 changed files with 12 additions and 3 deletions
@@ -146,7 +146,7 @@ public class PyImportReferenceImpl extends PyReferenceImpl {
}
public Object[] execute() {
int relative_level = 0;
int relative_level = -1;
Condition<PsiElement> node_filter = new PyResolveUtil.FilterNameNotIn(myNamesAlready);
InsertHandler<LookupElement> insertHandler = null;
@@ -208,7 +208,7 @@ public class PyImportReferenceImpl extends PyReferenceImpl {
}
}
// look at dir by level
if (myCurrentFile != null && (relative_level > 0 || !ResolveImportUtil.isAbsoluteImportEnabledFor(myCurrentFile))) {
if (myCurrentFile != null && (relative_level >= 0 || !ResolveImportUtil.isAbsoluteImportEnabledFor(myCurrentFile))) {
PyQualifiedName thisQName = ResolveImportUtil.findShortestImportableQName(myCurrentFile.getContainingDirectory());
if (thisQName == null) {
fillFromDir(ResolveImportUtil.stepBackFrom(myCurrentFile, relative_level), insertHandler);
@@ -219,7 +219,7 @@ public class PyImportReferenceImpl extends PyReferenceImpl {
}
}
}
if (relative_level == 0) {
if (relative_level == -1) {
fillFromQName(PyQualifiedName.fromComponents(), insertHandler);
}
@@ -0,0 +1 @@
from .string import <caret>
@@ -0,0 +1 @@
from .s<caret>
@@ -275,4 +275,11 @@ public class PythonCompletionTest extends PyLightFixtureTestCase {
public void testSuperClassAttributesNoCompletionInFunc() {
doTest();
}
public void testRelativeImport() { // PY-2816
myFixture.copyDirectoryToProject("completion/relativeImport", "relativeImport");
myFixture.configureByFile("relativeImport/pkg/main.py");
myFixture.completeBasic();
myFixture.checkResultByFile("completion/relativeImport/pkg/main.after.py");
}
}