From eaa97a1428656e5a24a7b16cd82d34a45f3eee60 Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Mon, 17 Oct 2022 13:23:37 -0700 Subject: [PATCH] Add unwrapArgs util --- utils/index.d.ts | 2 ++ utils/src/registerCommandWithTreeNodeUnwrapping.ts | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/utils/index.d.ts b/utils/index.d.ts index d673303ac5..f352386ce4 100644 --- a/utils/index.d.ts +++ b/utils/index.d.ts @@ -1765,3 +1765,5 @@ export declare type FindableByIdTreeNode = FindableByIdTreeNodeV2 | AzExtTreeIte * NOTE: If the environment variable `DEBUGTELEMETRY` is set to a non-empty, non-zero value, then telemetry will not be sent. If the value is 'verbose' or 'v', telemetry will be displayed in the console window. */ export declare function registerCommandWithTreeNodeUnwrapping(commandId: string, callback: TreeNodeCommandCallback, debounce?: number, telemetryId?: string): void; + +export declare function unwrapArgs(treeNodeCallback: TreeNodeCommandCallback): TreeNodeCommandCallback; diff --git a/utils/src/registerCommandWithTreeNodeUnwrapping.ts b/utils/src/registerCommandWithTreeNodeUnwrapping.ts index 75d6985e9b..8a559ff5e3 100644 --- a/utils/src/registerCommandWithTreeNodeUnwrapping.ts +++ b/utils/src/registerCommandWithTreeNodeUnwrapping.ts @@ -3,12 +3,16 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { CommandCallback, IActionContext, Wrapper } from '../index'; +import type { IActionContext, Wrapper } from '../index'; import type { TreeNodeCommandCallback } from '../hostapi.v2'; import { registerCommand } from './registerCommand'; export function registerCommandWithTreeNodeUnwrapping(commandId: string, treeNodeCallback: TreeNodeCommandCallback, debounce?: number, telemetryId?: string): void { - const unwrappingCallback: CommandCallback = async (context: IActionContext, ...args: unknown[]) => { + registerCommand(commandId, unwrapArgs(treeNodeCallback), debounce, telemetryId); +} + +export function unwrapArgs(treeNodeCallback: TreeNodeCommandCallback): TreeNodeCommandCallback { + return async (context: IActionContext, ...args: unknown[]) => { const maybeNodeWrapper = args?.[0]; const maybeNodeWrapperArray = args?.[1]; const remainingArgs = args.slice(2); @@ -35,11 +39,9 @@ export function registerCommandWithTreeNodeUnwrapping(commandId: string, tree nodes = maybeNodeWrapperArray as T[]; } - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return treeNodeCallback(context, node, nodes, ...remainingArgs); }; - - registerCommand(commandId, unwrappingCallback, debounce, telemetryId); } export function isWrapper(maybeWrapper: unknown): maybeWrapper is Wrapper {