Skip to content

Commit

Permalink
reuse the regeneration command
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Nov 15, 2024
1 parent ffe44e8 commit 1aadd1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
9 changes: 1 addition & 8 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}`);
Expand Down
28 changes: 18 additions & 10 deletions vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -60,31 +61,31 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider<WorkspaceT
if (element.label === KIOTA_WORKSPACE_FILE) {
const children: WorkspaceTreeItem[] = [];
if (Object.keys(this.workspaceContent.clients).length > 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))
);
}
}
return [];
}

getProperties(name: string, category: string): ClientOrPluginProperties | undefined {
if (category && category === 'Plugins') {
if (category && category === CLIENTS) {
return this.workspaceContent?.plugins[name];
}
return this.workspaceContent?.clients[name];
Expand Down Expand Up @@ -147,7 +148,7 @@ async function openResource(resource: vscode.Uri): Promise<void> {
await vscode.window.showTextDocument(resource);
}

export async function loadTreeView(context: vscode.ExtensionContext, treeDataProvider: WorkspaceTreeProvider): Promise<void> {
export async function loadTreeView(context: vscode.ExtensionContext, treeDataProvider: WorkspaceTreeProvider, regenerateCommand: RegenerateCommand): Promise<void> {
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
Expand All @@ -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! });
})
);

}

0 comments on commit 1aadd1f

Please sign in to comment.