diff --git a/vscode/microsoft-kiota/package-lock.json b/vscode/microsoft-kiota/package-lock.json index 28b6e2182d..423a71fd7d 100644 --- a/vscode/microsoft-kiota/package-lock.json +++ b/vscode/microsoft-kiota/package-lock.json @@ -1,12 +1,12 @@ { "name": "kiota", - "version": "1.13.100000001", + "version": "1.14.100000001", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kiota", - "version": "1.13.100000001", + "version": "1.14.100000001", "dependencies": { "@vscode/extension-telemetry": "^0.9.6", "@vscode/l10n": "^0.0.18", diff --git a/vscode/microsoft-kiota/package.json b/vscode/microsoft-kiota/package.json index af3bf0deb4..1c167733bc 100644 --- a/vscode/microsoft-kiota/package.json +++ b/vscode/microsoft-kiota/package.json @@ -240,22 +240,27 @@ { "command": "kiota.openApiExplorer.searchOrOpenApiDescription", "when": "view == kiota.openApiExplorer", - "group": "navigation@2" + "group": "navigation@1" }, { "command": "kiota.openApiExplorer.filterDescription", "when": "view == kiota.openApiExplorer", - "group": "navigation@3" + "group": "navigation@2" }, { "command": "kiota.openApiExplorer.generateClient", "when": "view == kiota.openApiExplorer", - "group": "navigation@4" + "group": "navigation@3" }, { "command": "kiota.openApiExplorer.openFile", "when": "view == kiota.workspace", - "group": "navigation@2" + "group": "navigation@1" + }, + { + "command": "kiota.openApiExplorer.regenerateButton", + "when": "view == kiota.openApiExplorer", + "group": "navigation@4" } ], "view/item/context": [ @@ -352,6 +357,13 @@ "enablement": "kiota.openApiExplorer.showIcons", "icon": "$(run-all)" }, + { + "command": "kiota.openApiExplorer.regenerateButton", + "category": "Kiota", + "title": "%kiota.openApiExplorer.regenerateButton.title%", + "enablement": "kiota.openApiExplorer.showRegenerateIcon", + "icon": "$(sync)" + }, { "command": "kiota.openApiExplorer.filterDescription", "category": "Kiota", @@ -413,11 +425,11 @@ }, { "command": "kiota.editPaths", - "title": "Edit Paths" + "title": "%kiota.openApiExplorer.editPaths.title%" }, { "command": "kiota.regenerate", - "title": "Re-generate" + "title": "%kiota.openApiExplorer.regenerateButton.title%" } ], "languages": [ diff --git a/vscode/microsoft-kiota/package.nls.json b/vscode/microsoft-kiota/package.nls.json index a182f66c42..858bcaec74 100644 --- a/vscode/microsoft-kiota/package.nls.json +++ b/vscode/microsoft-kiota/package.nls.json @@ -29,5 +29,8 @@ "kiota.generate.structuredMimeTypes.description": "The MIME types and preference to use for structured data model generation. As per RFC9110 Accept header notation.", "kiota.generate.includeAdditionalData.description": "Will include the 'AdditionalData' property for models", "kiota.workspace.name": "My Workspace", - "kiota.openApiExplorer.openFile.title": "Open file" + "kiota.openApiExplorer.openFile.title": "Open file", + "kiota.openApiExplorer.regenerateButton.title": "Re-generate", + "kiota.openApiExplorer.editPaths.title": "Edit paths" + } diff --git a/vscode/microsoft-kiota/src/codelensProvider.ts b/vscode/microsoft-kiota/src/codelensProvider.ts index b6aea433e7..fdb0896dad 100644 --- a/vscode/microsoft-kiota/src/codelensProvider.ts +++ b/vscode/microsoft-kiota/src/codelensProvider.ts @@ -21,7 +21,7 @@ export class CodeLensProvider implements vscode.CodeLensProvider { const editPathsCommand = { title: "Edit Paths", command: "kiota.editPaths", - arguments: [clientObject] + arguments: [clientKey, clientObject] }; codeLenses.push(new vscode.CodeLens(rangeBeforeClient, editPathsCommand)); const regenerateCommand = { diff --git a/vscode/microsoft-kiota/src/extension.ts b/vscode/microsoft-kiota/src/extension.ts index 635ebde33c..cccd48a11c 100644 --- a/vscode/microsoft-kiota/src/extension.ts +++ b/vscode/microsoft-kiota/src/extension.ts @@ -39,6 +39,8 @@ const treeViewId = `${extensionId}.openApiExplorer`; const treeViewFocusCommand = `${treeViewId}${focusCommandId}`; const dependenciesInfo = `${extensionId}.dependenciesInfo`; export const kiotaLockFile = "workspace.json"; +let globalClientKey: string; +let globalClientObject: any; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -222,6 +224,7 @@ export async function activate( if (config.descriptionPath) { await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(config.descriptionPath!)); await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, true); + await vscode.commands.executeCommand('setContext', `${treeViewId}.showRegenerateIcon`, false); } } ), @@ -266,10 +269,26 @@ export async function activate( `${treeViewId}.pasteManifest`, () => openManifestFromClipboard(openApiTreeProvider, "") ), - registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientObject: any) => { - await loadEditPaths(clientObject, openApiTreeProvider); - await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, true); + registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientKey: string, clientObject: any) => { + globalClientKey = clientKey; + globalClientObject = clientObject; + await loadEditPaths(clientObject, openApiTreeProvider); + await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, false); + await vscode.commands.executeCommand('setContext', `${treeViewId}.showRegenerateIcon`, true); }), + + vscode.commands.registerCommand(`${treeViewId}.regenerateButton`, async (clientKey: string, clientObject: any) => { + 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") + ); + } + await regenerateClient(globalClientKey, globalClientObject, settings, selectedPaths); + }), + + registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async (clientKey: string, clientObject: any) => { const settings = getExtensionSettings(extensionId); await regenerateClient(clientKey, clientObject, settings); @@ -421,41 +440,22 @@ export async function activate( await exportLogsAndShowErrors(result); } } - async function regenerateClient(clientKey: string, clientObject:any, settings: ExtensionSettings): Promise { + async function regenerateClient(clientKey: string, clientObject:any, settings: ExtensionSettings, selectedPaths?: string[]): Promise { const language = typeof clientObject.language === "string" ? parseGenerationLanguage(clientObject.language) : KiotaGenerationLanguage.CSharp; - console.log( - context, - clientObject.descriptionLocation, - clientObject.outputPath, - language, - clientObject.includePatterns, - clientObject.excludePatterns, - clientKey, - clientObject.clientNamespaceName, - clientObject.usesBackingStore, - true, // clearCache - true, // cleanOutput - clientObject.excludeBackwardCompatible, - clientObject.disabledValidationRules, - settings.languagesSerializationConfiguration[language].serializers, - settings.languagesSerializationConfiguration[language].deserializers, - clientObject.structuredMimeTypes, - clientObject.includeAdditionalData - ); await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, - title: vscode.l10n.t("Generating client...") + title: vscode.l10n.t("Re-generating client...") }, async (progress, _) => { const result = await generateClient( context, clientObject.descriptionLocation, clientObject.outputPath, language, - clientObject.includePatterns, + selectedPaths ? selectedPaths : clientObject.includePatterns, clientObject.excludePatterns, clientKey, clientObject.clientNamespaceName, @@ -473,7 +473,8 @@ export async function activate( return result; }); - void vscode.window.showInformationMessage(`Client ${clientKey} regenerated successfully.`); + void vscode.window.showInformationMessage(`Client ${clientKey} re-generated successfully.`); + openApiTreeProvider.closeDescription(); } // create a new status bar item that we can now manage