mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
PY-17941 Fix ranking of resolve results: don't skip empty modules, prefer real files to "__all__"
Test PyBinaryModuleCompletionTest#testPySideImport failed without special rule regarding references in "__all__".
This commit is contained in:
@@ -403,17 +403,16 @@ public class ResolveImportUtil {
|
||||
if (target instanceof PsiDirectory) {
|
||||
target = PyUtil.getPackageElement((PsiDirectory)target, null);
|
||||
}
|
||||
if (target != null) { // Ignore non-package dirs, worthless
|
||||
if (target != null) {
|
||||
int rate = RatedResolveResult.RATE_HIGH;
|
||||
if (target instanceof PyFile) {
|
||||
VirtualFile vFile = ((PyFile)target).getVirtualFile();
|
||||
if (vFile != null && vFile.getLength() > 0) {
|
||||
rate += 100;
|
||||
}
|
||||
for (PyResolveResultRater rater : Extensions.getExtensions(PyResolveResultRater.EP_NAME)) {
|
||||
rate += rater.getImportElementRate(target);
|
||||
}
|
||||
}
|
||||
else if (isDunderAll(target)) {
|
||||
rate = RatedResolveResult.RATE_NORMAL;
|
||||
}
|
||||
ret.poke(target, rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import re
|
||||
<ref>
|
||||
@@ -15,12 +15,14 @@
|
||||
*/
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.jetbrains.python.fixtures.PyMultiFileResolveTestCase;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -418,4 +420,12 @@ public class PyMultiFileResolveTest extends PyMultiFileResolveTestCase {
|
||||
public void testFromImportSubModuleDunderAll() {
|
||||
assertResolvesTo(PyFile.class, "m1.py");
|
||||
}
|
||||
|
||||
// PY-17941
|
||||
public void testEmptyModuleNamesake() {
|
||||
final PsiElement module = doResolve();
|
||||
assertNotNull(module);
|
||||
final Sdk moduleSdk = PythonSdkType.findPythonSdk(myFixture.getModule());
|
||||
assertFalse(PythonSdkType.isStdLib(module.getContainingFile().getVirtualFile(), moduleSdk));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user