diff --git a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts index ce554c6253..243da96c2f 100644 --- a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts +++ b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts @@ -1,6 +1,7 @@ import { extensionId, treeViewId } from "../constants"; import { ClientOrPluginProperties } from "../kiotaInterop"; import { OpenApiTreeProvider } from "../openApiTreeProvider"; +import { WorkspaceGenerationContext } from "../types/WorkspaceGenerationContext"; import { updateTreeViewIcons } from "../util"; import { openTreeViewWithProgress } from "../utilities/progress"; import { Command } from "./Command"; @@ -18,13 +19,13 @@ export class EditPathsCommand extends Command { return `${extensionId}.editPaths`; } - public async execute({ clientKey, clientObject }: { clientKey: string, clientObject: ClientOrPluginProperties }): Promise { - await this.loadEditPaths(clientKey, clientObject); + public async execute({ clientOrPluginKey, clientOrPluginObject }: Partial): Promise { + await this.loadEditPaths(clientOrPluginKey!, clientOrPluginObject!); this._openApiTreeProvider.resetInitialState(); await updateTreeViewIcons(treeViewId, false, true); } - private async loadEditPaths(clientKey: string, clientObject: ClientOrPluginProperties) { - await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(clientKey, clientObject)); + private async loadEditPaths(clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties) { + await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject)); } } diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index cd8b346328..63d5d0c303 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -12,10 +12,10 @@ import { generatePlugin } from "../../generatePlugin"; import { getLanguageInformation, getLanguageInformationForDescription } from "../../getLanguageInformation"; import { setGenerationConfiguration } from "../../handlers/configurationHandler"; import { clearDeepLinkParams, getDeepLinkParams } from "../../handlers/deepLinkParamsHandler"; -import { setWorkspaceGenerationType } from "../../handlers/workspaceGenerationTypeHandler"; import { ConsumerOperation, generationLanguageToString, getLogEntriesForLevel, KiotaLogEntry, LogLevel } from "../../kiotaInterop"; import { OpenApiTreeProvider } from "../../openApiTreeProvider"; import { GenerateState, generateSteps } from "../../steps"; +import { WorkspaceGenerationContext } from "../../types/WorkspaceGenerationContext"; import { getSanitizedString, getWorkspaceJsonDirectory, parseGenerationLanguage, parseGenerationType, parsePluginType, updateTreeViewIcons } from "../../util"; import { isDeeplinkEnabled, transformToGenerationConfig } from "../../utilities/deep-linking"; import { exportLogsAndShowErrors } from "../../utilities/logging"; @@ -27,12 +27,19 @@ export class GenerateClientCommand extends Command { private _openApiTreeProvider: OpenApiTreeProvider; private _context: vscode.ExtensionContext; private _dependenciesViewProvider: DependenciesViewProvider; + private _setWorkspaceGenerationContext: (params: Partial) => void; - constructor(openApiTreeProvider: OpenApiTreeProvider, context: vscode.ExtensionContext, dependenciesViewProvider: DependenciesViewProvider) { + constructor( + openApiTreeProvider: OpenApiTreeProvider, + context: vscode.ExtensionContext, + dependenciesViewProvider: DependenciesViewProvider, + setWorkspaceGenerationContext: (params: Partial) => void + ) { super(); this._openApiTreeProvider = openApiTreeProvider; this._context = context; this._dependenciesViewProvider = dependenciesViewProvider; + this._setWorkspaceGenerationContext = setWorkspaceGenerationContext; } public getName(): string { @@ -95,7 +102,7 @@ export class GenerateClientCommand extends Command { } const settings = getExtensionSettings(extensionId); - setWorkspaceGenerationType(config.generationType as string); + this._setWorkspaceGenerationContext({ generationType: config.generationType as string }); let result; switch (generationType) { case GenerationType.Client: diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts new file mode 100644 index 0000000000..8b0c375e53 --- /dev/null +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts @@ -0,0 +1,117 @@ +import TelemetryReporter from "@vscode/extension-telemetry"; +import * as vscode from "vscode"; +import { ExtensionContext } from "vscode"; + +import { extensionId } from "../../constants"; +import { KiotaGenerationLanguage, KiotaPluginType } from "../../enums"; +import { ExtensionSettings } from "../../extensionSettings"; +import { generateClient } from "../../generateClient"; +import { generatePlugin } from "../../generatePlugin"; +import { ClientObjectProperties, ClientOrPluginProperties, ConsumerOperation, getLogEntriesForLevel, LogLevel, PluginObjectProperties } from "../../kiotaInterop"; +import { OpenApiTreeProvider } from "../../openApiTreeProvider"; +import { parseGenerationLanguage, parsePluginType } from "../../util"; +import { exportLogsAndShowErrors } from "../../utilities/logging"; +import { checkForSuccess } from "../generate/generation-util"; + +export class RegenerateService { + private _context: ExtensionContext; + private _openApiTreeProvider: OpenApiTreeProvider; + private _clientKey: string; + private _clientObject: ClientOrPluginProperties; + + public constructor(context: ExtensionContext, openApiTreeProvider: OpenApiTreeProvider, + clientKey: string, clientObject: ClientOrPluginProperties) { + this._context = context; + this._openApiTreeProvider = openApiTreeProvider; + this._clientKey = clientKey; + this._clientObject = clientObject; + } + + async regenerateClient(settings: ExtensionSettings, selectedPaths?: string[]): Promise { + const clientObjectItem = this._clientObject as ClientObjectProperties; + const language = + typeof clientObjectItem.language === "string" + ? parseGenerationLanguage(clientObjectItem.language) + : KiotaGenerationLanguage.CSharp; + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + cancellable: false, + title: vscode.l10n.t("Re-generating client...") + }, async (progress, _) => { + const result = await generateClient( + this._context, + clientObjectItem.descriptionLocation ? clientObjectItem.descriptionLocation : this._openApiTreeProvider.descriptionUrl, + clientObjectItem.outputPath, + language, + selectedPaths ? selectedPaths : clientObjectItem.includePatterns, + clientObjectItem.excludePatterns ? clientObjectItem.excludePatterns : [], + this._clientKey, + clientObjectItem.clientNamespaceName, + clientObjectItem.usesBackingStore ? clientObjectItem.usesBackingStore : settings.backingStore, + true, // clearCache + true, // cleanOutput + clientObjectItem.excludeBackwardCompatible ? clientObjectItem.excludeBackwardCompatible : settings.excludeBackwardCompatible, + clientObjectItem.disabledValidationRules ? clientObjectItem.disabledValidationRules : settings.disableValidationRules, + settings.languagesSerializationConfiguration[language].serializers, + settings.languagesSerializationConfiguration[language].deserializers, + clientObjectItem.structuredMimeTypes ? clientObjectItem.structuredMimeTypes : settings.structuredMimeTypes, + clientObjectItem.includeAdditionalData ? clientObjectItem.includeAdditionalData : settings.includeAdditionalData, + ConsumerOperation.Edit + ); + if (result) { + const isSuccess = await checkForSuccess(result); + if (!isSuccess) { + await exportLogsAndShowErrors(result); + } + void vscode.window.showInformationMessage(`Client ${this._clientKey} re-generated successfully.`); + } + return result; + }); + + this._openApiTreeProvider.resetInitialState(); + } + + async regeneratePlugin(settings: ExtensionSettings, selectedPaths?: string[]) { + const pluginObjectItem = this._clientObject as PluginObjectProperties; + const pluginTypes = Array.isArray(pluginObjectItem.types) ? parsePluginType(pluginObjectItem.types) : [KiotaPluginType.ApiPlugin]; + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + cancellable: false, + title: vscode.l10n.t("Re-generating plugin...") + }, async (progress, _) => { + const start = performance.now(); + const result = await generatePlugin( + this._context, + pluginObjectItem.descriptionLocation ? pluginObjectItem.descriptionLocation : this._openApiTreeProvider.descriptionUrl, + pluginObjectItem.outputPath, + pluginTypes, + selectedPaths ? selectedPaths : pluginObjectItem.includePatterns, + [], + this._clientKey, + settings.clearCache, + false, + settings.disableValidationRules, + ConsumerOperation.Edit + ); + const duration = performance.now() - start; + const errorsCount = result ? getLogEntriesForLevel(result, LogLevel.critical, LogLevel.error).length : 0; + + const reporter = new TelemetryReporter(this._context.extension.packageJSON.telemetryInstrumentationKey); + reporter.sendRawTelemetryEvent(`${extensionId}.re-generatePlugin.completed`, { + "pluginType": pluginTypes.toString(), + "errorsCount": errorsCount.toString(), + }, { + "duration": duration, + }); + if (result) { + const isSuccess = await checkForSuccess(result); + if (!isSuccess) { + await exportLogsAndShowErrors(result); + } + void vscode.window.showInformationMessage(vscode.l10n.t(`Plugin ${this._clientKey} re-generated successfully.`)); + } + return result; + }); + this._openApiTreeProvider.resetInitialState(); + } +} \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts new file mode 100644 index 0000000000..5d4a85971e --- /dev/null +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts @@ -0,0 +1,66 @@ +import * as vscode from "vscode"; +import { ExtensionContext } from "vscode"; + +import { extensionId, treeViewId } from "../../constants"; +import { getExtensionSettings } from "../../extensionSettings"; +import { getGenerationConfiguration, setGenerationConfiguration } from "../../handlers/configurationHandler"; +import { OpenApiTreeProvider } from "../../openApiTreeProvider"; +import { WorkspaceGenerationContext } from "../../types/WorkspaceGenerationContext"; +import { isClientType, isPluginType } from "../../util"; +import { confirmOverride } from "../../utilities/regeneration"; +import { Command } from "../Command"; +import { RegenerateService } from "./regenerate.service"; + +export class RegenerateButtonCommand extends Command { + private _context: ExtensionContext; + private _openApiTreeProvider: OpenApiTreeProvider; + + constructor(context: ExtensionContext, openApiTreeProvider: OpenApiTreeProvider) { + super(); + this._context = context; + this._openApiTreeProvider = openApiTreeProvider; + } + + public getName(): string { + return `${treeViewId}.regenerateButton`; + } + + public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise { + const configuration = getGenerationConfiguration(); + const regenerate = await confirmOverride(); + if (!regenerate) { + return; + } + + if (!clientOrPluginKey || clientOrPluginKey === '') { + clientOrPluginKey = configuration.clientClassName || configuration.pluginName || ''; + } + + if (!configuration) { + setGenerationConfiguration({ + outputPath: clientOrPluginObject.outputPath, + clientClassName: clientOrPluginKey, + }); + } + + const settings = getExtensionSettings(extensionId); + const selectedPaths = this._openApiTreeProvider.getSelectedPaths(); + if (selectedPaths.length === 0) { + await vscode.window.showErrorMessage( + vscode.l10n.t("No endpoints selected, select endpoints first") + ); + return; + } + + const configObject = clientOrPluginObject || configuration; + const regenerateService = new RegenerateService(this._context, this._openApiTreeProvider, clientOrPluginKey, configObject); + + if (isClientType(generationType)) { + await regenerateService.regenerateClient(settings, selectedPaths); + } + if (isPluginType(generationType)) { + await regenerateService.regeneratePlugin(settings, selectedPaths); + } + } + +} \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts new file mode 100644 index 0000000000..7c849dbc91 --- /dev/null +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts @@ -0,0 +1,52 @@ +import * as vscode from "vscode"; +import { ExtensionContext } from "vscode"; + +import { extensionId, KIOTA_WORKSPACE_FILE } from "../../constants"; +import { getExtensionSettings } from "../../extensionSettings"; +import { OpenApiTreeProvider } from "../../openApiTreeProvider"; +import { WorkspaceGenerationContext } from "../../types/WorkspaceGenerationContext"; +import { isClientType, isPluginType } from "../../util"; +import { confirmOverride } from "../../utilities/regeneration"; +import { Command } from "../Command"; +import { RegenerateService } from "./regenerate.service"; + +export class RegenerateCommand extends Command { + private _context: ExtensionContext; + private _openApiTreeProvider: OpenApiTreeProvider; + + constructor(context: ExtensionContext, openApiTreeProvider: OpenApiTreeProvider) { + super(); + this._context = context; + this._openApiTreeProvider = openApiTreeProvider; + } + + public getName(): string { + return `${extensionId}.regenerate`; + } + + public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise { + const regenerate = await confirmOverride(); + if (!regenerate) { + return; + } + + const settings = getExtensionSettings(extensionId); + const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE)); + if (workspaceJson && workspaceJson.isDirty) { + await vscode.window.showInformationMessage( + vscode.l10n.t("Please save the workspace.json file before re-generation."), + vscode.l10n.t("OK") + ); + return; + } + + const regenerateService = new RegenerateService(this._context, this._openApiTreeProvider, clientOrPluginKey, clientOrPluginObject); + if (isClientType(generationType)) { + await regenerateService.regenerateClient(settings); + } + if (isPluginType(generationType)) { + await regenerateService.regeneratePlugin(settings); + } + } + +} \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/extension.ts b/vscode/microsoft-kiota/src/extension.ts index 9ad33a86f4..83948522ad 100644 --- a/vscode/microsoft-kiota/src/extension.ts +++ b/vscode/microsoft-kiota/src/extension.ts @@ -1,13 +1,12 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import TelemetryReporter from '@vscode/extension-telemetry'; -import * as path from 'path'; import * as vscode from "vscode"; import { CodeLensProvider } from "./codelensProvider"; import { EditPathsCommand } from './commands/editPathsCommand'; import { GenerateClientCommand } from './commands/generate/generateClientCommand'; -import { checkForSuccess, displayGenerationResults } from './commands/generate/generation-util'; +import { displayGenerationResults } from './commands/generate/generation-util'; import { MigrateFromLockFileCommand } from './commands/migrateFromLockFileCommand'; import { AddAllToSelectedEndpointsCommand } from './commands/open-api-tree-view/addAllToSelectedEndpointsCommand'; import { AddToSelectedEndpointsCommand } from './commands/open-api-tree-view/addToSelectedEndpointsCommand'; @@ -16,42 +15,36 @@ import { OpenDocumentationPageCommand } from './commands/open-api-tree-view/open import { RemoveAllFromSelectedEndpointsCommand } from './commands/open-api-tree-view/removeAllFromSelectedEndpointsCommand'; import { RemoveFromSelectedEndpointsCommand } from './commands/open-api-tree-view/removeFromSelectedEndpointsCommand'; import { SearchOrOpenApiDescriptionCommand } from './commands/open-api-tree-view/search-or-open-api-description/searchOrOpenApiDescriptionCommand'; -import { API_MANIFEST_FILE, KIOTA_WORKSPACE_FILE, dependenciesInfo, extensionId, statusBarCommandId, treeViewId } from "./constants"; +import { RegenerateButtonCommand } from './commands/regenerate/regenerateButtonCommand'; +import { RegenerateCommand } from './commands/regenerate/regenerateCommand'; +import { API_MANIFEST_FILE, dependenciesInfo, extensionId, statusBarCommandId, treeViewId } from "./constants"; import { DependenciesViewProvider } from "./dependenciesViewProvider"; -import { KiotaGenerationLanguage, KiotaPluginType } from "./enums"; -import { ExtensionSettings, getExtensionSettings } from "./extensionSettings"; -import { generateClient } from "./generateClient"; +import { getExtensionSettings } from "./extensionSettings"; import { GeneratedOutputState } from './GeneratedOutputState'; -import { generatePlugin } from "./generatePlugin"; import { getKiotaVersion } from "./getKiotaVersion"; -import { getGenerationConfiguration, setGenerationConfiguration } from './handlers/configurationHandler'; +import { getGenerationConfiguration } from './handlers/configurationHandler'; import { getDeepLinkParams, setDeepLinkParams } from './handlers/deepLinkParamsHandler'; -import { getWorkspaceGenerationType, setWorkspaceGenerationType } from './handlers/workspaceGenerationTypeHandler'; import { - ClientOrPluginProperties, - ConsumerOperation, - LogLevel, - getLogEntriesForLevel + ClientOrPluginProperties } from "./kiotaInterop"; import { checkForLockFileAndPrompt } from "./migrateFromLockFile"; import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider"; +import { WorkspaceGenerationContext } from "./types/WorkspaceGenerationContext"; import { updateClients } from "./updateClients"; import { - isClientType, isPluginType, parseGenerationLanguage, - parsePluginType, updateTreeViewIcons + updateTreeViewIcons } from "./util"; import { IntegrationParams, validateDeepLinkQueryParams } from './utilities/deep-linking'; import { loadWorkspaceFile } from './utilities/file'; import { exportLogsAndShowErrors } from './utilities/logging'; import { showUpgradeWarningMessage } from './utilities/messaging'; import { openTreeViewWithProgress } from './utilities/progress'; -import { confirmOverride } from './utilities/regeneration'; import { loadTreeView } from "./workspaceTreeProvider"; let kiotaStatusBarItem: vscode.StatusBarItem; let kiotaOutputChannel: vscode.LogOutputChannel; -let clientOrPluginKey: string; -let clientOrPluginObject: ClientOrPluginProperties; +let workspaceGenerationContext: WorkspaceGenerationContext; + // This method is called when your extension is activated // Your extension is activated the very first time the command is executed export async function activate( @@ -66,6 +59,10 @@ export async function activate( ); const reporter = new TelemetryReporter(context.extension.packageJSON.telemetryInstrumentationKey); + const setWorkspaceGenerationContext = (params: Partial) => { + workspaceGenerationContext = { ...workspaceGenerationContext, ...params }; + }; + const migrateFromLockFileCommand = new MigrateFromLockFileCommand(context); const addAllToSelectedEndpointsCommand = new AddAllToSelectedEndpointsCommand(openApiTreeProvider); const addToSelectedEndpointsCommand = new AddToSelectedEndpointsCommand(openApiTreeProvider); @@ -75,7 +72,9 @@ export async function activate( const openDocumentationPageCommand = new OpenDocumentationPageCommand(); const editPathsCommand = new EditPathsCommand(openApiTreeProvider); const searchOrOpenApiDescriptionCommand = new SearchOrOpenApiDescriptionCommand(openApiTreeProvider, context); - const generateClientCommand = new GenerateClientCommand(openApiTreeProvider, context, dependenciesInfoProvider); + const generateClientCommand = new GenerateClientCommand(openApiTreeProvider, context, dependenciesInfoProvider, setWorkspaceGenerationContext); + const regenerateCommand = new RegenerateCommand(context, openApiTreeProvider); + const regenerateButtonCommand = new RegenerateButtonCommand(context, openApiTreeProvider); await loadTreeView(context); await checkForLockFileAndPrompt(context); @@ -162,158 +161,20 @@ export async function activate( } ), registerCommandWithTelemetry(reporter, filterDescriptionCommand.getName(), async () => await filterDescriptionCommand.execute()), - registerCommandWithTelemetry(reporter, editPathsCommand.getName(), async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => { - clientOrPluginKey = clientKey; - clientOrPluginObject = clientObject; - setWorkspaceGenerationType(generationType); - await editPathsCommand.execute({ clientKey, clientObject }); + registerCommandWithTelemetry(reporter, editPathsCommand.getName(), async (clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties, generationType: string) => { + setWorkspaceGenerationContext({ clientOrPluginKey, clientOrPluginObject, generationType }); + await editPathsCommand.execute({ clientOrPluginKey, clientOrPluginObject, generationType }); }), - - registerCommandWithTelemetry(reporter, `${treeViewId}.regenerateButton`, async () => { - const configuration = getGenerationConfiguration(); - const regenerate = await confirmOverride(); - if (!regenerate) { - return; - } - - if (!clientOrPluginKey || clientOrPluginKey === '') { - clientOrPluginKey = configuration.clientClassName || configuration.pluginName || ''; - } - - if (!configuration) { - setGenerationConfiguration({ - outputPath: clientOrPluginObject.outputPath, - clientClassName: clientOrPluginKey, - }); - } - - const settings = getExtensionSettings(extensionId); - const selectedPaths = openApiTreeProvider.getSelectedPaths(); - if (selectedPaths.length === 0) { - await vscode.window.showErrorMessage( - vscode.l10n.t("No endpoints selected, select endpoints first") - ); - return; - } - const workspaceGenerationType = getWorkspaceGenerationType(); - const configObject = clientOrPluginObject || configuration; - - if (isClientType(workspaceGenerationType)) { - await regenerateClient(clientOrPluginKey, configObject, settings, selectedPaths); - } - if (isPluginType(workspaceGenerationType)) { - await regeneratePlugin(clientOrPluginKey, configObject, settings, selectedPaths); - } + registerCommandWithTelemetry(reporter, regenerateButtonCommand.getName(), async () => { + await regenerateButtonCommand.execute(workspaceGenerationContext); }), - registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => { - const regenerate = await confirmOverride(); - if (!regenerate) { - return; - } - - const settings = getExtensionSettings(extensionId); - const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE)); - if (workspaceJson && workspaceJson.isDirty) { - await vscode.window.showInformationMessage( - vscode.l10n.t("Please save the workspace.json file before re-generation."), - vscode.l10n.t("OK") - ); - return; - } - if (isClientType(generationType)) { - await regenerateClient(clientKey, clientObject, settings); - } - if (isPluginType(generationType)) { - await regeneratePlugin(clientKey, clientObject, settings); - } + registerCommandWithTelemetry(reporter, regenerateCommand.getName(), async (clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties, generationType: string) => { + setWorkspaceGenerationContext({ clientOrPluginKey, clientOrPluginObject, generationType }); + await regenerateCommand.execute({ clientOrPluginKey, clientOrPluginObject, generationType }); }), registerCommandWithTelemetry(reporter, migrateFromLockFileCommand.getName(), async (uri: vscode.Uri) => await migrateFromLockFileCommand.execute(uri)), ); - - async function regenerateClient(clientKey: string, clientObject: any, settings: ExtensionSettings, selectedPaths?: string[]): Promise { - const language = - typeof clientObject.language === "string" - ? parseGenerationLanguage(clientObject.language) - : KiotaGenerationLanguage.CSharp; - await vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - cancellable: false, - title: vscode.l10n.t("Re-generating client...") - }, async (progress, _) => { - const result = await generateClient( - context, - clientObject.descriptionLocation ? clientObject.descriptionLocation : openApiTreeProvider.descriptionUrl, - clientObject.outputPath, - language, - selectedPaths ? selectedPaths : clientObject.includePatterns, - clientObject.excludePatterns ? clientObject.excludePatterns : [], - clientKey, - clientObject.clientNamespaceName, - clientObject.usesBackingStore ? clientObject.usesBackingStore : settings.backingStore, - true, // clearCache - true, // cleanOutput - clientObject.excludeBackwardCompatible ? clientObject.excludeBackwardCompatible : settings.excludeBackwardCompatible, - clientObject.disabledValidationRules ? clientObject.disabledValidationRules : settings.disableValidationRules, - settings.languagesSerializationConfiguration[language].serializers, - settings.languagesSerializationConfiguration[language].deserializers, - clientObject.structuredMimeTypes ? clientObject.structuredMimeTypes : settings.structuredMimeTypes, - clientObject.includeAdditionalData ? clientObject.includeAdditionalData : settings.includeAdditionalData, - ConsumerOperation.Edit - ); - if (result) { - const isSuccess = await checkForSuccess(result); - if (!isSuccess) { - await exportLogsAndShowErrors(result); - } - void vscode.window.showInformationMessage(`Client ${clientKey} re-generated successfully.`); - } - return result; - }); - - openApiTreeProvider.resetInitialState(); - } - async function regeneratePlugin(clientKey: string, clientObject: any, settings: ExtensionSettings, selectedPaths?: string[]) { - const pluginTypes = Array.isArray(clientObject.types) ? parsePluginType(clientObject.types) : [KiotaPluginType.ApiPlugin]; - await vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - cancellable: false, - title: vscode.l10n.t("Re-generating plugin...") - }, async (progress, _) => { - const start = performance.now(); - const result = await generatePlugin( - context, - clientObject.descriptionLocation ? clientObject.descriptionLocation : openApiTreeProvider.descriptionUrl, - clientObject.outputPath, - pluginTypes, - selectedPaths ? selectedPaths : clientObject.includePatterns, - [], - clientKey, - settings.clearCache, - false, - settings.disableValidationRules, - ConsumerOperation.Edit - ); - const duration = performance.now() - start; - const errorsCount = result ? getLogEntriesForLevel(result, LogLevel.critical, LogLevel.error).length : 0; - reporter.sendRawTelemetryEvent(`${extensionId}.re-generatePlugin.completed`, { - "pluginType": pluginTypes.toString(), - "errorsCount": errorsCount.toString(), - }, { - "duration": duration, - }); - if (result) { - const isSuccess = await checkForSuccess(result); - if (!isSuccess) { - await exportLogsAndShowErrors(result); - } - void vscode.window.showInformationMessage(`Plugin ${clientKey} re-generated successfully.`); - } - return result; - }); - openApiTreeProvider.resetInitialState(); - } - // create a new status bar item that we can now manage kiotaStatusBarItem = vscode.window.createStatusBarItem( vscode.StatusBarAlignment.Right, diff --git a/vscode/microsoft-kiota/src/handlers/workspaceGenerationTypeHandler.ts b/vscode/microsoft-kiota/src/handlers/workspaceGenerationTypeHandler.ts deleted file mode 100644 index 23c8ab9764..0000000000 --- a/vscode/microsoft-kiota/src/handlers/workspaceGenerationTypeHandler.ts +++ /dev/null @@ -1,6 +0,0 @@ -let workspaceGenerationType: string; - -export const getWorkspaceGenerationType = () => workspaceGenerationType; -export const setWorkspaceGenerationType = (generationType: string) => { - workspaceGenerationType = generationType; -}; \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/types/WorkspaceGenerationContext.ts b/vscode/microsoft-kiota/src/types/WorkspaceGenerationContext.ts new file mode 100644 index 0000000000..91fe462d77 --- /dev/null +++ b/vscode/microsoft-kiota/src/types/WorkspaceGenerationContext.ts @@ -0,0 +1,7 @@ +import { ClientOrPluginProperties } from "../kiotaInterop"; + +export interface WorkspaceGenerationContext { + clientOrPluginKey: string; + clientOrPluginObject: ClientOrPluginProperties; + generationType: string; +}