Skip to content

Commit

Permalink
Merge pull request #103 from spouliot/reload
Browse files Browse the repository at this point in the history
Add 'Reload Assembly' command
  • Loading branch information
Rpinski authored Jan 13, 2023
2 parents ea51c81 + be9aa98 commit 9b70d5f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
14 changes: 14 additions & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
"title": "Unload Assembly",
"category": "ILSpy"
},
{
"command": "ilspy.reloadAssembly",
"title": "Reload Assembly",
"category": "ILSpy"
},
{
"command": "ilspy.selectOutputLanguage",
"title": "Output language",
Expand All @@ -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": [
Expand All @@ -121,6 +131,10 @@
"command": "ilspy.unloadAssembly",
"when": "ilspy.backendAvailable"
},
{
"command": "ilspy.reloadAssembly",
"when": "ilspy.backendAvailable"
},
{
"command": "ilspy.selectOutputLanguage",
"when": "resourceScheme == ilspy"
Expand Down
25 changes: 25 additions & 0 deletions vscode-extension/src/commands/reloadAssembly.ts
Original file line number Diff line number Diff line change
@@ -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);
}
);
}
21 changes: 20 additions & 1 deletion vscode-extension/src/decompiler/DecompiledTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ export class DecompiledTreeProvider implements TreeDataProvider<MemberNode> {
return response?.removed ?? false;
}

public async reloadAssembly(assembly: string): Promise<boolean> {
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,
Expand Down Expand Up @@ -191,7 +210,7 @@ export class DecompiledTreeProvider implements TreeDataProvider<MemberNode> {
}

public getParent?(element: MemberNode): ProviderResult<MemberNode> {
// 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;
}

Expand Down
2 changes: 2 additions & 0 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9b70d5f

Please sign in to comment.