mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no stubs for variables in list comprehensions (PY-4029)
This commit is contained in:
@@ -8,6 +8,7 @@ import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.stubs.StubInputStream;
|
||||
import com.intellij.psi.stubs.StubOutputStream;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.psi.*;
|
||||
@@ -102,18 +103,21 @@ public class PyTargetExpressionElementType extends PyStubElementType<PyTargetExp
|
||||
}
|
||||
|
||||
public boolean shouldCreateStub(final ASTNode node) {
|
||||
if (PsiTreeUtil.getParentOfType(node.getPsi(), PyComprehensionElement.class, true, PyDocStringOwner.class) != null) {
|
||||
return false;
|
||||
}
|
||||
final ASTNode functionNode = TreeUtil.findParent(node, PyElementTypes.FUNCTION_DECLARATION);
|
||||
final ASTNode qualifierNode = node.findChildByType(PyElementTypes.REFERENCE_EXPRESSION);
|
||||
if (functionNode != null && qualifierNode != null) {
|
||||
final ASTNode parameterList = functionNode.findChildByType(PyElementTypes.PARAMETER_LIST);
|
||||
assert parameterList != null;
|
||||
final ASTNode[] children = parameterList.getChildren(PyElementTypes.FORMAL_PARAMETER_SET);
|
||||
if (children.length > 0 && children [0].getText().equals(qualifierNode.getText())) {
|
||||
if (children.length > 0 && children[0].getText().equals(qualifierNode.getText())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return functionNode == null && qualifierNode == null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexStub(PyTargetExpressionStub stub, IndexSink sink) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
print [xyzzy for xyzzy in range(1, 10)]
|
||||
@@ -316,9 +316,17 @@ public class PyStubsTest extends PyLightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testIfNameMain() { // PY-4008
|
||||
ensureVariableNotInIndex("xyzzy");
|
||||
}
|
||||
|
||||
public void testVariableInComprehension() { // PY-4029
|
||||
ensureVariableNotInIndex("xyzzy");
|
||||
}
|
||||
|
||||
private void ensureVariableNotInIndex(String name) {
|
||||
getTestFile();
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myFixture.getProject());
|
||||
Collection<PyTargetExpression> result = PyVariableNameIndex.find("xyzzy", myFixture.getProject(), scope);
|
||||
Collection<PyTargetExpression> result = PyVariableNameIndex.find(name, myFixture.getProject(), scope);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user