Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a subfolder to the default vscode output path #6054

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vscode/microsoft-kiota/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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');
baywet marked this conversation as resolved.
Show resolved Hide resolved
}
let config = await generateSteps(
availableStateInfo,
languagesInformation,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
baywet marked this conversation as resolved.
Show resolved Hide resolved
clientObjectItem.excludeBackwardCompatible ? clientObjectItem.excludeBackwardCompatible : settings.excludeBackwardCompatible,
clientObjectItem.disabledValidationRules ? clientObjectItem.disabledValidationRules : settings.disableValidationRules,
settings.languagesSerializationConfiguration[language].serializers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -23,8 +24,14 @@ export class RegenerateButtonCommand extends Command {

public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise<void> {
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;
}

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -21,12 +22,17 @@ export class RegenerateCommand extends Command {
}

public async execute({ generationType, clientOrPluginKey, clientOrPluginObject }: WorkspaceGenerationContext): Promise<void> {
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(
Expand All @@ -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');
}
}
22 changes: 11 additions & 11 deletions vscode/microsoft-kiota/src/modules/steps/generateSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ export async function generateSteps(existingConfiguration: Partial<GenerateState

let step = 1;
const folderSelectionOption = l10n.t('Browse your output directory');
let inputOptions = [
{ label: l10n.t('Default folder'), description: workspaceFolder },
{ label: folderSelectionOption }
];

function getOutputPath(workspaceFolder: string, clientName: string) {
const outputPath = path.join(workspaceFolder, clientName);
return [
{ label: l10n.t('Default folder'), description: outputPath },
{ label: folderSelectionOption }
];
}

function updateWorkspaceFolder(name: string | undefined) {
if (name && (!workspaceOpen)) {
workspaceFolder = getWorkspaceJsonDirectory(name);
inputOptions = [
{ label: l10n.t('Default folder'), description: workspaceFolder },
{ label: folderSelectionOption }
];
}
}
function getNextStepForGenerationType(generationType: string | QuickPickItem) {
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function generateSteps(existingConfiguration: Partial<GenerateState
step: step++,
totalSteps: 5,
placeholder: l10n.t('Enter an output path relative to the root of the project'),
items: inputOptions,
items: getOutputPath(workspaceFolder, state.clientClassName!),
calebkiage marked this conversation as resolved.
Show resolved Hide resolved
shouldResume: shouldResume
});
if (selectedOption) {
Expand Down Expand Up @@ -241,7 +241,7 @@ export async function generateSteps(existingConfiguration: Partial<GenerateState
step: step++,
totalSteps: 4,
placeholder: l10n.t('Enter an output path relative to the root of the project'),
items: inputOptions,
items: getOutputPath(workspaceFolder, state.clientClassName!),
shouldResume: shouldResume
});
if (selectedOption) {
Expand Down Expand Up @@ -297,7 +297,7 @@ export async function generateSteps(existingConfiguration: Partial<GenerateState
step: step++,
totalSteps: 4,
placeholder: l10n.t('Enter an output path relative to the root of the project'),
items: inputOptions,
items: getOutputPath(workspaceFolder, state.clientClassName!),
shouldResume: shouldResume
});
if (selectedOption) {
Expand Down
12 changes: 12 additions & 0 deletions vscode/microsoft-kiota/src/utilities/generation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {l10n, window} from "vscode";


export async function confirmDeletionOnCleanOutput(): Promise<boolean> {
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;
}
4 changes: 2 additions & 2 deletions vscode/microsoft-kiota/src/utilities/regeneration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";

export async function confirmOverride(): Promise<boolean> {
export async function confirmOverwriteOnRegenerate(): Promise<boolean> {
const yesAnswer = vscode.l10n.t("Yes, override it");
const confirmation = await vscode.window
.showWarningMessage(
Expand All @@ -9,4 +9,4 @@ export async function confirmOverride(): Promise<boolean> {
vscode.l10n.t("Cancel")
);
return confirmation === yesAnswer;
}
}
Loading