From b7f16d38d9af8e9723a2ea2d70574a76283bb2f3 Mon Sep 17 00:00:00 2001 From: Rahul Senna Date: Sat, 3 Sep 2022 13:30:25 +0530 Subject: [PATCH] refresh memory view when stepping through code --- package.json | 5 ----- src/MemoryViewerViewProvider.ts | 23 +++++++++++++++++++++++ src/extension.ts | 9 +-------- webview/src/MemoryViewer.tsx | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 262a251..bcb57b0 100644 --- a/package.json +++ b/package.json @@ -12,16 +12,11 @@ "Other" ], "activationEvents": [ - "onCommand:memoryViewer.helloWorld", "onView:memoryViewer.webview" ], "main": "./out/extension.js", "contributes": { "commands": [ - { - "command": "memoryViewer.helloWorld", - "title": "Hello World" - } ], "views": { "debug": [ diff --git a/src/MemoryViewerViewProvider.ts b/src/MemoryViewerViewProvider.ts index 0874fb4..40a1cd4 100644 --- a/src/MemoryViewerViewProvider.ts +++ b/src/MemoryViewerViewProvider.ts @@ -2,6 +2,7 @@ import { CancellationToken, Uri, Webview, WebviewView, WebviewViewProvider, Webv import { getUri } from "./utilites/getUri"; import * as vscode from 'vscode'; +let global_message: MemoryViewerReadMemoryRequest; export class MemoryViewerViewProvider implements WebviewViewProvider { public static readonly viewType = "memoryViewer.webview"; @@ -69,6 +70,7 @@ export class MemoryViewerViewProvider implements WebviewViewProvider { case "readMemory": const activeDebugSession = vscode.debug.activeDebugSession; if (activeDebugSession !== undefined) { + global_message = message; try { activeDebugSession.customRequest("readMemory", { memoryReference: message.address, @@ -88,6 +90,27 @@ export class MemoryViewerViewProvider implements WebviewViewProvider { break; } }); + vscode.window.onDidChangeTextEditorSelection(e => { + const activeDebugSession = vscode.debug.activeDebugSession; + if (activeDebugSession !== undefined) { + try { + activeDebugSession.customRequest("readMemory", { + memoryReference: global_message.address, + // offset: global_message.offset, + count: global_message.bufferSize, + }).then((response: MemoryViewerReadMemoryResponse) => { + console.log("Got response onDidChangeTextEditorSelection ", response); + response.direction = global_message.offset >= 0 ? "POSITIVE" : "NEGATIVE"; + webviewView.webview.postMessage(response); + + }); + } catch (e) { + console.error("THERE WAS AN ERROR",e); + } + } else { + // console.warn("Not is a valid debug session is running..."); + } + }); } } diff --git a/src/extension.ts b/src/extension.ts index 9852bff..c99e5fd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,16 +9,10 @@ export function activate(context: vscode.ExtensionContext) { // Use the console to output diagnostic information (console.log) and errors (console.error) // This line of code will only be executed once when your extension is activated - console.log('Congratulations, your extension "memoryViewer" is now active!'); // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json - let disposable = vscode.commands.registerCommand('memoryViewer.helloWorld', () => { - // The code you place here will be executed every time your command is executed - // Display a message box to the user - vscode.window.showInformationMessage('Hello World from Memory Viewer!'); - }); const provider = new MemoryViewerViewProvider(context.extensionUri); @@ -27,9 +21,8 @@ export function activate(context: vscode.ExtensionContext) { MemoryViewerViewProvider.viewType, provider ); - + context.subscriptions.push(memoryViewDisposable); - context.subscriptions.push(disposable); } // this method is called when your extension is deactivated diff --git a/webview/src/MemoryViewer.tsx b/webview/src/MemoryViewer.tsx index 160f5d7..9ca089f 100644 --- a/webview/src/MemoryViewer.tsx +++ b/webview/src/MemoryViewer.tsx @@ -15,6 +15,7 @@ export default function MemoryViewer() { const [activePositiveOffset, setActivePositiveOffset] = createSignal(0); const onMessageCallback = (message: any) => { console.log("Message", message); + setBytes([]); var binaryString = window.atob(message.data.data); var len = binaryString.length; var collectedBytes = new Array(len); @@ -59,7 +60,6 @@ export default function MemoryViewer() {
{ - setBytes([]); vscode.postMessage({ command: "readMemory", address: address(),