Skip to content

Commit

Permalink
Task: create edit paths command (#5517)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Oct 3, 2024
1 parent f837b76 commit 1cc92e2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
30 changes: 30 additions & 0 deletions vscode/microsoft-kiota/src/commands/editPathsCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { extensionId, treeViewId } from "../constants";
import { ClientOrPluginProperties } from "../kiotaInterop";
import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { updateTreeViewIcons } from "../util";
import { openTreeViewWithProgress } from "../utilities/progress";
import { Command } from "./Command";

export class EditPathsCommand extends Command {

private _openApiTreeProvider: OpenApiTreeProvider;

public constructor(openApiTreeProvider: OpenApiTreeProvider) {
super();
this._openApiTreeProvider = openApiTreeProvider;
}

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

public async execute({ clientKey, clientObject }: { clientKey: string, clientObject: ClientOrPluginProperties }): Promise<void> {
await this.loadEditPaths(clientKey, clientObject);
this._openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
}

private async loadEditPaths(clientKey: string, clientObject: ClientOrPluginProperties) {
await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(clientKey, clientObject));
}
}
23 changes: 7 additions & 16 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as path from 'path';
import * as vscode from "vscode";

import { CodeLensProvider } from "./codelensProvider";
import { EditPathsCommand } from './commands/editPathsCommand';
import { MigrateFromLockFileCommand } from './commands/migrateFromLockFileCommand';
import { AddAllToSelectedEndpointsCommand } from './commands/open-api-tree-view/addAllToSelectedEndpointsCommand';
import { AddToSelectedEndpointsCommand } from './commands/open-api-tree-view/addToSelectedEndpointsCommand';
Expand Down Expand Up @@ -40,6 +41,7 @@ import {
parseGenerationType, parsePluginType, updateTreeViewIcons
} from "./util";
import { IntegrationParams, isDeeplinkEnabled, transformToGenerationConfig, validateDeepLinkQueryParams } from './utilities/deep-linking';
import { openTreeViewWithProgress } from './utilities/progress';
import { confirmOverride } from './utilities/regeneration';
import { loadTreeView } from "./workspaceTreeProvider";

Expand Down Expand Up @@ -75,6 +77,7 @@ export async function activate(
const removeFromSelectedEndpointsCommand = new RemoveFromSelectedEndpointsCommand(openApiTreeProvider);
const filterDescriptionCommand = new FilterDescriptionCommand(openApiTreeProvider);
const openDocumentationPageCommand = new OpenDocumentationPageCommand();
const editPathsCommand = new EditPathsCommand(openApiTreeProvider);

await loadTreeView(context);
await checkForLockFileAndPrompt(context);
Expand Down Expand Up @@ -303,15 +306,13 @@ export async function activate(
}
),
registerCommandWithTelemetry(reporter, filterDescriptionCommand.getName(), async () => await filterDescriptionCommand.execute()),

registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => {
registerCommandWithTelemetry(reporter, editPathsCommand.getName(), async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => {
clientOrPluginKey = clientKey;
clientOrPluginObject = clientObject;
workspaceGenerationType = generationType;
await loadEditPaths(clientOrPluginKey, clientObject, openApiTreeProvider);
openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
await editPathsCommand.execute({ clientKey, clientObject });
}),

registerCommandWithTelemetry(reporter, `${treeViewId}.regenerateButton`, async () => {
const regenerate = await confirmOverride();
if (!regenerate) {
Expand Down Expand Up @@ -675,17 +676,7 @@ export async function activate(

context.subscriptions.push(disposable);
}
function openTreeViewWithProgress<T>(callback: () => Promise<T>): Thenable<T> {
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
cancellable: false,
title: vscode.l10n.t("Loading...")
}, async (progress, _) => {
const result = await callback();
await vscode.commands.executeCommand(treeViewFocusCommand);
return result;
});
}

function registerCommandWithTelemetry(reporter: TelemetryReporter, command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
return vscode.commands.registerCommand(command, (...args: any[]) => {
const splatCommand = command.split('/');
Expand Down
17 changes: 17 additions & 0 deletions vscode/microsoft-kiota/src/utilities/progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as vscode from "vscode";

import { treeViewFocusCommand } from "../constants";

function openTreeViewWithProgress<T>(callback: () => Promise<T>): Thenable<T> {
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
cancellable: false,
title: vscode.l10n.t("Loading...")
}, async (progress, _) => {
const result = await callback();
await vscode.commands.executeCommand(treeViewFocusCommand);
return result;
});
}

export { openTreeViewWithProgress };

0 comments on commit 1cc92e2

Please sign in to comment.