-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a new viewer for decompiled code based on virtual documents
- Replace the temporary files opened in normal text editors with virtual documents - Introduce a setting for the default output language of decompilation, which is overridable for single documents through editor toolbar. There is no need to open both C# and IL.
- Loading branch information
Showing
17 changed files
with
378 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*------------------------------------------------------------------------------------------------ | ||
* Copyright (c) 2021 ICSharpCode | ||
* Licensed under the MIT License. See LICENSE.TXT in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from "vscode"; | ||
import { DecompilerTextDocumentContentProvider } from "../decompiler/DecompilerTextDocumentContentProvider"; | ||
import { languageInfos } from "../decompiler/languageInfos"; | ||
import { ILSPY_URI_SCHEME } from "../decompiler/memberNodeUri"; | ||
import { getDefaultOutputLanguage } from "../decompiler/settings"; | ||
import { LanguageName } from "../protocol/DecompileResponse"; | ||
|
||
type OutputLanguageQuickPickItem = vscode.QuickPickItem & { | ||
languageName: string; | ||
}; | ||
|
||
export function registerSelectOutputLanguage( | ||
contentProvider: DecompilerTextDocumentContentProvider | ||
) { | ||
return vscode.commands.registerCommand( | ||
"ilspy.selectOutputLanguage", | ||
async () => { | ||
let document = vscode.window.activeTextEditor?.document; | ||
if (document?.uri.scheme !== ILSPY_URI_SCHEME) { | ||
return; | ||
} | ||
|
||
const language = await vscode.window.showQuickPick( | ||
Object.entries(languageInfos).map((languageInfoEntry) => { | ||
const [languageName, languageInfo] = languageInfoEntry; | ||
return { | ||
label: languageInfo.displayName, | ||
description: | ||
getDefaultOutputLanguage() === languageName | ||
? "default" | ||
: undefined, | ||
languageName, | ||
} as OutputLanguageQuickPickItem; | ||
}), | ||
{ | ||
title: "Please select language of decompiled code output", | ||
} | ||
); | ||
if (language) { | ||
contentProvider.setDocumentOutputLanguage( | ||
document.uri, | ||
language.languageName as LanguageName | ||
); | ||
vscode.languages.setTextDocumentLanguage( | ||
document, | ||
languageInfos[language.languageName].vsLanguageMode | ||
); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*------------------------------------------------------------------------------------------------ | ||
* Copyright (c) 2021 ICSharpCode | ||
* 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 { memberNodeToUri } from "../decompiler/memberNodeUri"; | ||
import { MemberNode } from "../decompiler/MemberNode"; | ||
import { languageInfos } from "../decompiler/languageInfos"; | ||
import { getDefaultOutputLanguage } from "../decompiler/settings"; | ||
|
||
let lastSelectedNode: MemberNode | undefined = undefined; | ||
|
||
export function registerShowCode( | ||
decompiledTreeProvider: DecompiledTreeProvider | ||
) { | ||
return vscode.commands.registerCommand( | ||
"showCode", | ||
async (node: MemberNode) => { | ||
if (lastSelectedNode === node) { | ||
return; | ||
} | ||
|
||
lastSelectedNode = node; | ||
|
||
let doc = await vscode.workspace.openTextDocument(memberNodeToUri(node)); | ||
vscode.languages.setTextDocumentLanguage( | ||
doc, | ||
languageInfos[getDefaultOutputLanguage()].vsLanguageMode | ||
); | ||
await vscode.window.showTextDocument(doc, { preview: true }); | ||
} | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.