diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index 99b896ede6..d570a8bee8 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -62,7 +62,7 @@ export class GenerateClientCommand extends Command { if (!deepLinkParams.name && this._openApiTreeProvider.apiTitle) { deepLinkParams.name = getSanitizedString(this._openApiTreeProvider.apiTitle); } - availableStateInfo = transformToGenerationConfig(deepLinkParams); + availableStateInfo = await transformToGenerationConfig(deepLinkParams); } else { const pluginName = getSanitizedString(this._openApiTreeProvider.apiTitle); availableStateInfo = { diff --git a/vscode/microsoft-kiota/src/test/suite/commands/generateClientCommand.test.ts b/vscode/microsoft-kiota/src/test/suite/commands/generateClientCommand.test.ts index edc0337b60..448448c9d3 100644 --- a/vscode/microsoft-kiota/src/test/suite/commands/generateClientCommand.test.ts +++ b/vscode/microsoft-kiota/src/test/suite/commands/generateClientCommand.test.ts @@ -173,7 +173,7 @@ suite('GenerateClientCommand Test Suite', () => { assert.strictEqual(!treeProvider.descriptionUrl, false); vscodeWindowSpy.verify(); sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context); - let stateInfo = transformToGenerationConfig(pluginParams); + let stateInfo = await transformToGenerationConfig(pluginParams); sinon.assert.calledOnceWithMatch(generateStepsFn, stateInfo, undefined , pluginParams); sinon.assert.calledOnce(showUpgradeWarningMessageStub); sinon.assert.calledOnceWithMatch(getExtensionSettingsStub, "kiota"); diff --git a/vscode/microsoft-kiota/src/utilities/deep-linking.ts b/vscode/microsoft-kiota/src/utilities/deep-linking.ts index c58663a711..4a6497cee7 100644 --- a/vscode/microsoft-kiota/src/utilities/deep-linking.ts +++ b/vscode/microsoft-kiota/src/utilities/deep-linking.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; import * as path from 'path'; +import { promises as fs } from 'fs'; import { GenerateState } from "../modules/steps/generateSteps"; import { KiotaGenerationLanguage, KiotaPluginType } from "../types/enums"; @@ -11,8 +11,8 @@ export function isDeeplinkEnabled(deepLinkParams: Partial): b return Object.values(deepLinkParams).filter(property => property).length >= minimumNumberOfParams; } -export function transformToGenerationConfig(deepLinkParams: Partial) - : Partial { +export async function transformToGenerationConfig(deepLinkParams: Partial) + : Promise> { const generationConfig: Partial = {}; if (deepLinkParams.kind === "client") { generationConfig.generationType = "client"; @@ -37,7 +37,7 @@ export function transformToGenerationConfig(deepLinkParams: Partial): string | undefined { +async function determineOutputPath(deepLinkParams: Partial): Promise { if (deepLinkParams.projectPath) { try { - if (!fs.existsSync(deepLinkParams.projectPath)) { + const exists = await fs.access(deepLinkParams.projectPath).then(() => true).catch(() => false); + if (!exists) { try { - fs.mkdirSync(deepLinkParams.projectPath); + await fs.mkdir(deepLinkParams.projectPath); } catch (err: unknown) { throw new Error(`Error creating directory: ${(err as Error).message}`); }