provide command name in command

This commit is contained in:
thewahome 2024-08-14 11:58:12 +03:00
Родитель 44b330d44a
Коммит c3ff57d585
17 изменённых файлов: 105 добавлений и 35 удалений

Просмотреть файл

@ -13,6 +13,10 @@ export class CloseDescriptionCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.closeDescription`;
}
async execute(): Promise<void> {
const yesAnswer = vscode.l10n.t("Yes");
const response = await vscode.window.showInformationMessage(

Просмотреть файл

@ -1,7 +1,5 @@
export abstract class Command {
public toString():string {
return this.constructor.name;
}
public abstract toString():string;
abstract execute(args: unknown):void;
}

Просмотреть файл

@ -1,4 +1,4 @@
import { treeViewId } from "../constants";
import { extensionId, treeViewId } from "../constants";
import { ClientOrPluginProperties } from "../kiotaInterop";
import { OpenApiTreeProvider } from "../providers/openApiTreeProvider";
import { updateTreeViewIcons } from "../util";
@ -18,13 +18,17 @@ export class EditPathsCommand extends Command {
this._clientObject = clientObject;
}
public toString(): string {
return `${extensionId}.editPaths`;
}
async execute(): Promise<void> {
await this.loadEditPaths();
this._openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
}
async loadEditPaths() {
private async loadEditPaths() {
await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(this._clientKey, this._clientObject));
}

Просмотреть файл

@ -1,15 +1,20 @@
import { treeViewId } from "../constants";
import { OpenApiTreeProvider } from "../providers/openApiTreeProvider";
import { filterSteps } from "../steps";
import { Command } from "./Command";
export class FilterDescriptionCommand extends Command {
private _openApiTreeProvider: OpenApiTreeProvider;
constructor(openApiTreeProvider: OpenApiTreeProvider) {
super();
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.filterDescription`;
}
async execute(): Promise<void> {
await filterSteps(this._openApiTreeProvider.filter,
x => this._openApiTreeProvider.filter = x);

Просмотреть файл

@ -1,7 +1,7 @@
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";
import { extensionId } from "../constants";
import { extensionId, treeViewId } from "../constants";
import { getExtensionSettings } from "../extensionSettings";
import { OpenApiTreeProvider } from "../providers/openApiTreeProvider";
import { searchDescription } from "../searchDescription";
@ -10,6 +10,7 @@ import { openTreeViewWithProgress } from "../utilities/file";
import { Command } from "./Command";
export class SearchOrOpenApiDescriptionCommand extends Command {
private _context: ExtensionContext;
private _openApiTreeProvider: OpenApiTreeProvider;
@ -19,6 +20,10 @@ export class SearchOrOpenApiDescriptionCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.searchOrOpenApiDescription`;
}
async execute(): Promise<void> {
const yesAnswer = vscode.l10n.t("Yes, override it");
if (!this._openApiTreeProvider.isEmpty() && this._openApiTreeProvider.hasChanges()) {

Просмотреть файл

@ -1,8 +1,10 @@
import { extensionId } from "../constants";
import { OpenApiTreeProvider } from "../providers/openApiTreeProvider";
import { loadLockFile } from "../utilities/file";
import { Command } from "./Command";
export class SelectLockCommand extends Command {
private _openApiTreeProvider: OpenApiTreeProvider;
constructor(openApiTreeProvider: OpenApiTreeProvider) {
@ -10,6 +12,10 @@ export class SelectLockCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${extensionId}.selectLock`;
}
execute(x: any): void {
void loadLockFile(x, this._openApiTreeProvider);
}

Просмотреть файл

@ -11,7 +11,6 @@ import { updateStatusBarItem } from '../utilities/status-bar';
import { Command } from "./Command";
export class UpdateClientsCommand extends Command {
private _context: ExtensionContext;
public constructor(context: ExtensionContext) {
@ -19,6 +18,10 @@ export class UpdateClientsCommand extends Command {
this._context = context;
}
public toString(): string {
return `${extensionId}.updateClients`;
}
async execute(kiotaStatusBarItem: StatusBarItem): Promise<void> {
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
await vscode.window.showErrorMessage(

Просмотреть файл

@ -5,8 +5,10 @@ import { GenerateState } from "../../steps";
import { Command } from "../Command";
import { GeneratedOutputState } from "../GeneratedOutputState";
import { displayGenerationResults } from "./generation-results";
import { extensionId } from "../../constants";
export class DisplayGenerationResultsCommand extends Command {
private _context: ExtensionContext;
private _openApiTreeProvider: OpenApiTreeProvider;
@ -16,6 +18,10 @@ export class DisplayGenerationResultsCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${extensionId}.displayGenerationResults`;
}
async execute(config: Partial<GenerateState>): Promise<void> {
const generatedOutput = this._context.workspaceState.get<GeneratedOutputState>('generatedOutput');
if (generatedOutput) {
@ -25,6 +31,4 @@ export class DisplayGenerationResultsCommand extends Command {
void this._context.workspaceState.update('generatedOutput', undefined);
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";
import { extensionId, treeViewFocusCommand } from "../../constants";
import { extensionId, treeViewFocusCommand, treeViewId } from "../../constants";
import { ExtensionSettings, getExtensionSettings } from "../../extensionSettings";
import { generateClient } from '../../generateClient';
import { generatePlugin } from '../../generatePlugin';
@ -32,6 +32,10 @@ export class GenerateClientCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.generateClient`;
}
public async execute() {
const selectedPaths = this._openApiTreeProvider.getSelectedPaths();
if (selectedPaths.length === 0) {
@ -97,7 +101,7 @@ export class GenerateClientCommand extends Command {
}
}
async generateClientAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
private async generateClientAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
const language =
typeof config.language === "string"
? parseGenerationLanguage(config.language)
@ -166,7 +170,7 @@ export class GenerateClientCommand extends Command {
return result;
}
async generatePluginAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
private async generatePluginAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
const pluginTypes = Array.isArray(config.pluginTypes) ? parsePluginType(config.pluginTypes) : [KiotaPluginType.ApiPlugin];
const result = await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
@ -210,7 +214,7 @@ export class GenerateClientCommand extends Command {
return result;
}
async generateManifestAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
private async generateManifestAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
const pluginTypes = KiotaPluginType.ApiManifest;
const result = await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,

Просмотреть файл

@ -1,13 +1,19 @@
import { treeViewId } from "../../constants";
import { OpenApiTreeNode, OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
import { Command } from "../Command";
export class AddAllToSelectedEndpointsCommand extends Command {
private _openApiTreeProvider: OpenApiTreeProvider;
constructor(openApiTreeProvider: OpenApiTreeProvider) {
super();;
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.addAllToSelectedEndpoints`;
}
execute(openApiTreeNode: OpenApiTreeNode): void {
this._openApiTreeProvider.select(openApiTreeNode, true, true);

Просмотреть файл

@ -1,3 +1,4 @@
import { treeViewId } from "../../constants";
import { OpenApiTreeNode, OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
import { Command } from "../Command";
@ -10,6 +11,10 @@ export class AddToSelectedEndpointsCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.addToSelectedEndpoints`;
}
execute(openApiTreeNode: OpenApiTreeNode): void {
this._openApiTreeProvider.select(openApiTreeNode, true, false);
}

Просмотреть файл

@ -1,12 +1,18 @@
import * as vscode from "vscode";
import { treeViewId } from "../../constants";
import { OpenApiTreeNode } from "../../providers/openApiTreeProvider";
import { Command } from "../Command";
export class OpenDocumentationPageCommand extends Command {
constructor() {
super();
}
public toString(): string {
return `${treeViewId}.openDocumentationPage`;
}
execute(openApiTreeNode: OpenApiTreeNode): void {
if (openApiTreeNode.documentationUrl) {
vscode.env.openExternal(vscode.Uri.parse(openApiTreeNode.documentationUrl));

Просмотреть файл

@ -1,3 +1,4 @@
import { treeViewId } from "../../constants";
import { OpenApiTreeNode, OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
import { Command } from "../Command";
@ -8,7 +9,11 @@ export class RemoveAllFromSelectedEndpointsCommand extends Command {
super();;
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.removeAllFromSelectedEndpoints`;
}
execute(openApiTreeNode: OpenApiTreeNode): void {
this._openApiTreeProvider.select(openApiTreeNode, false, true);
}

Просмотреть файл

@ -1,7 +1,9 @@
import { treeViewId } from "../../constants";
import { OpenApiTreeNode, OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
import { Command } from "../Command";
export class RemoveFromSelectedEndpointsCommand extends Command {
private _openApiTreeProvider: OpenApiTreeProvider;
constructor(openApiTreeProvider: OpenApiTreeProvider) {
@ -9,6 +11,10 @@ export class RemoveFromSelectedEndpointsCommand extends Command {
this._openApiTreeProvider = openApiTreeProvider;
}
public toString(): string {
return `${treeViewId}.removeFromSelectedEndpoints`;
}
execute(openApiTreeNode: OpenApiTreeNode): void {
this._openApiTreeProvider.select(openApiTreeNode, false, false);
}

Просмотреть файл

@ -1,7 +1,7 @@
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";
import { extensionId } from "../../constants";
import { extensionId, treeViewId } from "../../constants";
import { getExtensionSettings } from "../../extensionSettings";
import { ClientOrPluginProperties } from "../../kiotaInterop";
import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
@ -11,7 +11,6 @@ import { Command } from "../Command";
import { RegenerateService } from "./regenerate.service";
export class RegenerateButtonCommand extends Command {
private _context: ExtensionContext;
private _openApiTreeProvider: OpenApiTreeProvider;
private _clientKey: string;
@ -28,6 +27,10 @@ export class RegenerateButtonCommand extends Command {
this._workspaceGenerationType = workspaceGenerationType;
}
public toString(): string {
return `${treeViewId}.regenerateButton`;
}
async execute(config: Partial<GenerateState>): Promise<void> {
if (!this._clientKey || this._clientKey === '') {
this._clientKey = config.clientClassName || config.pluginName || '';

Просмотреть файл

@ -10,7 +10,8 @@ import { Command } from "../Command";
import { RegenerateService } from "./regenerate.service";
export class RegenerateCommand extends Command {
private _context: ExtensionContext;
private _openApiTreeProvider: OpenApiTreeProvider;
private _clientKey: string;
@ -27,6 +28,10 @@ export class RegenerateCommand extends Command {
this._workspaceGenerationType = workspaceGenerationType;
}
public toString(): string {
return `${extensionId}.regenerate`;
}
async execute(): Promise<void> {
const settings = getExtensionSettings(extensionId);
const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE));

Просмотреть файл

@ -29,6 +29,7 @@ import { OpenApiTreeNode, OpenApiTreeProvider } from './providers/openApiTreePro
import { loadTreeView } from './providers/workspaceTreeProvider';
import { GenerateState } from "./steps";
import { updateStatusBarItem } from './utilities/status-bar';
import { AddAllToSelectedEndpointsCommand } from './commands/open-api-tree-node/AddAllToSelectedEndpointsCommand';
let kiotaStatusBarItem: vscode.StatusBarItem;
let clientOrPluginKey: string;
@ -57,7 +58,7 @@ export async function activate(
const regenerateButtonCommand = new RegenerateButtonCommand(context, openApiTreeProvider, clientOrPluginKey, clientOrPluginObject, workspaceGenerationType);
const regenerateCommand = new RegenerateCommand(context, openApiTreeProvider, clientOrPluginKey, clientOrPluginObject, workspaceGenerationType);
const addToSelectedEndpointsCommand = new AddToSelectedEndpointsCommand(openApiTreeProvider);
const addAllToSelectedEndpointsCommand = new AddToSelectedEndpointsCommand(openApiTreeProvider);
const addAllToSelectedEndpointsCommand = new AddAllToSelectedEndpointsCommand(openApiTreeProvider);
const removeFromSelectedEndpointsCommand = new RemoveFromSelectedEndpointsCommand(openApiTreeProvider);
const removeAllFromSelectedEndpointsCommand = new RemoveAllFromSelectedEndpointsCommand(openApiTreeProvider);
const updateClientsCommand = new UpdateClientsCommand(context);
@ -68,7 +69,7 @@ export async function activate(
const reporter = new TelemetryReporter(context.extension.packageJSON.telemetryInstrumentationKey);
await loadTreeView(context);
context.subscriptions.push(
reporter,
@ -77,20 +78,20 @@ export async function activate(
vscode.window.registerWebviewViewProvider(dependenciesInfo, dependenciesInfoProvider),
vscode.window.registerTreeDataProvider(treeViewId, openApiTreeProvider),
registerCommandWithTelemetry(reporter, `${extensionId}.selectLock`, (x) => selectLockCommand.execute(x)),
registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async () => editPathsCommand.execute()),
registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async () => regenerateCommand.execute()),
registerCommandWithTelemetry(reporter, selectLockCommand.toString(), (x) => selectLockCommand.execute(x)),
registerCommandWithTelemetry(reporter, editPathsCommand.toString(), async () => editPathsCommand.execute()),
registerCommandWithTelemetry(reporter, regenerateCommand.toString(), async () => regenerateCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.openDocumentationPage`, (openApiTreeNode: OpenApiTreeNode) => openDocumentationPageCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.addToSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => addToSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.addAllToSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => addAllToSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.removeFromSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => removeFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.removeAllFromSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => removeAllFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.generateClient`, () => generateClientCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.searchOrOpenApiDescription`, () => searchOrOpenApiDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.closeDescription`, () => closeDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.filterDescription`, () => filterDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.regenerateButton`, async () => regenerateButtonCommand.execute(config)),
registerCommandWithTelemetry(reporter, openDocumentationPageCommand.toString(), (openApiTreeNode: OpenApiTreeNode) => openDocumentationPageCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, addToSelectedEndpointsCommand.toString(), (openApiTreeNode: OpenApiTreeNode) => addToSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, addAllToSelectedEndpointsCommand.toString(), (openApiTreeNode: OpenApiTreeNode) => addAllToSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, removeFromSelectedEndpointsCommand.toString(), (openApiTreeNode: OpenApiTreeNode) => removeFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, removeAllFromSelectedEndpointsCommand.toString(), (openApiTreeNode: OpenApiTreeNode) => removeAllFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, generateClientCommand.toString(), () => generateClientCommand.execute()),
registerCommandWithTelemetry(reporter, searchOrOpenApiDescriptionCommand.toString(), () => searchOrOpenApiDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, closeDescriptionCommand.toString(), () => closeDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, filterDescriptionCommand.toString(), () => filterDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, regenerateButtonCommand.toString(), async () => regenerateButtonCommand.execute(config)),
registerCommandWithTelemetry(reporter, statusBarCommandId, async () => kiotaStatusCommand.execute()),
vscode.workspace.onDidChangeWorkspaceFolders(async () => displayGenerationResultsCommand.execute(config)),
@ -103,7 +104,7 @@ export async function activate(
// update status bar item once at start
await updateStatusBarItem(context, kiotaStatusBarItem);
context.subscriptions.push(registerCommandWithTelemetry(reporter, `${extensionId}.updateClients`, async () => updateClientsCommand.execute(kiotaStatusBarItem)));
context.subscriptions.push(registerCommandWithTelemetry(reporter, updateClientsCommand.toString(), async () => updateClientsCommand.execute(kiotaStatusBarItem)));
}