|
1 | 1 | import { |
2 | 2 | CancellationError, |
| 3 | + CancellationToken, |
| 4 | + CancellationTokenSource, |
3 | 5 | Disposable, |
4 | 6 | Event, |
5 | 7 | EventEmitter, |
6 | 8 | LogOutputChannel, |
7 | 9 | MarkdownString, |
| 10 | + Progress, |
8 | 11 | ProgressLocation, |
9 | 12 | } from 'vscode'; |
10 | 13 | import { |
@@ -70,31 +73,48 @@ export class CondaPackageManager implements PackageManager, Disposable { |
70 | 73 | install: toInstall, |
71 | 74 | uninstall: toUninstall, |
72 | 75 | }; |
73 | | - await withProgress( |
74 | | - { |
75 | | - location: ProgressLocation.Notification, |
76 | | - title: CondaStrings.condaInstallingPackages, |
77 | | - cancellable: true, |
78 | | - }, |
79 | | - async (_progress, token) => { |
80 | | - try { |
81 | | - const before = this.packages.get(environment.envId.id) ?? []; |
82 | | - const after = await managePackages(environment, manageOptions, this.api, this, token, this.log); |
83 | | - const changes = getChanges(before, after); |
84 | | - this.packages.set(environment.envId.id, after); |
85 | | - this._onDidChangePackages.fire({ environment: environment, manager: this, changes }); |
86 | | - } catch (e) { |
87 | | - if (e instanceof CancellationError) { |
88 | | - throw e; |
89 | | - } |
90 | 76 |
|
91 | | - this.log.error('Error installing packages', e); |
92 | | - setImmediate(async () => { |
93 | | - await showErrorMessageWithLogs(CondaStrings.condaInstallError, this.log); |
94 | | - }); |
| 77 | + const executeManage = async ( |
| 78 | + _progress: Progress<{ message?: string; increment?: number }> | undefined, |
| 79 | + token: CancellationToken, |
| 80 | + ) => { |
| 81 | + try { |
| 82 | + const before = this.packages.get(environment.envId.id) ?? []; |
| 83 | + const after = await managePackages(environment, manageOptions, this.api, this, token, this.log); |
| 84 | + const changes = getChanges(before, after); |
| 85 | + this.packages.set(environment.envId.id, after); |
| 86 | + this._onDidChangePackages.fire({ environment: environment, manager: this, changes }); |
| 87 | + } catch (e) { |
| 88 | + if (e instanceof CancellationError) { |
| 89 | + throw e; |
95 | 90 | } |
96 | | - }, |
97 | | - ); |
| 91 | + |
| 92 | + this.log.error('Error installing packages', e); |
| 93 | + setImmediate(async () => { |
| 94 | + await showErrorMessageWithLogs(CondaStrings.condaInstallError, this.log); |
| 95 | + }); |
| 96 | + } |
| 97 | + }; |
| 98 | + |
| 99 | + if (options.suppressProgress) { |
| 100 | + // When suppressProgress is true, execute without showing a separate progress notification |
| 101 | + // Create a cancellation token source since conda's managePackages requires one |
| 102 | + const tokenSource = new CancellationTokenSource(); |
| 103 | + try { |
| 104 | + await executeManage(undefined, tokenSource.token); |
| 105 | + } finally { |
| 106 | + tokenSource.dispose(); |
| 107 | + } |
| 108 | + } else { |
| 109 | + await withProgress( |
| 110 | + { |
| 111 | + location: ProgressLocation.Notification, |
| 112 | + title: CondaStrings.condaInstallingPackages, |
| 113 | + cancellable: true, |
| 114 | + }, |
| 115 | + executeManage, |
| 116 | + ); |
| 117 | + } |
98 | 118 | } |
99 | 119 |
|
100 | 120 | async refresh(environment: PythonEnvironment): Promise<void> { |
|
0 commit comments