|
1 | | -// Intentionally left empty |
2 | | -// Extension only provides debug adapter |
| 1 | +import * as vscode from "vscode"; |
| 2 | +import { DebugProtocol } from "@vscode/debugprotocol"; |
| 3 | +import { UAEDebugSessionVsc } from "./debugSessionVsc"; |
| 4 | + |
| 5 | +export async function activate( |
| 6 | + context: vscode.ExtensionContext |
| 7 | +): Promise<void> { |
| 8 | + const disassembledMemoryDataProvider = new DisassembledMemoryDataProvider(); |
| 9 | + vscode.window.registerTreeDataProvider( |
| 10 | + "disassembledMemory", |
| 11 | + disassembledMemoryDataProvider |
| 12 | + ); |
| 13 | + |
| 14 | + vscode.commands.registerCommand( |
| 15 | + "disassembledMemory.setDisassembledMemory", |
| 16 | + (memory: DebugProtocol.DisassembledInstruction[]) => |
| 17 | + disassembledMemoryDataProvider.setDisassembledMemory(memory) |
| 18 | + ); |
| 19 | + |
| 20 | + context.subscriptions.push( |
| 21 | + vscode.debug.registerDebugAdapterDescriptorFactory( |
| 22 | + "mame-m68k-debugger", |
| 23 | + new InlineDebugAdapterFactory() |
| 24 | + ) |
| 25 | + ); |
| 26 | +} |
| 27 | + |
| 28 | +class InlineDebugAdapterFactory |
| 29 | + implements vscode.DebugAdapterDescriptorFactory |
| 30 | +{ |
| 31 | + createDebugAdapterDescriptor( |
| 32 | + _session: vscode.DebugSession |
| 33 | + ): vscode.ProviderResult<vscode.DebugAdapterDescriptor> { |
| 34 | + // since DebugAdapterInlineImplementation is proposed API, a cast to <any> is required for now |
| 35 | + return new (vscode as any).DebugAdapterInlineImplementation( |
| 36 | + new UAEDebugSessionVsc() |
| 37 | + ); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +export class DisassembledMemoryDataProvider |
| 42 | + implements vscode.TreeDataProvider<ViewLineItem> |
| 43 | +{ |
| 44 | + private _onDidChangeTreeData: vscode.EventEmitter<ViewLineItem | undefined> = |
| 45 | + new vscode.EventEmitter<ViewLineItem | undefined>(); |
| 46 | + readonly onDidChangeTreeData: vscode.Event<ViewLineItem | undefined> = |
| 47 | + this._onDidChangeTreeData.event; |
| 48 | + private currentValues?: Array<ViewLineItem>; |
| 49 | + |
| 50 | + refresh(): void { |
| 51 | + this._onDidChangeTreeData.fire(undefined); |
| 52 | + } |
| 53 | + |
| 54 | + getTreeItem(element: ViewLineItem): vscode.TreeItem { |
| 55 | + return element; |
| 56 | + } |
| 57 | + |
| 58 | + async getChildren(element?: ViewLineItem): Promise<ViewLineItem[]> { |
| 59 | + if (!element && this.currentValues) { |
| 60 | + return this.currentValues; |
| 61 | + } else { |
| 62 | + return []; |
| 63 | + } |
| 64 | + } |
| 65 | + setDisassembledMemory(memory: DebugProtocol.DisassembledInstruction[]): void { |
| 66 | + this.currentValues = new Array<ViewLineItem>(); |
| 67 | + for (const dl of memory) { |
| 68 | + const item = new ViewLineItem(`${dl.address}: ${dl.instruction}`); |
| 69 | + if (dl.instructionBytes) { |
| 70 | + item.description = dl.instructionBytes; |
| 71 | + } |
| 72 | + this.currentValues.push(item); |
| 73 | + } |
| 74 | + this.refresh(); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +export class ViewLineItem extends vscode.TreeItem { |
| 79 | + public description = ""; |
| 80 | + |
| 81 | + constructor(label: string) { |
| 82 | + super(label, vscode.TreeItemCollapsibleState.None); |
| 83 | + } |
| 84 | + |
| 85 | + getDescription(): string { |
| 86 | + return this.description; |
| 87 | + } |
| 88 | +} |
0 commit comments