tool to apply decompiler suggestions on define-externs

This commit is contained in:
Hat Kid 2024-01-18 20:05:29 +01:00
parent 381a18f3d7
commit 3119c06513
2 changed files with 26 additions and 0 deletions

View file

@ -131,6 +131,10 @@
"command": "opengoal.decomp.misc.genMethodStubs",
"title": "OpenGOAL - Misc - Generate Method Stubs"
},
{
"command": "opengoal.decomp.misc.applyDecompilerSuggestions",
"title": "OpenGOAL - Misc - Apply Decompiler Suggestions to Selection"
},
{
"command": "opengoal.decomp.typeSearcher.open",
"title": "OpenGOAL - Misc - Type Searcher"

View file

@ -439,6 +439,22 @@ async function genMethodStubs() {
return;
}
async function applyDecompilerSuggestions() {
const editor = vscode.window.activeTextEditor;
if (editor === undefined || editor.selection.isEmpty) {
return;
}
editor.edit((selectedText) => {
const content = editor.document.getText(editor.selection);
const result = content.replace(
/\(define-extern (\S+) (\S+)\) ;; (.+)/g,
"(define-extern $1 $3)",
);
selectedText.replace(editor.selection, result);
});
}
export async function activateMiscDecompTools() {
getExtensionContext().subscriptions.push(
vscode.commands.registerCommand(
@ -482,4 +498,10 @@ export async function activateMiscDecompTools() {
genMethodStubs,
),
);
getExtensionContext().subscriptions.push(
vscode.commands.registerCommand(
"opengoal.decomp.misc.applyDecompilerSuggestions",
applyDecompilerSuggestions,
),
);
}