mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
DS-1661: performance optimization of the "findSdkForDirectory" method
DS-1661 New opened terminal sessions use the Workspace environment even though the opened folder has a different environment set in settings GitOrigin-RevId: 286d7d076429f6b429b8b5378229d1336a6bca06
This commit is contained in:
committed by
intellij-monorepo-bot
parent
93fba88f4e
commit
8c83d321a2
@@ -10,14 +10,14 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.PySdkBundle;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
@@ -241,28 +241,36 @@ public final class PySdkUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds sdk for provided directory. Takes into account not project and module SDK
|
||||
* Finds sdk for provided directory. Takes into account both project and module SDK
|
||||
*/
|
||||
public static @Nullable Sdk findSdkForDirectory(@NotNull Project project, String workingDirectory) {
|
||||
Sdk firstSdk = null;
|
||||
for (Module m : ModuleManager.getInstance(project).getModules()) {
|
||||
Sdk sdk = PythonSdkUtil.findPythonSdk(m);
|
||||
if (sdk != null && !PythonSdkUtil.isRemote(sdk)) {
|
||||
if (workingDirectory == null) {
|
||||
VirtualFile workingDirectoryVirtualFile = LocalFileSystem.getInstance().findFileByPath(workingDirectory);
|
||||
if (workingDirectoryVirtualFile != null) {
|
||||
Sdk sdk = getLocalSdkForFile(project, workingDirectoryVirtualFile);
|
||||
if (sdk != null) {
|
||||
return sdk;
|
||||
}
|
||||
if (firstSdk == null) {
|
||||
firstSdk = sdk;
|
||||
}
|
||||
VirtualFile moduleDir = ProjectUtil.guessModuleDir(m);
|
||||
if (moduleDir != null) {
|
||||
if (VfsUtilCore.isEqualOrAncestor(moduleDir.getPath(), workingDirectory)) {
|
||||
return sdk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return firstSdk;
|
||||
for (Module m : ModuleManager.getInstance(project).getModules()) {
|
||||
Sdk sdk = PythonSdkUtil.findPythonSdk(m);
|
||||
if (sdk != null && !PythonSdkUtil.isRemote(sdk)) {
|
||||
return sdk;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Sdk getLocalSdkForFile(@NotNull Project project, @NotNull VirtualFile workingDirectoryVirtualFile) {
|
||||
Module module = ModuleUtilCore.findModuleForFile(workingDirectoryVirtualFile, project);
|
||||
if (module != null) {
|
||||
Sdk sdk = PythonSdkUtil.findPythonSdk(module);
|
||||
if (sdk != null && !PythonSdkUtil.isRemote(sdk)) {
|
||||
return sdk;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user