diff --git a/vscode/microsoft-kiota/CHANGELOG.md b/vscode/microsoft-kiota/CHANGELOG.md index 3c530e5d9f..4d80c21cb0 100644 --- a/vscode/microsoft-kiota/CHANGELOG.md +++ b/vscode/microsoft-kiota/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. ### Changed - Fixed a bug in the VS Code extension deeplink with the API Center extension [#6004](https://github.com/microsoft/kiota/issues/6004) +- Use a subdirectory in the output path when generating clients [#5977](https://github.com/microsoft/kiota/issues/5977) ## [1.22.100000001] - 2025-01-10 diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index 849426bdf5..ea200aa57c 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -22,6 +22,7 @@ import { generateClient } from "./generateClient"; import { generatePlugin } from "./generatePlugin"; import { displayGenerationResults } from "./generation-util"; import { getLanguageInformation, getLanguageInformationForDescription } from "./getLanguageInformation"; +import { confirmDeletionOnCleanOutput } from "../../utilities/generation"; export class GenerateClientCommand extends Command { @@ -66,6 +67,11 @@ export class GenerateClientCommand extends Command { pluginName }; } + const settings = getExtensionSettings(extensionId); + if (settings.cleanOutput && !(await confirmDeletionOnCleanOutput())) { + // cancel generation and open settings + return vscode.commands.executeCommand('workbench.action.openSettings', 'kiota.cleanOutput.enabled'); + } let config = await generateSteps( availableStateInfo, languagesInformation, @@ -101,7 +107,6 @@ export class GenerateClientCommand extends Command { return; } - const settings = getExtensionSettings(extensionId); this._setWorkspaceGenerationContext({ generationType: config.generationType as string }); let result; switch (generationType) { diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts index b9ca84c3ed..79939712cf 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts @@ -40,8 +40,8 @@ export class RegenerateService { this._clientKey, clientObjectItem.clientNamespaceName, clientObjectItem.usesBackingStore ? clientObjectItem.usesBackingStore : settings.backingStore, - true, // clearCache - true, // cleanOutput + settings.clearCache, + settings.cleanOutput, clientObjectItem.excludeBackwardCompatible ? clientObjectItem.excludeBackwardCompatible : settings.excludeBackwardCompatible, clientObjectItem.disabledValidationRules ? clientObjectItem.disabledValidationRules : settings.disableValidationRules, settings.languagesSerializationConfiguration[language].serializers, diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts index 7319264b44..8045522017 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts @@ -7,7 +7,8 @@ import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; import { getExtensionSettings } from "../../types/extensionSettings"; import { WorkspaceGenerationContext } from "../../types/WorkspaceGenerationContext"; import { isClientType, isPluginType } from "../../util"; -import { confirmOverride } from "../../utilities/regeneration"; +import { confirmDeletionOnCleanOutput } from "../../utilities/generation"; +import { confirmOverwriteOnRegenerate } from "../../utilities/regeneration"; import { Command } from "../Command"; import { RegenerateService } from "./regenerate.service"; @@ -23,8 +24,14 @@ export class RegenerateButtonCommand extends Command { public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise { const configuration = getGenerationConfiguration(); - const regenerate = await confirmOverride(); - if (!regenerate) { + const settings = getExtensionSettings(extensionId); + if (settings.cleanOutput) { + const accept = await confirmDeletionOnCleanOutput(); + if (!accept) { + // cancel generation and open settings + return vscode.commands.executeCommand('workbench.action.openSettings', 'kiota.cleanOutput.enabled'); + } + } else if (!(await confirmOverwriteOnRegenerate())) { return; } @@ -39,7 +46,6 @@ export class RegenerateButtonCommand extends Command { }); } - const settings = getExtensionSettings(extensionId); const selectedPaths = this._openApiTreeProvider.getSelectedPaths(); if (selectedPaths.length === 0) { await vscode.window.showErrorMessage( diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts index c4c0d673fc..69f50888fe 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts @@ -6,7 +6,8 @@ import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; import { getExtensionSettings } from "../../types/extensionSettings"; import { WorkspaceGenerationContext } from "../../types/WorkspaceGenerationContext"; import { isClientType, isPluginType } from "../../util"; -import { confirmOverride } from "../../utilities/regeneration"; +import { confirmDeletionOnCleanOutput } from "../../utilities/generation"; +import { confirmOverwriteOnRegenerate } from "../../utilities/regeneration"; import { Command } from "../Command"; import { RegenerateService } from "./regenerate.service"; @@ -21,12 +22,17 @@ export class RegenerateCommand extends Command { } public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise { - const regenerate = await confirmOverride(); - if (!regenerate) { + const settings = getExtensionSettings(extensionId); + if (settings.cleanOutput) { + const accept = await confirmDeletionOnCleanOutput(); + if (!accept) { + // cancel generation and open settings + return vscode.commands.executeCommand('workbench.action.openSettings', 'kiota.cleanOutput.enabled'); + } + } else if (!(await confirmOverwriteOnRegenerate())) { 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( @@ -46,6 +52,6 @@ export class RegenerateCommand extends Command { await regenerateService.regenerateTeamsApp(workspaceJson, clientOrPluginKey); } } - await vscode.commands.executeCommand('kiota.workspace.refresh'); + await vscode.commands.executeCommand('kiota.workspace.refresh'); } } \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/modules/steps/generateSteps.ts b/vscode/microsoft-kiota/src/modules/steps/generateSteps.ts index e26c457efa..38d0ef09cc 100644 --- a/vscode/microsoft-kiota/src/modules/steps/generateSteps.ts +++ b/vscode/microsoft-kiota/src/modules/steps/generateSteps.ts @@ -52,18 +52,18 @@ export async function generateSteps(existingConfiguration: Partial { + const yesAnswer = l10n.t("Yes, proceed"); + const noAnswer = l10n.t("Change configuration"); + const message = l10n.t("All existing files in the output directory are going to be deleted."); + const confirmation = await window.showWarningMessage( + message, yesAnswer, noAnswer + ); + return confirmation === yesAnswer; +} diff --git a/vscode/microsoft-kiota/src/utilities/regeneration.ts b/vscode/microsoft-kiota/src/utilities/regeneration.ts index 5a8f8a775d..1e2ec2d47a 100644 --- a/vscode/microsoft-kiota/src/utilities/regeneration.ts +++ b/vscode/microsoft-kiota/src/utilities/regeneration.ts @@ -1,6 +1,6 @@ import * as vscode from "vscode"; -export async function confirmOverride(): Promise { +export async function confirmOverwriteOnRegenerate(): Promise { const yesAnswer = vscode.l10n.t("Yes, override it"); const confirmation = await vscode.window .showWarningMessage( @@ -9,4 +9,4 @@ export async function confirmOverride(): Promise { vscode.l10n.t("Cancel") ); return confirmation === yesAnswer; -} \ No newline at end of file +}