From be9aa98dd7145c8dfdecdd3e420f0877d8feffc7 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 12 Jan 2023 20:33:27 -0500 Subject: [PATCH] Add 'Reload Assembly' command Simplistic* approach but a time saver when using the extension. Partial fix for https://github.com/icsharpcode/ilspy-vscode/issues/88 * Pretty much `removeAssembly` and `addAssembly` but with a single `refresh` call. It would be cleaner to have a single call to the backend (maybe later). --- vscode-extension/package.json | 14 +++++++++++ .../src/commands/reloadAssembly.ts | 25 +++++++++++++++++++ .../src/decompiler/DecompiledTreeProvider.ts | 21 +++++++++++++++- vscode-extension/src/extension.ts | 2 ++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 vscode-extension/src/commands/reloadAssembly.ts diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 24704fb6..1040b541 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -77,6 +77,11 @@ "title": "Unload Assembly", "category": "ILSpy" }, + { + "command": "ilspy.reloadAssembly", + "title": "Reload Assembly", + "category": "ILSpy" + }, { "command": "ilspy.selectOutputLanguage", "title": "Output language", @@ -99,6 +104,11 @@ "command": "ilspy.unloadAssembly", "when": "view == ilspyDecompiledMembers && viewItem == assemblyNode", "group": "1_GeneralCommands@1" + }, + { + "command": "ilspy.reloadAssembly", + "when": "view == ilspyDecompiledMembers && viewItem == assemblyNode", + "group": "1_GeneralCommands@1" } ], "editor/title": [ @@ -121,6 +131,10 @@ "command": "ilspy.unloadAssembly", "when": "ilspy.backendAvailable" }, + { + "command": "ilspy.reloadAssembly", + "when": "ilspy.backendAvailable" + }, { "command": "ilspy.selectOutputLanguage", "when": "resourceScheme == ilspy" diff --git a/vscode-extension/src/commands/reloadAssembly.ts b/vscode-extension/src/commands/reloadAssembly.ts new file mode 100644 index 00000000..832f20fd --- /dev/null +++ b/vscode-extension/src/commands/reloadAssembly.ts @@ -0,0 +1,25 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as vscode from "vscode"; +import { DecompiledTreeProvider } from "../decompiler/DecompiledTreeProvider"; +import { MemberNode } from "../decompiler/MemberNode"; + +export function registerReloadAssembly( + decompiledTreeProvider: DecompiledTreeProvider +) { + return vscode.commands.registerCommand( + "ilspy.reloadAssembly", + async (node: MemberNode) => { + if (!node) { + vscode.window.showInformationMessage( + 'Please use context menu: right-click on the assembly node then select "Reload Assembly"' + ); + return; + } + await decompiledTreeProvider.reloadAssembly(node.assembly); + } + ); +} diff --git a/vscode-extension/src/decompiler/DecompiledTreeProvider.ts b/vscode-extension/src/decompiler/DecompiledTreeProvider.ts index 7e9dc21b..2c8c93d3 100644 --- a/vscode-extension/src/decompiler/DecompiledTreeProvider.ts +++ b/vscode-extension/src/decompiler/DecompiledTreeProvider.ts @@ -65,6 +65,25 @@ export class DecompiledTreeProvider implements TreeDataProvider { return response?.removed ?? false; } + public async reloadAssembly(assembly: string): Promise { + const response = await this.backend.sendRemoveAssembly({ + assemblyPath: assembly, + }); + if (response?.removed) { + this.backend.assemblies.delete(assembly); + + const response = await this.backend.sendAddAssembly({ + assemblyPath: assembly, + }); + if (response?.added && response?.assemblyData) { + this.backend.assemblies.set(assembly, response.assemblyData); + this.refresh(); + return true; + } + } + return false; + } + public getTreeItem(element: MemberNode): TreeItem { return { label: element.name, @@ -191,7 +210,7 @@ export class DecompiledTreeProvider implements TreeDataProvider { } public getParent?(element: MemberNode): ProviderResult { - // Note: This allows relealing of assembly nodes in TreeView, which are placed in root. It won't work for other nodes. + // Note: This allows releasing of assembly nodes in TreeView, which are placed in root. It won't work for other nodes. return undefined; } diff --git a/vscode-extension/src/extension.ts b/vscode-extension/src/extension.ts index 2decc83c..d6f129f0 100644 --- a/vscode-extension/src/extension.ts +++ b/vscode-extension/src/extension.ts @@ -14,6 +14,7 @@ import ILSpyBackend from "./decompiler/ILSpyBackend"; import { DecompiledTreeProvider } from "./decompiler/DecompiledTreeProvider"; import { registerDecompileAssemblyInWorkspace } from "./commands/decompileAssemblyInWorkspace"; import { registerDecompileAssemblyViaDialog } from "./commands/decompileAssemblyViaDialog"; +import { registerReloadAssembly } from "./commands/reloadAssembly"; import { registerUnloadAssembly } from "./commands/unloadAssembly"; import { acquireDotnetRuntime } from "./dotnet-acquire/acquire"; import OutputWindowLogger from "./OutputWindowLogger"; @@ -116,6 +117,7 @@ export async function activate(context: ExtensionContext) { disposables.push( registerSelectOutputLanguage(decompilerTextDocumentContentProvider) ); + disposables.push(registerReloadAssembly(decompileTreeProvider)); disposables.push(registerUnloadAssembly(decompileTreeProvider)); context.subscriptions.push(...disposables);