diff --git a/vscode/microsoft-kiota/src/extension.ts b/vscode/microsoft-kiota/src/extension.ts index 6a6186f843..1a8cbbd433 100644 --- a/vscode/microsoft-kiota/src/extension.ts +++ b/vscode/microsoft-kiota/src/extension.ts @@ -82,7 +82,7 @@ export async function activate( const selectLockCommand = new SelectLockCommand(openApiTreeProvider); const updateClientsCommand = new UpdateClientsCommand(context); - await loadTreeView(context, workspaceTreeProvider); + await loadTreeView(context, workspaceTreeProvider, regenerateCommand); await checkForLockFileAndPrompt(context); let codeLensProvider = new CodeLensProvider(); context.subscriptions.push( @@ -132,13 +132,6 @@ export async function activate( ); - context.subscriptions.push( - vscode.commands.registerCommand('kiota.workspace.regenerate', (workspaceTreeItem: WorkspaceTreeItem) => { - // Implement edit item logic here - vscode.window.showInformationMessage(`Regenerate item: ${workspaceTreeItem.label}`); - }) - ); - context.subscriptions.push( vscode.commands.registerCommand('kiota.workspace.delete', (workspaceTreeItem: WorkspaceTreeItem) => { vscode.window.showInformationMessage(`Delete item: ${workspaceTreeItem.label}`); diff --git a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts index 8f396343dd..620163b669 100644 --- a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts +++ b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts @@ -1,8 +1,9 @@ import * as vscode from 'vscode'; -import { KIOTA_WORKSPACE_FILE } from '../constants'; +import { RegenerateCommand } from '../commands/regenerate/regenerateCommand'; +import { CLIENTS, KIOTA_WORKSPACE_FILE, PLUGINS } from '../constants'; import { ClientOrPluginProperties } from '../kiotaInterop'; -import { getWorkspaceJsonPath, isKiotaWorkspaceFilePresent } from '../util'; +import { getWorkspaceJsonPath, isClientType, isKiotaWorkspaceFilePresent, isPluginType } from '../util'; import { SharedService } from './sharedService'; interface WorkspaceContent { @@ -60,23 +61,23 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider 0) { - children.push(new WorkspaceTreeItem('Clients', vscode.TreeItemCollapsibleState.Expanded, 'category')); + children.push(new WorkspaceTreeItem(CLIENTS, vscode.TreeItemCollapsibleState.Expanded, 'category')); } if (Object.keys(this.workspaceContent.plugins).length > 0) { - children.push(new WorkspaceTreeItem('Plugins', vscode.TreeItemCollapsibleState.Expanded, 'category')); + children.push(new WorkspaceTreeItem(PLUGINS, vscode.TreeItemCollapsibleState.Expanded, 'category')); } return children; } - if (element.label === 'Clients') { + if (isClientType(element.label)) { return Object.keys(this.workspaceContent.clients).map(clientName => - new WorkspaceTreeItem(clientName, vscode.TreeItemCollapsibleState.None, 'item', 'Clients', this.getProperties(clientName, 'Clients')) + new WorkspaceTreeItem(clientName, vscode.TreeItemCollapsibleState.None, 'item', CLIENTS, this.getProperties(clientName, CLIENTS)) ); } - if (element.label === 'Plugins') { + if (isPluginType(element.label)) { return Object.keys(this.workspaceContent.plugins).map(pluginName => - new WorkspaceTreeItem(pluginName, vscode.TreeItemCollapsibleState.None, 'item', 'Plugins', this.getProperties(pluginName, 'Plugins')) + new WorkspaceTreeItem(pluginName, vscode.TreeItemCollapsibleState.None, 'item', PLUGINS, this.getProperties(pluginName, CLIENTS)) ); } } @@ -84,7 +85,7 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider { await vscode.window.showTextDocument(resource); } -export async function loadTreeView(context: vscode.ExtensionContext, treeDataProvider: WorkspaceTreeProvider): Promise { +export async function loadTreeView(context: vscode.ExtensionContext, treeDataProvider: WorkspaceTreeProvider, regenerateCommand: RegenerateCommand): Promise { context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(async () => { treeDataProvider.isWorkspacePresent = await isKiotaWorkspaceFilePresent(); await vscode.commands.executeCommand('kiota.workspace.refresh'); // Refresh the tree view when workspace folders change @@ -158,4 +159,11 @@ export async function loadTreeView(context: vscode.ExtensionContext, treeDataPro treeDataProvider.isWorkspacePresent = await isKiotaWorkspaceFilePresent(); await treeDataProvider.refreshView(); })); + context.subscriptions.push( + vscode.commands.registerCommand('kiota.workspace.regenerate', async (workspaceTreeItem: WorkspaceTreeItem) => { + const { label, properties, category } = workspaceTreeItem; + await regenerateCommand.execute({ clientOrPluginKey: label, clientOrPluginObject: properties!, generationType: category! }); + }) + ); + }