mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
when completing members of imported module, look at local imports, not only file-level ones (PY-3668)
This commit is contained in:
@@ -4,7 +4,9 @@ import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
@@ -51,7 +53,9 @@ public class PyImportedModuleType implements PyType {
|
||||
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
List<LookupElement> result = new ArrayList<LookupElement>();
|
||||
final List<PyImportElement> importTargets = myImportedModule.getContainingFile().getImportTargets();
|
||||
ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(location, ScopeOwner.class);
|
||||
assert scopeOwner != null;
|
||||
final List<PyImportElement> importTargets = PyModuleType.getVisibleImports(scopeOwner);
|
||||
final int imported = myImportedModule.getImportedPrefix().getComponentCount();
|
||||
for (PyImportElement importTarget : importTargets) {
|
||||
final PyQualifiedName qName = importTarget.getImportedQName();
|
||||
|
||||
@@ -167,7 +167,7 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<PyImportElement> getVisibleImports(@NotNull ScopeOwner owner) {
|
||||
public static List<PyImportElement> getVisibleImports(@NotNull ScopeOwner owner) {
|
||||
final List<PyImportElement> visibleImports = new ArrayList<PyImportElement>();
|
||||
PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() {
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def func():
|
||||
import foo.bar
|
||||
foo.bar
|
||||
@@ -0,0 +1,3 @@
|
||||
def func():
|
||||
import foo.bar
|
||||
foo.<caret>
|
||||
@@ -613,4 +613,11 @@ public class PythonCompletionTest extends PyTestCase {
|
||||
doTestByText("def foo(**<caret>)");
|
||||
myFixture.checkResult("def foo(**kwargs)");
|
||||
}
|
||||
|
||||
public void testLocalImportedModule() { // PY-3668
|
||||
myFixture.copyDirectoryToProject("completion/py3668", "");
|
||||
myFixture.configureByFile("py3668.py");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile("completion/py3668/py3668.after.py");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user