From 96c5b59f6e652254733201eda3ea5989816c8c76 Mon Sep 17 00:00:00 2001 From: Andrea Buzzi <155985472+buzzia2001@users.noreply.github.com> Date: Wed, 1 Jul 2026 21:41:20 +0200 Subject: [PATCH 1/3] Enhance action sorting options in getAllAvailableActions function --- package.json | 8 +++++-- src/ui/actions.ts | 59 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 979e58733..8bdb80003 100644 --- a/package.json +++ b/package.json @@ -436,11 +436,15 @@ "default": "usage", "enum": [ "usage", - "name" + "name", + "config", + "actionsFile" ], "enumDescriptions": [ "Sort actions by most recently used", - "Sort actions alphabetically by name" + "Sort actions alphabetically by name", + "Only show actions defined in the general configuration, in the order they are written", + "Only show actions defined in actions.json, in the order they are written" ], "description": "Determine how actions should be sorted in the action selection menu" }, diff --git a/src/ui/actions.ts b/src/ui/actions.ts index 777f05b22..efb0a7a63 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -645,7 +645,8 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur export type AvailableAction = { label: string; action: Action; } export async function getAllAvailableActions(targets: ActionTarget[], scheme: string) { - const allActions = [...await ActionTools.getActions()]; + const configActions = await ActionTools.getActions(); + const actionsFileActions: Action[] = []; // Then, if we're being called from a local file // we fetch the Actions defined from the workspace. @@ -657,11 +658,12 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st const allTargetsInOne = targets.every(t => t.workspaceFolder?.index === workspaceId); if (allTargetsInOne) { - const localActions = await ActionTools.getActions(firstWorkspace); - allActions.push(...localActions); + actionsFileActions.push(...await ActionTools.getActions(firstWorkspace)); } } + const allActions = [...configActions, ...actionsFileActions]; + // We make sure all extensions are uppercase allActions.forEach(action => { if (action.extensions) { @@ -669,26 +671,45 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st }; }); + const matchesContext = (action: Action) => action.type === scheme + && (!action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || + action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`)) + && (action.runOnProtected || !targets.some(t => t.protected)); + // Get the sort preference from settings const sortBy = IBMi.connectionManager.get(`sortActionsBy`) || `usage`; + let sortedActions: Action[]; + if (sortBy === `config`) { + // Only show actions defined in the general configuration, in the order they're written + sortedActions = configActions.filter(matchesContext); + } else if (sortBy === `actionsFile`) { + if (actionsFileActions.length) { + // Only show actions defined in actions.json, in the order they're written + sortedActions = actionsFileActions.filter(matchesContext); + } else { + // No actions.json found (or it's empty): fall back to the actions from the general configuration + vscode.window.showWarningMessage(l10n.t(`"actionsFile" sort order is configured, but no actions were found in actions.json. Showing actions from the general configuration instead.`)); + sortedActions = configActions.filter(matchesContext); + } + } else { + sortedActions = allActions.filter(matchesContext) + .sort((a, b) => { + if (sortBy === `name`) { + // Sort alphabetically by name + return a.name.localeCompare(b.name); + } else { + // Sort by most recently used (default behavior) + return (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0); + } + }); + } + // Then we get all the available Actions for the current context - const availableActions: AvailableAction[] = allActions.filter(action => action.type === scheme) - .filter(action => !action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`)) - .filter(action => action.runOnProtected || !targets.some(t => t.protected)) - .sort((a, b) => { - if (sortBy === `name`) { - // Sort alphabetically by name - return a.name.localeCompare(b.name); - } else { - // Sort by most recently used (default behavior) - return (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0); - } - }) - .map(action => ({ - label: action.name, - action - })); + const availableActions: AvailableAction[] = sortedActions.map(action => ({ + label: action.name, + action + })); return availableActions; } From 8c7092a7966151fbd803f35f09eca96476b36b4a Mon Sep 17 00:00:00 2001 From: Andrea Buzzi Date: Sun, 5 Jul 2026 18:52:01 +0200 Subject: [PATCH 2/3] Refactor logic in getAllAvailableActions function --- package.json | 6 ++---- src/ui/actions.ts | 52 +++++++++++++++-------------------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 8bdb80003..35825f449 100644 --- a/package.json +++ b/package.json @@ -437,14 +437,12 @@ "enum": [ "usage", "name", - "config", - "actionsFile" + "config" ], "enumDescriptions": [ "Sort actions by most recently used", "Sort actions alphabetically by name", - "Only show actions defined in the general configuration, in the order they are written", - "Only show actions defined in actions.json, in the order they are written" + "Sort actions in the order they are defined in the configuration, regardless of their origin" ], "description": "Determine how actions should be sorted in the action selection menu" }, diff --git a/src/ui/actions.ts b/src/ui/actions.ts index efb0a7a63..df1ac7fa6 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -645,8 +645,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur export type AvailableAction = { label: string; action: Action; } export async function getAllAvailableActions(targets: ActionTarget[], scheme: string) { - const configActions = await ActionTools.getActions(); - const actionsFileActions: Action[] = []; + const allActions = [...await ActionTools.getActions()]; // Then, if we're being called from a local file // we fetch the Actions defined from the workspace. @@ -658,12 +657,11 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st const allTargetsInOne = targets.every(t => t.workspaceFolder?.index === workspaceId); if (allTargetsInOne) { - actionsFileActions.push(...await ActionTools.getActions(firstWorkspace)); + const localActions = await ActionTools.getActions(firstWorkspace); + allActions.push(...localActions); } } - const allActions = [...configActions, ...actionsFileActions]; - // We make sure all extensions are uppercase allActions.forEach(action => { if (action.extensions) { @@ -671,42 +669,24 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st }; }); - const matchesContext = (action: Action) => action.type === scheme - && (!action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || - action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`)) - && (action.runOnProtected || !targets.some(t => t.protected)); - // Get the sort preference from settings const sortBy = IBMi.connectionManager.get(`sortActionsBy`) || `usage`; - let sortedActions: Action[]; - if (sortBy === `config`) { - // Only show actions defined in the general configuration, in the order they're written - sortedActions = configActions.filter(matchesContext); - } else if (sortBy === `actionsFile`) { - if (actionsFileActions.length) { - // Only show actions defined in actions.json, in the order they're written - sortedActions = actionsFileActions.filter(matchesContext); - } else { - // No actions.json found (or it's empty): fall back to the actions from the general configuration - vscode.window.showWarningMessage(l10n.t(`"actionsFile" sort order is configured, but no actions were found in actions.json. Showing actions from the general configuration instead.`)); - sortedActions = configActions.filter(matchesContext); - } - } else { - sortedActions = allActions.filter(matchesContext) - .sort((a, b) => { - if (sortBy === `name`) { - // Sort alphabetically by name - return a.name.localeCompare(b.name); - } else { - // Sort by most recently used (default behavior) - return (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0); - } - }); + // Then we get all the available Actions for the current context + const contextActions = allActions.filter(action => action.type === scheme) + .filter(action => !action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`)) + .filter(action => action.runOnProtected || !targets.some(t => t.protected)); + + if (sortBy === `name`) { + // Sort alphabetically by name + contextActions.sort((a, b) => a.name.localeCompare(b.name)); + } else if (sortBy !== `config`) { + // Sort by most recently used (default behavior). + // `config` keeps actions in the order they are defined, regardless of their origin. + contextActions.sort((a, b) => (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0)); } - // Then we get all the available Actions for the current context - const availableActions: AvailableAction[] = sortedActions.map(action => ({ + const availableActions: AvailableAction[] = contextActions.map(action => ({ label: action.name, action })); From 2d1caaabab201216db692782f25737cc92092cdf Mon Sep 17 00:00:00 2001 From: Andrea Buzzi Date: Sun, 5 Jul 2026 20:12:47 +0200 Subject: [PATCH 3/3] Modified actions.ts to improve readability --- src/ui/actions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/actions.ts b/src/ui/actions.ts index df1ac7fa6..4e73f3c70 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -670,7 +670,7 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st }); // Get the sort preference from settings - const sortBy = IBMi.connectionManager.get(`sortActionsBy`) || `usage`; + const sortBy = IBMi.connectionManager.get<'name'|'usage'|'config'>(`sortActionsBy`) || `usage`; // Then we get all the available Actions for the current context const contextActions = allActions.filter(action => action.type === scheme) @@ -680,7 +680,7 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st if (sortBy === `name`) { // Sort alphabetically by name contextActions.sort((a, b) => a.name.localeCompare(b.name)); - } else if (sortBy !== `config`) { + } else if (sortBy === `usage`) { // Sort by most recently used (default behavior). // `config` keeps actions in the order they are defined, regardless of their origin. contextActions.sort((a, b) => (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0));