Skip to content

Commit

Permalink
add regeneration button on api explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
ElinorW committed May 13, 2024
1 parent b03f5b2 commit 2bebba5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
4 changes: 2 additions & 2 deletions vscode/microsoft-kiota/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
5 changes: 4 additions & 1 deletion vscode/microsoft-kiota/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}
2 changes: 1 addition & 1 deletion vscode/microsoft-kiota/src/codelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
53 changes: 27 additions & 26 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -421,41 +440,22 @@ export async function activate(
await exportLogsAndShowErrors(result);
}
}
async function regenerateClient(clientKey: string, clientObject:any, settings: ExtensionSettings): Promise<void> {
async function regenerateClient(clientKey: string, clientObject:any, settings: ExtensionSettings, selectedPaths?: string[]): Promise<void> {
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,
Expand All @@ -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
Expand Down

0 comments on commit 2bebba5

Please sign in to comment.