From 77cba1e4ffdfe2ca7c60d13c97b9f1e93baf5f83 Mon Sep 17 00:00:00 2001 From: ElinorW Date: Tue, 21 May 2024 19:46:11 +0300 Subject: [PATCH] add types --- vscode/microsoft-kiota/src/extension.ts | 27 +++++++++++----------- vscode/microsoft-kiota/src/kiotaInterop.ts | 25 +++++++++++++++++++- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/vscode/microsoft-kiota/src/extension.ts b/vscode/microsoft-kiota/src/extension.ts index 0f424fb8e2..db3cfea594 100644 --- a/vscode/microsoft-kiota/src/extension.ts +++ b/vscode/microsoft-kiota/src/extension.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import * as fs from 'fs'; import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider"; import { + ClientOrPluginProperties, ConsumerOperation, generationLanguageToString, getLogEntriesForLevel, @@ -33,9 +34,9 @@ import { dependenciesInfo, extensionId, kiotaWorkspaceFile, statusBarCommandId, let kiotaStatusBarItem: vscode.StatusBarItem; let kiotaOutputChannel: vscode.LogOutputChannel; -let globalClientKey: string; -let globalClientObject: any; -let globalGenerationType: string; +let clientOrPluginKey: string; +let clientOrPluginObject: ClientOrPluginProperties; +let workspaceGenerationType: string; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -268,16 +269,16 @@ export async function activate( `${treeViewId}.pasteManifest`, () => openManifestFromClipboard(openApiTreeProvider, "") ), - registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientKey: string, clientObject: any, generationType: string) => { - globalClientKey = clientKey; - globalClientObject = clientObject; - globalGenerationType = generationType; + registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => { + clientOrPluginKey = clientKey; + clientOrPluginObject = clientObject; + workspaceGenerationType = generationType; 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 () => { + registerCommandWithTelemetry(reporter,`${treeViewId}.regenerateButton`, async () => { const settings = getExtensionSettings(extensionId); const selectedPaths = openApiTreeProvider.getSelectedPaths(); if (selectedPaths.length === 0) { @@ -286,15 +287,15 @@ export async function activate( ); return; } - if(globalGenerationType === "clients") { - await regenerateClient(globalClientKey, globalClientObject, settings, selectedPaths); + if(workspaceGenerationType === "clients") { + await regenerateClient(clientOrPluginKey, clientOrPluginObject, settings, selectedPaths); } - else if (globalGenerationType === "plugins") { - await regeneratePlugin(globalClientKey, globalClientObject, settings, selectedPaths); + else if (workspaceGenerationType === "plugins") { + await regeneratePlugin(clientOrPluginKey, clientOrPluginObject, settings, selectedPaths); } }), - registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async (clientKey: string, clientObject: any, generationType: string) => { + registerCommandWithTelemetry(reporter, `${extensionId}.regenerate`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => { const settings = getExtensionSettings(extensionId); const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(kiotaWorkspaceFile)); if (workspaceJson && workspaceJson.isDirty) { diff --git a/vscode/microsoft-kiota/src/kiotaInterop.ts b/vscode/microsoft-kiota/src/kiotaInterop.ts index 8f1f4477f4..d48b828d55 100644 --- a/vscode/microsoft-kiota/src/kiotaInterop.ts +++ b/vscode/microsoft-kiota/src/kiotaInterop.ts @@ -291,4 +291,27 @@ export interface GenerationConfiguration { usesBackingStore: boolean; pluginTypes: KiotaPluginType[]; operation: ConsumerOperation; -} \ No newline at end of file +} + +interface WorkspaceObjectProperties { + descriptionLocation: string; + includePatterns: string[]; + excludePatterns: string[]; + outputPath: string; +} + +interface ClientObjectProperties extends WorkspaceObjectProperties { + language: string; + structuredMimeTypes: string[]; + clientNamespaceName: string; + usesBackingStore: boolean; + includeAdditionalData: boolean; + excludeBackwardCompatible: boolean; + disabledValidationRules: string[]; +} + +interface PluginObjectProperties extends WorkspaceObjectProperties { + types: string[]; +} + +export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties; \ No newline at end of file