From 5d9d4690a5d2cd7e831a61f2d6c959abf6ee81d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Smolarek?= <34063647+Razz4780@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:11:08 +0100 Subject: [PATCH] Plugin respects target set in the config (#167) * plugin respects target set in the config * Param doc, variable renamed for clarity --- changelog.d/+target-selection.fixed.md | 1 + src/api.ts | 12 ++++++++---- src/debugger.ts | 6 +++--- src/targetQuickPick.ts | 9 ++++----- 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 changelog.d/+target-selection.fixed.md diff --git a/changelog.d/+target-selection.fixed.md b/changelog.d/+target-selection.fixed.md new file mode 100644 index 00000000..e0d17339 --- /dev/null +++ b/changelog.d/+target-selection.fixed.md @@ -0,0 +1 @@ +Fixed a bug where mirrord was not respecting target selected in the mirrord config. diff --git a/src/api.ts b/src/api.ts index 58f31751..921ea323 100644 --- a/src/api.ts +++ b/src/api.ts @@ -370,8 +370,12 @@ export class MirrordAPI { * setting env vars, both from system, and from `launch.json` (`configEnv`). * * Has 60 seconds timeout + * + * @param quickPickSelection target selected by the user from the quick pick widget. + * `undefined` if we found the target in the config, + * and the widget was not shown. */ - async binaryExecute(target: UserSelection, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise { + async binaryExecute(quickPickSelection: UserSelection | undefined, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise { tickMirrordForTeamsCounter(); tickFeedbackCounter(); tickDiscordCounter(); @@ -387,11 +391,11 @@ export class MirrordAPI { reject("timeout"); }, 120 * 1000); - const args = makeMirrordArgs(target.path ?? "targetless", configFile, executable); + const args = makeMirrordArgs(quickPickSelection?.path, configFile, executable); let env: EnvVars; - if (target.namespace) { + if (quickPickSelection?.namespace) { // eslint-disable-next-line @typescript-eslint/naming-convention - env = { MIRRORD_TARGET_NAMESPACE: target.namespace, ...configEnv }; + env = { MIRRORD_TARGET_NAMESPACE: quickPickSelection.namespace, ...configEnv }; } else { env = configEnv; } diff --git a/src/debugger.ts b/src/debugger.ts index d7c70276..ea413330 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -110,7 +110,7 @@ async function main( let mirrordApi = new MirrordAPI(cliPath); config.env ||= {}; - let target: UserSelection = {}; + let quickPickSelection: UserSelection | undefined = undefined; let configPath = await MirrordConfigManager.getInstance().resolveMirrordConfig(folder, config); const verifiedConfig = await mirrordApi.verifyConfig(configPath, config.env); @@ -123,7 +123,7 @@ async function main( try { const quickPick = await TargetQuickPick.new(getTargets); - target = await quickPick.showAndGet(); + quickPickSelection = await quickPick.showAndGet(); } catch (err) { mirrordFailure(`mirrord failed to list targets: ${err}`); return null; @@ -152,7 +152,7 @@ async function main( let executionInfo; try { - executionInfo = await mirrordApi.binaryExecute(target, configPath?.path || null, executable, config.env); + executionInfo = await mirrordApi.binaryExecute(quickPickSelection, configPath?.path || null, executable, config.env); } catch (err) { mirrordFailure(`mirrord preparation failed: ${err}`); return null; diff --git a/src/targetQuickPick.ts b/src/targetQuickPick.ts index 9e81435f..fa3f82e8 100644 --- a/src/targetQuickPick.ts +++ b/src/targetQuickPick.ts @@ -51,7 +51,7 @@ const TARGET_SELECTION_PAGES: (TargetQuickPickPage & {targetType: string})[] = [ * An item in the @see TargetQuickPick. */ type TargetQuickPickItem = vscode.QuickPickItem & ( - { type: 'target', value?: string } | // select target + { type: 'target', value: string } | // select target { type: 'namespace', value: string } | // switch to another namespace { type: 'page', value: TargetQuickPickPage } // switch to another page (e.g select pod -> select deployment) ); @@ -62,6 +62,7 @@ type TargetQuickPickItem = vscode.QuickPickItem & ( const TARGETLESS_ITEM: TargetQuickPickItem = { type: 'target', label: 'No Target (\"targetless\")', + value: 'targetless', }; /** @@ -75,10 +76,8 @@ export type TargetFetcher = (namespace?: string) => Thenable; export type UserSelection = { /** * Selected target. - * - * undefined if targetless. */ - path?: string, + path: string, /** * Selected namespace. * @@ -313,7 +312,7 @@ export class TargetQuickPick { .withDisableAction("promptTargetless") .info(); - return { namespace: this.lsOutput.current_namespace }; + return { path: 'targetless', namespace: this.lsOutput.current_namespace }; } } }