From 124327698ff1c4bae202a502772e77cbcc21899e Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 12:41:03 +0300 Subject: [PATCH 1/8] enable correct icons --- vscode/microsoft-kiota/src/commands/editPathsCommand.ts | 8 ++++++-- .../searchOrOpenApiDescriptionCommand.ts | 6 +++++- .../microsoft-kiota/src/providers/openApiTreeProvider.ts | 1 - 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts index f15882825c..f99e501f88 100644 --- a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts +++ b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts @@ -24,12 +24,16 @@ export class EditPathsCommand extends Command { public async execute({ clientOrPluginKey, clientOrPluginObject }: Partial): Promise { await this.loadEditPaths(clientOrPluginKey!, clientOrPluginObject!); this.openApiTreeProvider.resetInitialState(); - await updateTreeViewIcons(treeViewId, false, true); await vscode.commands.executeCommand('kiota.workspace.refresh'); } private async loadEditPaths(clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties) { - await openTreeViewWithProgress(() => this.openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject)); + await openTreeViewWithProgress( + async () => { + await this.openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject); + await updateTreeViewIcons(treeViewId, false, true); + } + ); const regenerateAnswer = vscode.l10n.t("Regenerate"); const showGenerateMessage = this.context.globalState.get(SHOW_MESSAGE_AFTER_API_LOAD, true); diff --git a/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts b/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts index 4dbca1de20..a4eec01cc3 100644 --- a/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts +++ b/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts @@ -6,6 +6,7 @@ import { setDeepLinkParams } from "../../handlers/deepLinkParamsHandler"; import { searchSteps } from "../../modules/steps/searchSteps"; import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; import { getExtensionSettings } from "../../types/extensionSettings"; +import { updateTreeViewIcons } from "../../util"; import { IntegrationParams, validateDeepLinkQueryParams } from "../../utilities/deep-linking"; import { openTreeViewWithProgress } from "../../utilities/progress"; import { Command } from "../Command"; @@ -60,7 +61,10 @@ export class SearchOrOpenApiDescriptionCommand extends Command { })); if (config.descriptionPath) { - await openTreeViewWithProgress(() => this.openApiTreeProvider.setDescriptionUrl(config.descriptionPath!)); + await openTreeViewWithProgress(async () => { + await this.openApiTreeProvider.setDescriptionUrl(config.descriptionPath!); + await updateTreeViewIcons(treeViewId, true, false); + }); const generateAnswer = vscode.l10n.t("Generate"); const showGenerateMessage = this.context.globalState.get(SHOW_MESSAGE_AFTER_API_LOAD, true); diff --git a/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts b/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts index 56622108b4..8b433d01f9 100644 --- a/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts +++ b/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts @@ -353,7 +353,6 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider Date: Wed, 11 Dec 2024 13:17:29 +0300 Subject: [PATCH 2/8] close description before removing from --- .../deleteWorkspaceItem/deleteWorkspaceItemCommand.ts | 10 +++++++++- vscode/microsoft-kiota/src/extension.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts b/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts index 8d84b15a3e..e72ca8f870 100644 --- a/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts +++ b/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts @@ -3,6 +3,8 @@ import * as vscode from "vscode"; import { extensionId } from "../../constants"; import { getLogEntriesForLevel, KiotaLogEntry, LogLevel } from "../../kiotaInterop"; +import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; +import { SharedService } from "../../providers/sharedService"; import { WorkspaceTreeItem } from "../../providers/workspaceTreeProvider"; import { isPluginType } from "../../util"; import { exportLogsAndShowErrors } from "../../utilities/logging"; @@ -12,7 +14,9 @@ import { removeClient, removePlugin } from "./removeItem"; export class DeleteWorkspaceItemCommand extends Command { constructor( private _context: vscode.ExtensionContext, - private _kiotaOutputChannel: vscode.LogOutputChannel + private _openApiTreeProvider: OpenApiTreeProvider, + private _kiotaOutputChannel: vscode.LogOutputChannel, + private sharedService: SharedService ) { super(); } @@ -33,6 +37,10 @@ export class DeleteWorkspaceItemCommand extends Command { ); if (response?.title === yesAnswer.title) { + if (this.sharedService.get('clientOrPluginKey') === workspaceTreeItem.label) { + this._openApiTreeProvider.closeDescription(); + } + const result = await this.deleteItem(type, workspaceTreeItem); if (result) { const isSuccess = result.some(k => k.message.includes('removed successfully')); diff --git a/vscode/microsoft-kiota/src/extension.ts b/vscode/microsoft-kiota/src/extension.ts index a11d7471da..19e9828adc 100644 --- a/vscode/microsoft-kiota/src/extension.ts +++ b/vscode/microsoft-kiota/src/extension.ts @@ -82,7 +82,7 @@ export async function activate( const closeDescriptionCommand = new CloseDescriptionCommand(openApiTreeProvider); const statusCommand = new StatusCommand(); const selectLockCommand = new SelectLockCommand(openApiTreeProvider); - const deleteWorkspaceItemCommand = new DeleteWorkspaceItemCommand(context, kiotaOutputChannel); + const deleteWorkspaceItemCommand = new DeleteWorkspaceItemCommand(context, openApiTreeProvider, kiotaOutputChannel, sharedService); const updateClientsCommand = new UpdateClientsCommand(context, kiotaOutputChannel); await loadTreeView(context, workspaceTreeProvider); From 4e4a0bdd4e5807d7863ecf528ea1020b44bc870d Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 13:18:28 +0300 Subject: [PATCH 3/8] refresh workspace tree (even) when workspace file is closed --- .../deleteWorkspaceItem/deleteWorkspaceItemCommand.ts | 1 + .../src/commands/generate/generateClientCommand.ts | 1 + .../src/commands/regenerate/regenerateButtonCommand.ts | 1 + .../src/commands/regenerate/regenerateCommand.ts | 1 + .../src/providers/workspaceTreeProvider.ts | 8 -------- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts b/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts index e72ca8f870..4eb9b79c05 100644 --- a/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts +++ b/vscode/microsoft-kiota/src/commands/deleteWorkspaceItem/deleteWorkspaceItemCommand.ts @@ -44,6 +44,7 @@ export class DeleteWorkspaceItemCommand extends Command { const result = await this.deleteItem(type, workspaceTreeItem); if (result) { const isSuccess = result.some(k => k.message.includes('removed successfully')); + await vscode.commands.executeCommand('kiota.workspace.refresh'); if (isSuccess) { void vscode.window.showInformationMessage(vscode.l10n.t('{0} removed successfully.', workspaceTreeItem.label)); } else { diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index 172f138fa6..c7e21c47f0 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -172,6 +172,7 @@ export class GenerateClientCommand extends Command { } else { await displayGenerationResults(this._openApiTreeProvider, config); } + await vscode.commands.executeCommand('kiota.workspace.refresh'); } clearDeepLinkParams(); // Clear the state after successful generation diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts index 44e07ad3ff..7319264b44 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts @@ -61,6 +61,7 @@ export class RegenerateButtonCommand extends Command { await regenerateService.regenerateTeamsApp(workspaceJson, clientOrPluginKey); } } + await vscode.commands.executeCommand('kiota.workspace.refresh'); } } \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts index d9647fe9b6..c4c0d673fc 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts @@ -46,5 +46,6 @@ export class RegenerateCommand extends Command { await regenerateService.regenerateTeamsApp(workspaceJson, clientOrPluginKey); } } + await vscode.commands.executeCommand('kiota.workspace.refresh'); } } \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts index a7ed3f9943..bbf07f5f04 100644 --- a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts +++ b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts @@ -139,12 +139,4 @@ export async function loadTreeView(context: vscode.ExtensionContext, treeDataPro await vscode.commands.executeCommand('kiota.editPaths', label, properties, category); }) ); - context.subscriptions.push( - vscode.workspace.onDidChangeTextDocument(async (event: vscode.TextDocumentChangeEvent) => { - const document = event.document; - if (document.fileName.endsWith(KIOTA_WORKSPACE_FILE)) { - await vscode.commands.executeCommand('kiota.workspace.refresh'); - } - }) - ); }; \ No newline at end of file From 6704fceed9362c60295e9b15598c19d0f9328179 Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 13:45:15 +0300 Subject: [PATCH 4/8] refresh workspace view after selecting a tree item --- vscode/microsoft-kiota/src/commands/editPathsCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts index f99e501f88..e2eb7c6060 100644 --- a/vscode/microsoft-kiota/src/commands/editPathsCommand.ts +++ b/vscode/microsoft-kiota/src/commands/editPathsCommand.ts @@ -24,7 +24,6 @@ export class EditPathsCommand extends Command { public async execute({ clientOrPluginKey, clientOrPluginObject }: Partial): Promise { await this.loadEditPaths(clientOrPluginKey!, clientOrPluginObject!); this.openApiTreeProvider.resetInitialState(); - await vscode.commands.executeCommand('kiota.workspace.refresh'); } private async loadEditPaths(clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties) { @@ -32,6 +31,7 @@ export class EditPathsCommand extends Command { async () => { await this.openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject); await updateTreeViewIcons(treeViewId, false, true); + await vscode.commands.executeCommand('kiota.workspace.refresh'); } ); From fcc8361be3c92537a31c451de77ee786a6d74687 Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 14:52:23 +0300 Subject: [PATCH 5/8] load workspace file without needing file to be open --- .../src/modules/workspace/workspaceContentService.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vscode/microsoft-kiota/src/modules/workspace/workspaceContentService.ts b/vscode/microsoft-kiota/src/modules/workspace/workspaceContentService.ts index a7997b2444..1ea61a6882 100644 --- a/vscode/microsoft-kiota/src/modules/workspace/workspaceContentService.ts +++ b/vscode/microsoft-kiota/src/modules/workspace/workspaceContentService.ts @@ -3,7 +3,6 @@ import * as path from 'path'; import * as fs from 'fs'; import { WorkspaceContent } from "."; -import { KIOTA_WORKSPACE_FILE } from "../../constants"; import { getWorkspaceJsonPath } from '../../util'; class WorkspaceContentService { @@ -15,11 +14,7 @@ class WorkspaceContentService { return; } try { - const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE)); - if (!workspaceJson) { - throw new Error('Workspace file not found'); - } - const content = workspaceJson.getText(); + const content = await fs.promises.readFile(getWorkspaceJsonPath(), 'utf-8'); return JSON.parse(content); } catch (error) { console.error('Error loading workspace.json:', error); From 30f04fc5c0b313f8f62366b6a6fed63c6df0aac5 Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 14:52:55 +0300 Subject: [PATCH 6/8] show workspace file content on first load --- .../src/providers/workspaceTreeProvider.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts index bbf07f5f04..51563edfdf 100644 --- a/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts +++ b/vscode/microsoft-kiota/src/providers/workspaceTreeProvider.ts @@ -29,7 +29,6 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider { @@ -47,11 +46,15 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider 0; - const hasPlugins = this.workspaceContent?.plugins && Object.keys(this.workspaceContent.plugins).length > 0; - const collapsibleState = (hasClients || hasPlugins) ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed; - return [ - new WorkspaceTreeItem(KIOTA_WORKSPACE_FILE, collapsibleState, 'root') + const hasClients = this.workspaceContent.clients && Object.keys(this.workspaceContent.clients).length > 0; + const hasPlugins = this.workspaceContent.plugins && Object.keys(this.workspaceContent.plugins).length > 0; + const hasWorkspaceContent = hasClients || hasPlugins; + return hasWorkspaceContent ? [ + new WorkspaceTreeItem(KIOTA_WORKSPACE_FILE, + vscode.TreeItemCollapsibleState.Expanded, 'root') + ] : [ + new WorkspaceTreeItem(vscode.l10n.t('No clients or plugins are available'), + vscode.TreeItemCollapsibleState.None, 'info') ]; } @@ -64,9 +67,6 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider 0) { children.push(new WorkspaceTreeItem(PLUGINS, vscode.TreeItemCollapsibleState.Expanded, 'category')); } - if (children.length === 0) { - children.push(new WorkspaceTreeItem(vscode.l10n.t("No clients or plugins are available"), vscode.TreeItemCollapsibleState.None, 'info')); - } return children; } @@ -101,7 +101,7 @@ export class WorkspaceTreeProvider implements vscode.TreeDataProvider Date: Wed, 11 Dec 2024 14:58:51 +0300 Subject: [PATCH 7/8] fix delete workspace command tests after enhancement --- .../test/suite/commands/deleteWorkspaceItemCommand.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vscode/microsoft-kiota/src/test/suite/commands/deleteWorkspaceItemCommand.test.ts b/vscode/microsoft-kiota/src/test/suite/commands/deleteWorkspaceItemCommand.test.ts index b431e29e36..9b6debfb39 100644 --- a/vscode/microsoft-kiota/src/test/suite/commands/deleteWorkspaceItemCommand.test.ts +++ b/vscode/microsoft-kiota/src/test/suite/commands/deleteWorkspaceItemCommand.test.ts @@ -3,6 +3,8 @@ import * as sinon from "sinon"; import * as vscode from 'vscode'; import { DeleteWorkspaceItemCommand } from '../../../commands/deleteWorkspaceItem/deleteWorkspaceItemCommand'; +import * as treeModule from "../../../providers/openApiTreeProvider"; +import * as sharedServiceModule from '../../../providers/sharedService'; import { WorkspaceTreeItem } from '../../../providers/workspaceTreeProvider'; suite('DeleteWorkspaceItemCommand Tests', () => { @@ -14,7 +16,9 @@ suite('DeleteWorkspaceItemCommand Tests', () => { setup(() => { context = { extension: { packageJSON: { telemetryInstrumentationKey: 'test-key' } } } as any; outputChannel = { appendLine: sinon.stub() } as any; - command = new DeleteWorkspaceItemCommand(context, outputChannel); + var treeProvider = sinon.createStubInstance(treeModule.OpenApiTreeProvider); + var stubbedSharedService = sinon.createStubInstance(sharedServiceModule.SharedService); + command = new DeleteWorkspaceItemCommand(context, treeProvider, outputChannel, stubbedSharedService,); workspaceTreeItem = { label: 'test-item', category: 'plugin' } as any; }); From 66679e40179ff74d3509797200846aa365492a5c Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 11 Dec 2024 16:20:47 +0300 Subject: [PATCH 8/8] reset unnecessary changes --- .../openApidescription/searchOrOpenApiDescriptionCommand.ts | 6 +----- vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts b/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts index a4eec01cc3..4dbca1de20 100644 --- a/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts +++ b/vscode/microsoft-kiota/src/commands/openApidescription/searchOrOpenApiDescriptionCommand.ts @@ -6,7 +6,6 @@ import { setDeepLinkParams } from "../../handlers/deepLinkParamsHandler"; import { searchSteps } from "../../modules/steps/searchSteps"; import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; import { getExtensionSettings } from "../../types/extensionSettings"; -import { updateTreeViewIcons } from "../../util"; import { IntegrationParams, validateDeepLinkQueryParams } from "../../utilities/deep-linking"; import { openTreeViewWithProgress } from "../../utilities/progress"; import { Command } from "../Command"; @@ -61,10 +60,7 @@ export class SearchOrOpenApiDescriptionCommand extends Command { })); if (config.descriptionPath) { - await openTreeViewWithProgress(async () => { - await this.openApiTreeProvider.setDescriptionUrl(config.descriptionPath!); - await updateTreeViewIcons(treeViewId, true, false); - }); + await openTreeViewWithProgress(() => this.openApiTreeProvider.setDescriptionUrl(config.descriptionPath!)); const generateAnswer = vscode.l10n.t("Generate"); const showGenerateMessage = this.context.globalState.get(SHOW_MESSAGE_AFTER_API_LOAD, true); diff --git a/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts b/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts index 8b433d01f9..56622108b4 100644 --- a/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts +++ b/vscode/microsoft-kiota/src/providers/openApiTreeProvider.ts @@ -353,6 +353,7 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider