Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Reload Assembly' command #103

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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