Skip to content

Commit

Permalink
[partial] delete workspace item
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Nov 18, 2024
1 parent b285a33 commit 711294c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
36 changes: 36 additions & 0 deletions vscode/microsoft-kiota/src/commands/deleteWorkspaceItemCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";

import { extensionId } from "../constants";
import { WorkspaceTreeItem } from "../providers/workspaceTreeProvider";
import { Command } from "./Command";
import { connectToKiota, KiotaLogEntry } from "../kiotaInterop";
import { isPluginType } from "../util";

export class DeleteWorkspaceItemCommand extends Command {
constructor(private _context: vscode.ExtensionContext) {
super();
}

public getName(): string {
return `${extensionId}.workspace.deleteItem`;
}

public async execute(workspaceTreeItem: WorkspaceTreeItem): Promise<void> {
const result = await deleteItem(this._context, isPluginType(workspaceTreeItem.category!) ? "plugin" : "client", workspaceTreeItem.label);
vscode.window.showInformationMessage(`Delete item: ${workspaceTreeItem.label}`);
}
}

export function deleteItem(context: vscode.ExtensionContext, workspaceItemType: string, key: string): Promise<KiotaLogEntry[] | undefined> {
return connectToKiota(context, async (connection) => {
const request = new rpc.RequestType1<string, KiotaLogEntry[], void>(
workspaceItemType
);
const result = await connection.sendRequest(
request,
key
);
return result;
});
};
9 changes: 3 additions & 6 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TelemetryReporter from '@vscode/extension-telemetry';
import * as vscode from "vscode";

import { CloseDescriptionCommand } from './commands/closeDescriptionCommand';
import { DeleteWorkspaceItemCommand } from './commands/deleteWorkspaceItemCommand';
import { EditPathsCommand } from './commands/editPathsCommand';
import { GenerateClientCommand } from './commands/generate/generateClientCommand';
import { displayGenerationResults } from './commands/generate/generation-util';
Expand Down Expand Up @@ -81,6 +82,7 @@ export async function activate(
const statusCommand = new StatusCommand();
const selectLockCommand = new SelectLockCommand(openApiTreeProvider);
const updateClientsCommand = new UpdateClientsCommand(context);
const deleteWorkspaceItemCommand = new DeleteWorkspaceItemCommand(context);

await loadTreeView(context, workspaceTreeProvider, regenerateCommand);
await checkForLockFileAndPrompt(context);
Expand Down Expand Up @@ -129,15 +131,10 @@ export async function activate(
await regenerateCommand.execute({ clientOrPluginKey, clientOrPluginObject, generationType });
}),
registerCommandWithTelemetry(reporter, migrateFromLockFileCommand.getName(), async (uri: vscode.Uri) => await migrateFromLockFileCommand.execute(uri)),
registerCommandWithTelemetry(reporter, deleteWorkspaceItemCommand.getName(), async (workspaceTreeItem: WorkspaceTreeItem) => await deleteWorkspaceItemCommand.execute(workspaceTreeItem)),

);

context.subscriptions.push(
vscode.commands.registerCommand('kiota.workspace.delete', (workspaceTreeItem: WorkspaceTreeItem) => {
vscode.window.showInformationMessage(`Delete item: ${workspaceTreeItem.label}`);
})
);

// create a new status bar item that we can now manage
kiotaStatusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
Expand Down

0 comments on commit 711294c

Please sign in to comment.