|
1 | 1 | import * as fs from 'fs-extra'; |
2 | 2 | import path from 'path'; |
3 | | -import { PythonCommandRunConfiguration, PythonEnvironment } from '../../api'; |
| 3 | +import { commands, ConfigurationTarget, window, workspace } from 'vscode'; |
| 4 | +import { PythonCommandRunConfiguration, PythonEnvironment, PythonEnvironmentApi } from '../../api'; |
4 | 5 | import { isWindows } from '../../common/utils/platformUtils'; |
5 | 6 | import { ShellConstants } from '../../features/common/shellConstants'; |
| 7 | +import { getDefaultEnvManagerSetting, setDefaultEnvManagerBroken } from '../../features/settings/settingHelpers'; |
| 8 | +import { PythonProjectManager } from '../../internal.api'; |
6 | 9 | import { Installable } from './types'; |
7 | 10 |
|
8 | 11 | export function noop() { |
@@ -194,3 +197,41 @@ export async function getShellActivationCommands(binDir: string): Promise<{ |
194 | 197 | shellDeactivation, |
195 | 198 | }; |
196 | 199 | } |
| 200 | + |
| 201 | +export async function notifyMissingManagerIfDefault( |
| 202 | + managerId: string, |
| 203 | + projectManager: PythonProjectManager, |
| 204 | + api: PythonEnvironmentApi, |
| 205 | +) { |
| 206 | + const defaultEnvManager = getDefaultEnvManagerSetting(projectManager); |
| 207 | + if (defaultEnvManager === managerId) { |
| 208 | + setDefaultEnvManagerBroken(true); |
| 209 | + await api.refreshEnvironments(undefined); |
| 210 | + window |
| 211 | + .showErrorMessage( |
| 212 | + `The default environment manager is set to '${defaultEnvManager}', but the ${ |
| 213 | + managerId.split(':')[1] |
| 214 | + } executable could not be found.`, |
| 215 | + 'Reset setting', |
| 216 | + 'View setting', |
| 217 | + 'Close', |
| 218 | + ) |
| 219 | + .then((selection) => { |
| 220 | + if (selection === 'Reset setting') { |
| 221 | + // Remove the setting from all scopes |
| 222 | + const config = workspace.getConfiguration('python-envs'); |
| 223 | + const inspect = config.inspect('defaultEnvManager'); |
| 224 | + if (inspect?.workspaceValue !== undefined) { |
| 225 | + // Remove from workspace settings |
| 226 | + config.update('defaultEnvManager', undefined, ConfigurationTarget.Workspace); |
| 227 | + } else if (inspect?.globalValue !== undefined) { |
| 228 | + // Remove from user settings |
| 229 | + config.update('defaultEnvManager', undefined, ConfigurationTarget.Global); |
| 230 | + } |
| 231 | + } |
| 232 | + if (selection === 'View setting') { |
| 233 | + commands.executeCommand('workbench.action.openSettings', 'python-envs.defaultEnvManager'); |
| 234 | + } |
| 235 | + }); |
| 236 | + } |
| 237 | +} |
0 commit comments