PY-28341 Already used entries don't removed from completion list

Entries that were used in code remain in the completion list.
Return type of PyQualifiedReference updated to reflect the fact that it
returns PyTargetExpression's only.
This commit is contained in:
Anton Bragin
2018-04-10 14:16:53 +03:00
parent 1d0bb28d91
commit d2061e69f7
5 changed files with 22 additions and 15 deletions
@@ -282,24 +282,17 @@ public class PyQualifiedReference extends PyReferenceImpl {
final PyQualifiedExpression qualifierExpression = (PyQualifiedExpression)qualifier;
final QualifiedName qualifiedName = qualifierExpression.asQualifiedName();
if (qualifiedName != null) {
final Collection<PyExpression> attrs = collectAssignedAttributes(qualifiedName, qualifier);
for (PyExpression ex : attrs) {
final String name = ex.getName();
final Collection<PyTargetExpression> attrs = collectAssignedAttributes(qualifiedName, qualifier);
for (PyTargetExpression expression : attrs) {
final String name = expression.getName();
if (name != null && name.endsWith(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED)) {
continue;
}
if (ex instanceof PsiNamedElement && qualifierType instanceof PyClassType && name != null) {
variants.add(LookupElementBuilder.createWithSmartPointer(name, ex)
if (qualifierType instanceof PyClassType && name != null) {
variants.add(LookupElementBuilder.createWithSmartPointer(name, expression)
.withTypeText(qualifierType.getName())
.withIcon(PlatformIcons.FIELD_ICON));
}
if (ex instanceof PyReferenceExpression) {
PyReferenceExpression refExpr = (PyReferenceExpression)ex;
namesAlready.add(refExpr.getReferencedName());
}
else if (ex instanceof PyTargetExpression) {
PyTargetExpression targetExpr = (PyTargetExpression)ex;
namesAlready.add(targetExpr.getName());
namesAlready.add(name);
}
}
}
@@ -414,10 +407,10 @@ public class PyQualifiedReference extends PyReferenceImpl {
* Can be used for completion.
*/
@NotNull
public static Collection<PyExpression> collectAssignedAttributes(@NotNull final QualifiedName qualifierQName,
public static Collection<PyTargetExpression> collectAssignedAttributes(@NotNull final QualifiedName qualifierQName,
@NotNull final PsiElement anchor) {
final Set<String> names = new HashSet<>();
final List<PyExpression> results = new ArrayList<>();
final List<PyTargetExpression> results = new ArrayList<>();
for (ScopeOwner owner = ScopeUtil.getScopeOwner(anchor); owner != null; owner = ScopeUtil.getScopeOwner(owner)) {
final Scope scope = ControlFlowCache.getScope(owner);
for (final PyTargetExpression target : scope.getTargetExpressions()) {
@@ -0,0 +1,4 @@
import m1
m1.a
m1.a = 0
@@ -0,0 +1,4 @@
import m1
m1.<caret>
m1.a = 0
@@ -0,0 +1 @@
a = 1
@@ -1335,6 +1335,11 @@ public class PythonCompletionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON34, this::assertSingleVariantInExtendedCompletion);
}
// PY-28341
public void testCompletionForUsedAttribute() {
doMultiFileTest();
}
// PY-28103
public void testPrintFunctionWithoutFuture() {
final List<String> suggested = doTestByText("pr<caret>");