mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-22570 Filter out private names when collecting symbols imported via wildcard for code completion
This commit is contained in:
@@ -17,11 +17,12 @@ package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.scope.DelegatingScopeProcessor;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
@@ -161,7 +162,17 @@ public class PyFromImportStatementImpl extends PyBaseElementImpl<PyFromImportSta
|
||||
for (PsiElement target : targets) {
|
||||
final PsiElement importedFile = PyUtil.turnDirIntoInit(target);
|
||||
if (importedFile != null) {
|
||||
if (!importedFile.processDeclarations(processor, state, null, place)) {
|
||||
PsiScopeProcessor starImportableNamesProcessor = new DelegatingScopeProcessor(processor) {
|
||||
@Override
|
||||
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
|
||||
if (element instanceof PyElement && importedFile instanceof PyFile &&
|
||||
!PyUtil.isStarImportableFrom(StringUtil.notNullize(((PyElement)element).getName()), (PyFile)importedFile)) {
|
||||
return true;
|
||||
}
|
||||
return super.execute(element, state);
|
||||
}
|
||||
};
|
||||
if (!importedFile.processDeclarations(starImportableNamesProcessor, state, null, place)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from pkg import <caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
from .mod1 import *
|
||||
from .mod2 import *
|
||||
@@ -0,0 +1,2 @@
|
||||
foo = 1
|
||||
_foo = 2
|
||||
@@ -0,0 +1,4 @@
|
||||
__all__ = ['_bar']
|
||||
|
||||
bar = 1
|
||||
_bar = 2
|
||||
@@ -1105,6 +1105,15 @@ public class PythonCompletionTest extends PyTestCase {
|
||||
assertContainsElements(suggested, "baz");
|
||||
}
|
||||
|
||||
// PY-22570
|
||||
public void testNamesReexportedViaStarImport() {
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
myFixture.configureByFile("a.py");
|
||||
myFixture.completeBasic();
|
||||
final List<String> variants = myFixture.getLookupElementStrings();
|
||||
assertSameElements(variants, "mod1", "mod2", "foo", "_bar");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/completion";
|
||||
|
||||
Reference in New Issue
Block a user