mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix off-by-one error in counting target directory for relative imports (part of PY-2816)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user