From 02e83d3d4f0490e0179c79fec84e0ca283f4963d Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 4 Oct 2024 18:23:32 +0200 Subject: [PATCH] Make sure child instantiation service instances are disposed/tracked for disposal (#230502) --- .../api/browser/mainThreadCLICommands.ts | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadCLICommands.ts b/src/vs/workbench/api/browser/mainThreadCLICommands.ts index c8aed8587cd..be73afd9fd4 100644 --- a/src/vs/workbench/api/browser/mainThreadCLICommands.ts +++ b/src/vs/workbench/api/browser/mainThreadCLICommands.ts @@ -65,28 +65,34 @@ CommandsRegistry.registerCommand('_remoteCLI.manageExtensions', async function ( lines.push(message); } }(); - const cliService = instantiationService.createChild(new ServiceCollection([IExtensionManagementService, remoteExtensionManagementService])).createInstance(RemoteExtensionManagementCLI, logger); + const childInstantiationService = instantiationService.createChild(new ServiceCollection([IExtensionManagementService, remoteExtensionManagementService])); + try { + const cliService = childInstantiationService.createInstance(RemoteExtensionManagementCLI, logger); - if (args.list) { - await cliService.listExtensions(!!args.list.showVersions, args.list.category, undefined); - } else { - const revive = (inputs: (string | UriComponents)[]) => inputs.map(input => isString(input) ? input : URI.revive(input)); - if (Array.isArray(args.install) && args.install.length) { - try { - await cliService.installExtensions(revive(args.install), [], { isMachineScoped: true }, !!args.force); - } catch (e) { - lines.push(e.message); + if (args.list) { + await cliService.listExtensions(!!args.list.showVersions, args.list.category, undefined); + } else { + const revive = (inputs: (string | UriComponents)[]) => inputs.map(input => isString(input) ? input : URI.revive(input)); + if (Array.isArray(args.install) && args.install.length) { + try { + await cliService.installExtensions(revive(args.install), [], { isMachineScoped: true }, !!args.force); + } catch (e) { + lines.push(e.message); + } } - } - if (Array.isArray(args.uninstall) && args.uninstall.length) { - try { - await cliService.uninstallExtensions(revive(args.uninstall), !!args.force, undefined); - } catch (e) { - lines.push(e.message); + if (Array.isArray(args.uninstall) && args.uninstall.length) { + try { + await cliService.uninstallExtensions(revive(args.uninstall), !!args.force, undefined); + } catch (e) { + lines.push(e.message); + } } } + return lines.join('\n'); + } finally { + childInstantiationService.dispose(); } - return lines.join('\n'); + }); class RemoteExtensionManagementCLI extends ExtensionManagementCLI {