mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
DS-1661 Add working directory to customizeCommandAndEnvironment
DS-1661 New opened terminal sessions use the Workspace environment even though the opened folder has a different environment set in settings GitOrigin-RevId: e47df9bc9b6ee65e85f0667f0390be7edce4a891
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ce368bd156
commit
3bb6f6204f
@@ -23,12 +23,23 @@ public abstract class LocalTerminalCustomizer {
|
||||
* {@code /usr/bin/bash --rcfile PATH_TO/community/plugins/terminal/resources/jediterm-bash.in}. See the {@code jediterm-bash.in} script
|
||||
* for more information on how to alter the execution process.
|
||||
*/
|
||||
public @NotNull String[] customizeCommandAndEnvironment(@NotNull Project project,
|
||||
@NotNull String[] command,
|
||||
@NotNull Map<String, String> envs) {
|
||||
public String[] customizeCommandAndEnvironment(@NotNull Project project,
|
||||
@Nullable String workingDirectory,
|
||||
@NotNull String[] command,
|
||||
@NotNull Map<String, String> envs) {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use LocalTerminalCustomizer#customizeCommandAndEnvironment(Project, String, String[], Map)
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] customizeCommandAndEnvironment(@NotNull Project project,
|
||||
@NotNull String[] command,
|
||||
@NotNull Map<String, String> envs) {
|
||||
return customizeCommandAndEnvironment(project, null, command, envs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return configurable for customizer-specific options
|
||||
*/
|
||||
|
||||
@@ -183,7 +183,7 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
|
||||
|
||||
for (LocalTerminalCustomizer customizer : LocalTerminalCustomizer.EP_NAME.getExtensions()) {
|
||||
try {
|
||||
command = customizer.customizeCommandAndEnvironment(myProject, command, envs);
|
||||
command = customizer.customizeCommandAndEnvironment(myProject, workingDir, command, envs);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error("Exception during customization of the terminal session", e);
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="module" module-name="intellij.python.psi.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -8,11 +8,17 @@ import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.openapi.application.Application;
|
||||
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.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.VirtualFile;
|
||||
import com.jetbrains.python.PySdkBundle;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
@@ -233,4 +239,30 @@ public final class PySdkUtil {
|
||||
public static String getBuiltinsFileName(@NotNull Sdk sdk) {
|
||||
return PyBuiltinCache.getBuiltinsFileName(getLanguageLevelForSdk(sdk));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds sdk for provided directory. Takes into account not 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.options.UnnamedConfigurable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
@@ -65,9 +64,10 @@ class PyVirtualEnvTerminalCustomizer : LocalTerminalCustomizer() {
|
||||
}
|
||||
|
||||
override fun customizeCommandAndEnvironment(project: Project,
|
||||
workingDirectory: String?,
|
||||
command: Array<out String>,
|
||||
envs: MutableMap<String, String>): Array<out String> {
|
||||
val sdk: Sdk? = findSdk(project)
|
||||
val sdk: Sdk? = PySdkUtil.findSdkForDirectory(project, workingDirectory)
|
||||
|
||||
if (sdk != null &&
|
||||
(PythonSdkUtil.isVirtualEnv(sdk) || PythonSdkUtil.isConda(sdk)) &&
|
||||
@@ -109,17 +109,6 @@ class PyVirtualEnvTerminalCustomizer : LocalTerminalCustomizer() {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun findSdk(project: Project): Sdk? {
|
||||
for (m in ModuleManager.getInstance(project).modules) {
|
||||
val sdk: Sdk? = PythonSdkUtil.findPythonSdk(m)
|
||||
if (sdk != null && !PythonSdkUtil.isRemote(sdk)) {
|
||||
return sdk
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getConfigurable(project: Project): UnnamedConfigurable = object : UnnamedConfigurable {
|
||||
val settings = PyVirtualEnvTerminalSettings.getInstance(project)
|
||||
|
||||
@@ -166,6 +155,5 @@ class PyVirtualEnvTerminalSettings : PersistentStateComponent<SettingsState> {
|
||||
return project.getService(PyVirtualEnvTerminalSettings::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user