mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
PY-25234 More efficient way to check that a user skeleton belongs to the stdlib
Also, I added a test on that scenario using the skeleton for "alembic" as an example.
This commit is contained in:
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.userSkeletons;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -56,7 +57,7 @@ public class PyUserSkeletonsUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil");
|
||||
public static final Key<Boolean> HAS_SKELETON = Key.create("PyUserSkeleton.hasSkeleton");
|
||||
|
||||
private static final ImmutableList<String> STDLIB_SKELETONS = ImmutableList.of(
|
||||
private static final ImmutableSet<String> STDLIB_SKELETONS = ImmutableSet.of(
|
||||
"asyncio",
|
||||
"multiprocessing",
|
||||
"os",
|
||||
@@ -130,12 +131,13 @@ public class PyUserSkeletonsUtil {
|
||||
if (skeletonsDir == null) {
|
||||
return false;
|
||||
}
|
||||
final String relativePath = VfsUtilCore.getRelativePath(virtualFile, skeletonsDir);
|
||||
final String relativePath = VfsUtilCore.getRelativePath(virtualFile, skeletonsDir, '/');
|
||||
// not under skeletons directory
|
||||
if (relativePath == null) {
|
||||
return false;
|
||||
}
|
||||
return ContainerUtil.exists(STDLIB_SKELETONS, relativePath::startsWith);
|
||||
final String firstComponent = ContainerUtil.getFirstItem(StringUtil.split(relativePath, "/"));
|
||||
return STDLIB_SKELETONS.contains(firstComponent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import sys
|
||||
|
||||
print(<error descr="Unresolved reference 'alembic'">alem<caret>bic</error>, sys)
|
||||
@@ -0,0 +1,5 @@
|
||||
import sys
|
||||
|
||||
import alembic
|
||||
|
||||
print(alembic, sys)
|
||||
@@ -55,10 +55,16 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
doMultiFileAutoImportTest("Import this name");
|
||||
}
|
||||
|
||||
public void testSkeletonStdlibModule() {
|
||||
// PY-25234
|
||||
public void testBinarySkeletonStdlibModule() {
|
||||
doMultiFileAutoImportTest("Import 'sys'");
|
||||
}
|
||||
|
||||
// PY-25234
|
||||
public void testUserSkeletonStdlibModule() {
|
||||
doMultiFileAutoImportTest("Import 'alembic'");
|
||||
}
|
||||
|
||||
private void doMultiFileAutoImportTest(@NotNull String hintPrefix) {
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user