From 156c2f1b02bdeeb5ddffbfcb5e8e8b8f4b720cbf Mon Sep 17 00:00:00 2001 From: thewahome Date: Sat, 11 Jan 2025 08:13:02 +0300 Subject: [PATCH 1/2] update generation result display to read workspace JSON from file system --- .../microsoft-kiota/src/commands/generate/generation-util.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/generate/generation-util.ts b/vscode/microsoft-kiota/src/commands/generate/generation-util.ts index c372cb916f..7eb72a053d 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generation-util.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generation-util.ts @@ -1,14 +1,15 @@ import * as vscode from "vscode"; +import * as fs from 'fs'; import { KIOTA_WORKSPACE_FILE, treeViewId } from "../../constants"; import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; -import { updateTreeViewIcons } from "../../util"; +import { getWorkspaceJsonPath, updateTreeViewIcons } from "../../util"; export async function displayGenerationResults(openApiTreeProvider: OpenApiTreeProvider, config: any) { const clientNameOrPluginName = config.clientClassName || config.pluginName; const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE)); if (workspaceJson) { - const content = workspaceJson.getText(); + const content = await fs.promises.readFile(getWorkspaceJsonPath(), 'utf-8'); const workspace = JSON.parse(content); const clientOrPluginObject = workspace.plugins[clientNameOrPluginName] || workspace.clients[clientNameOrPluginName]; await openApiTreeProvider.loadEditPaths(clientNameOrPluginName, clientOrPluginObject); From 6dd8eb2d6d44259f5f7195e418883731554c2cae Mon Sep 17 00:00:00 2001 From: thewahome Date: Mon, 13 Jan 2025 09:15:46 +0300 Subject: [PATCH 2/2] edge case: do not trigger if not defined --- .../microsoft-kiota/src/commands/generate/generation-util.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vscode/microsoft-kiota/src/commands/generate/generation-util.ts b/vscode/microsoft-kiota/src/commands/generate/generation-util.ts index 7eb72a053d..ec5dcfc1d8 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generation-util.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generation-util.ts @@ -12,7 +12,9 @@ export async function displayGenerationResults(openApiTreeProvider: OpenApiTreeP const content = await fs.promises.readFile(getWorkspaceJsonPath(), 'utf-8'); const workspace = JSON.parse(content); const clientOrPluginObject = workspace.plugins[clientNameOrPluginName] || workspace.clients[clientNameOrPluginName]; - await openApiTreeProvider.loadEditPaths(clientNameOrPluginName, clientOrPluginObject); + if (clientOrPluginObject) { + await openApiTreeProvider.loadEditPaths(clientNameOrPluginName, clientOrPluginObject); + } } openApiTreeProvider.resetInitialState(); await updateTreeViewIcons(treeViewId, false, true);