From 50e1c91f8d2bb98bd03e8414bc607badad163c12 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Tue, 21 Aug 2018 04:33:41 +0300 Subject: [PATCH] PY-25260: Do not resolve qnames to empty folders. spam.eggs.ham may be resolved to "spam/eggs.py#def ham" But empty folder "spam/eggs/" may go before "eggs.py" and break resolve process. We exclude folders without of python files from test process. --- python/src/com/jetbrains/extenstions/QualifiedNameExt.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/extenstions/QualifiedNameExt.kt b/python/src/com/jetbrains/extenstions/QualifiedNameExt.kt index e5983864fdfc..706ede9fc3b6 100644 --- a/python/src/com/jetbrains/extenstions/QualifiedNameExt.kt +++ b/python/src/com/jetbrains/extenstions/QualifiedNameExt.kt @@ -30,6 +30,7 @@ import com.intellij.psi.util.QualifiedName import com.jetbrains.extensions.getSdk import com.jetbrains.python.PyNames import com.jetbrains.python.psi.PyClass +import com.jetbrains.python.psi.PyFile import com.jetbrains.python.psi.resolve.* import com.jetbrains.python.psi.stubs.PyModuleNameIndex import com.jetbrains.python.psi.types.TypeEvalContext @@ -134,7 +135,10 @@ fun QualifiedName.getElementAndResolvableName(context: QNameResolveContext, stop // Drill as deep, as we can while (currentName.componentCount > 0 && element == null) { if (psiDirectory != null) { // Resolve against folder - element = resolveModuleAt(currentName, psiDirectory, resolveContext).firstOrNull() + // There could be folder and module on the same level. Empty folder should be ignored in this case. + element = resolveModuleAt(currentName, psiDirectory, resolveContext).filterNot { + it is PsiDirectory && it.children.filterIsInstance().isEmpty() + }.firstOrNull() } if (element == null) { // Resolve against roots