From 9d901d52715c30d8763c2bbd817a62fe8f9b7765 Mon Sep 17 00:00:00 2001 From: Wasim Lorgat Date: Fri, 9 Jun 2023 04:28:11 +0000 Subject: [PATCH] Merged PR posit-dev/positron-python#120: add a progress indicator and cancel button during ipykernel install Merge pull request #120 from posit-dev/ipykernel-progress-and-cancel add a progress indicator and cancel button during ipykernel install -------------------- Commit message for posit-dev/positron-python@d8c04ecc7a7a1c78715765f89493b2223853f299: add a progress indicator and cancel button during ipykernel install Authored-by: Wasim Lorgat Signed-off-by: Wasim Lorgat --- .../client/activation/jedi/pythonLanguageRuntime.ts | 8 +++++++- .../src/client/common/installer/moduleInstaller.ts | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/extensions/positron-python/src/client/activation/jedi/pythonLanguageRuntime.ts b/extensions/positron-python/src/client/activation/jedi/pythonLanguageRuntime.ts index ce845094469..fb2785b5369 100644 --- a/extensions/positron-python/src/client/activation/jedi/pythonLanguageRuntime.ts +++ b/extensions/positron-python/src/client/activation/jedi/pythonLanguageRuntime.ts @@ -112,8 +112,14 @@ export class PythonLanguageRuntime implements JupyterLanguageRuntime, Disposable // Thow an error if it could not be installed. const hasKernel = await this.installer.isInstalled(Product.ipykernel, this.interpreter); if (!hasKernel) { + // Pass a cancellation token to enable VSCode's progress indicator and let the user + // cancel the install. + const tokenSource = new vscode.CancellationTokenSource(); + const installerToken = tokenSource.token; + const response = await this.installer.promptToInstall(Product.ipykernel, - this.interpreter, undefined, undefined, this.installOptions); + this.interpreter, installerToken, undefined, this.installOptions); + switch (response) { case InstallerResponse.Installed: traceVerbose(`Successfully installed ipykernel for ${this.interpreter?.displayName}`); diff --git a/extensions/positron-python/src/client/common/installer/moduleInstaller.ts b/extensions/positron-python/src/client/common/installer/moduleInstaller.ts index 62160b7e25c..662d333e2f9 100644 --- a/extensions/positron-python/src/client/common/installer/moduleInstaller.ts +++ b/extensions/positron-python/src/client/common/installer/moduleInstaller.ts @@ -14,7 +14,7 @@ import { IApplicationShell } from '../application/types'; import { wrapCancellationTokens } from '../cancellation'; import { IFileSystem } from '../platform/types'; import * as internalPython from '../process/internal/python'; -import { IProcessServiceFactory } from '../process/types'; +import { IProcessServiceFactory, SpawnOptions } from '../process/types'; import { ITerminalServiceFactory, TerminalCreationOptions } from '../terminal/types'; import { ExecutionInfo, IConfigurationService, ILogOutputChannel, Product } from '../types'; import { isResource } from '../utils/misc'; @@ -31,7 +31,7 @@ export abstract class ModuleInstaller implements IModuleInstaller { public abstract get type(): ModuleInstallerType; - constructor(protected serviceContainer: IServiceContainer) {} + constructor(protected serviceContainer: IServiceContainer) { } public async installModule( productOrModuleName: Product | string, @@ -230,7 +230,12 @@ export abstract class ModuleInstaller implements IModuleInstaller { ); await processService.shellExec(quoted); } else { - await processService.exec(command, args); + // --- Start Positron --- + // Pass the cancellation token through so that users can cancel installs via the UI + // when executeInTerminal is false + const spawnOptions: SpawnOptions = { token }; + await processService.exec(command, args, spawnOptions); + // --- End Positron --- } } }