Skip to content

Commit

Permalink
Implement watch list management.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Oct 8, 2024
1 parent f23addd commit a9492ad
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 19 deletions.
7 changes: 5 additions & 2 deletions example/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"rtlDebugger.command": ["${workspaceFolder}/design_sim"]
}
"rtlDebugger.command": [
"${workspaceFolder}/design_sim"
],
"rtlDebugger.watchList": []
}
42 changes: 39 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"$comment": "UPSTREAM: Unfortunately there is no way to control the formatting of the extension name within the setting title. See microsoft/vscode#103592",
"properties": {
"rtlDebugger.command": {
"type": [
"array"
],
"type": "array",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -60,6 +58,20 @@
],
"default": "Verilog",
"markdownDescription": "Specifies the display format for variables."
},
"rtlDebugger.watchList": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string"},
"row": {"type": "integer"},
"bit": {"type": "integer"}
},
"required": ["id"],
"additionalProperties": false
},
"description": "Specifies the list of variables being watched separately."
}
}
},
Expand Down Expand Up @@ -104,6 +116,18 @@
"category": "RTL Debugger",
"title": "Step Backward",
"icon": "$(debug-step-back)"
},
{
"command": "rtlDebugger.watchVariable",
"category": "RTL Debugger",
"title": "Watch Variable",
"icon": "$(eye-watch)"
},
{
"command": "rtlDebugger.unWatchVariable",
"category": "RTL Debugger",
"title": "Stop Watching",
"icon": "$(remove)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -197,6 +221,18 @@
"when": "view == rtlDebugger.sidebar && rtlDebugger.sessionStatus == running",
"group": "navigation@5"
}
],
"view/item/context": [
{
"command": "rtlDebugger.watchVariable",
"when": "view == rtlDebugger.sidebar && viewItem == canWatch",
"group": "inline"
},
{
"command": "rtlDebugger.unWatchVariable",
"when": "view == rtlDebugger.sidebar && viewItem == inWatchList",
"group": "inline"
}
]
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/debug/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ export class Session {
);
}

async getVariable(variableIdentifier: string): Promise<Variable | null> {
const identifierParts = variableIdentifier.split(' ');
const scopeIdentifier = identifierParts.slice(0, identifierParts.length - 1).join(' ');
const items = await this.listItemsInScope(scopeIdentifier);
if (variableIdentifier in items) {
return Variable.fromCXXRTL(variableIdentifier, items[variableIdentifier]);
} else {
return null;
}
}

// ======================================== Querying the database

private referenceEpochs: Map<string, number> = new Map();
Expand Down
44 changes: 44 additions & 0 deletions src/debug/watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as vscode from 'vscode';

export interface IWatchItem {
id: string;
row?: number;
bit?: number;
}

export interface IWatchList {
get(): IWatchItem[];
set(items: IWatchItem[]): void;
append(item: IWatchItem): void;
remove(index: number): void;

onDidChange(callback: (items: IWatchItem[]) => any): vscode.Disposable;
}

export const watchList: IWatchList = {
get(): IWatchItem[] {
return vscode.workspace.getConfiguration('rtlDebugger').get('watchList') || [];
},

set(items: IWatchItem[]): void {
vscode.workspace.getConfiguration('rtlDebugger').update('watchList', items);
},

append(item: IWatchItem): void {
this.set(this.get().concat(item));
},

remove(index: number): void {
const items = this.get();
items.splice(index, 1);
this.set(items);
},

onDidChange(callback: (items: IWatchItem[]) => any): vscode.Disposable {
return vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration('rtlDebugger.watchList')) {
callback(watchList.get());
}
});
},
};
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as vscode from 'vscode';
import { watchList } from './debug/watch';
import { CXXRTLDebugger } from './debugger';
import * as sidebar from './ui/sidebar';
import { inputTime } from './ui/input';

export function activate(context: vscode.ExtensionContext) {
const rtlDebugger = new CXXRTLDebugger();
const sidebarTreeDataProvider = new sidebar.TreeDataProvider(rtlDebugger);

context.subscriptions.push(vscode.window.createTreeView('rtlDebugger.sidebar', {
const sidebarTreeDataProvider = new sidebar.TreeDataProvider(rtlDebugger);
const sidebarTreeView = vscode.window.createTreeView('rtlDebugger.sidebar', {
treeDataProvider: sidebarTreeDataProvider
}));
});
context.subscriptions.push(sidebarTreeView);

vscode.commands.executeCommand('setContext', 'rtlDebugger.sessionStatus', rtlDebugger.sessionStatus);
context.subscriptions.push(rtlDebugger.onDidChangeSessionStatus((state) =>
Expand Down Expand Up @@ -48,6 +50,11 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stepForward', () =>
rtlDebugger.session!.stepForward()));

context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.watchVariable', (treeItem) =>
watchList.append(treeItem.getWatchItem())));
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.unWatchVariable', (treeItem) =>
watchList.remove(treeItem.metadata.index)));

// For an unknown reason, the `vscode.open` command (which does the exact same thing) ignores the options.
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.openDocument',
(uri: vscode.Uri, options: vscode.TextDocumentShowOptions) => {
Expand Down
Loading

0 comments on commit a9492ad

Please sign in to comment.