Multiple slot selector working

This commit is contained in:
brice.boisson
2025-10-22 21:48:22 +02:00
parent 46c5561ee5
commit d88c95e3fe
2 changed files with 47 additions and 12 deletions

View File

@@ -16,7 +16,8 @@
{ "command": "modelsim.toggleWaveMode", "title": "Toggle Wave Debug Mode" } { "command": "modelsim.toggleWaveMode", "title": "Toggle Wave Debug Mode" }
], ],
"keybindings": [ "keybindings": [
{ "command": "modelsim.addWaveUnderCursor", "key": "ctrl+w" }, { "command": "modelsim.addWaveUnderCursor", "key": "ctrl+w", "args": { "mode": "auto" } },
{ "command": "modelsim.addWaveUnderCursor", "key": "ctrl+e", "args": { "mode": "set" } },
{ "command": "modelsim.toggleWaveMode", "key": "ctrl+alt+m" }, { "command": "modelsim.toggleWaveMode", "key": "ctrl+alt+m" },
{ "command": "modelsim.zoomInWave", "key": "ctrl+alt+u" } { "command": "modelsim.zoomInWave", "key": "ctrl+alt+u" }
], ],

View File

@@ -7,7 +7,7 @@ const lastHoverByDoc = new Map<string, { pos: vscode.Position; at: number }>();
const HOVER_FRESH_MS = 2000; const HOVER_FRESH_MS = 2000;
// Hold MANY instance paths per module name, e.g. queue_slot -> ["/test/...[0]", "/test/...[1]", ...] // Hold MANY instance paths per module name, e.g. queue_slot -> ["/test/...[0]", "/test/...[1]", ...]
let moduleTree: Record<string, string[]> = {}; let moduleTree: Record<string, { module: string[], last: number }> = {};
let waveMode = false; let waveMode = false;
let statusItem: vscode.StatusBarItem; let statusItem: vscode.StatusBarItem;
@@ -170,7 +170,7 @@ export function activate(context: vscode.ExtensionContext) {
const cmd_2 = vscode.commands.registerCommand('modelsim.toggleWaveMode', async () => { const cmd_2 = vscode.commands.registerCommand('modelsim.toggleWaveMode', async () => {
toggleWaveMode(); toggleWaveMode();
}); });
const cmd = vscode.commands.registerCommand('modelsim.addWaveUnderCursor', async () => { const cmd = vscode.commands.registerCommand('modelsim.addWaveUnderCursor', async (args?: { mode?: string }) => {
if (waveMode) { if (waveMode) {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
@@ -219,7 +219,7 @@ export function activate(context: vscode.ExtensionContext) {
const modName = path.basename(editor.document.fileName, path.extname(editor.document.fileName)); const modName = path.basename(editor.document.fileName, path.extname(editor.document.fileName));
let instancePaths = let instancePaths =
moduleTree[modName] ?? moduleTree[modName.toLowerCase()]; moduleTree[modName].module ?? moduleTree[modName.toLowerCase()].module;
if (!instancePaths || instancePaths.length === 0) { if (!instancePaths || instancePaths.length === 0) {
console.log( console.log(
`No instance paths found for module "${modName}". ` + `No instance paths found for module "${modName}". ` +
@@ -228,15 +228,49 @@ export function activate(context: vscode.ExtensionContext) {
return; return;
} }
// Add the token for every instance of this module (dedupe paths just in case) // Add the token for every instance of this module (dedupe paths just in case)
instancePaths = Array.from(new Set(instancePaths)).map(p => p.replace(/\/+/g, '/')); instancePaths = Array.from(new Set(instancePaths)).map(p => p.replace(/\/+/g, '/'));
let ok = true; const mode = args?.mode ?? 'auto';
for (const p of instancePaths) {
const cmd = `quietly add wave -noupdate ${p}/${tokenText}`.replace(/\/+/g, '/'); let instance_num = moduleTree[modName].last ?? moduleTree[modName.toLowerCase()].last;
const res = await sendAndAwait(sharedDir, cmd, timeoutMs); if (instancePaths.length > 1 && mode === 'set') {
ok = ok && !!res; const input_num = await vscode.window.showInputBox({
title: 'Enter a number',
prompt: 'This number will be used by the action.',
placeHolder: moduleTree[modName].last !== undefined ? `Press Enter to reuse ${moduleTree[modName].last}` : 'e.g. 42',
value: moduleTree[modName].last !== undefined ? String(moduleTree[modName].last) : '',
ignoreFocusOut: true,
validateInput: (value) => {
if (value.trim() === '') return null; // allow Enter to reuse last
const n = Number(value);
if (!Number.isInteger(n)) return 'Please enter an integer.';
if (n < 0) return 'Please enter a non-negative integer.';
// optionally cap it
if (n > 10000) return 'Thats too large (max 10000).';
return null;
},
});
if (input_num === undefined) {
// User hit Esc — do nothing
return;
}
// Empty input means reuse last (if any)
instance_num = (input_num.trim() === '' || Number(input_num) >= moduleTree[modName].module.length) && moduleTree[modName].last !== undefined ? moduleTree[modName].last : Number(input_num);
moduleTree[modName].last = instance_num;
} }
let ok = true;
// for (const p of instancePaths) {
const cmd = `quietly add wave -noupdate \{${instancePaths[instance_num]}/${tokenText}\}`.replace(/\/+/g, '/');
console.log(cmd);
const res = await sendAndAwait(sharedDir, cmd, timeoutMs);
ok = ok && !!res;
ok = ok && !!(await sendAndAwait(sharedDir, 'update', timeoutMs)); ok = ok && !!(await sendAndAwait(sharedDir, 'update', timeoutMs));
if (ok) { if (ok) {
@@ -355,7 +389,7 @@ async function requestModuleTree(
sharedDir: string, sharedDir: string,
topScope: string, topScope: string,
timeoutMs: number timeoutMs: number
): Promise<Record<string, string[]>> { ): Promise<Record<string, { module: string[], last: number }>> {
const tree: Record<string, string[]> = {}; const tree: Record<string, string[]> = {};
const payload = `get_module_tree ${topScope}`; const payload = `get_module_tree ${topScope}`;
console.log("Requesting ModuleTree"); console.log("Requesting ModuleTree");
@@ -365,7 +399,7 @@ async function requestModuleTree(
const text = (await res) ?? ""; const text = (await res) ?? "";
console.log("Module Hierarchy: ", text) console.log("Module Hierarchy: ", text)
const rx = /\{([^}]+?)\s+\(([^)]+)\)\}/g; // {<path> (<type>)} const rx = /\{([^}]+?)\s+\(([^)]+)\)\}/g; // {<path> (<type>)}
const moduleTree: Record<string, string[]> = {}; const moduleTree: Record<string, { module: string[], last: number }> = {};
let m: RegExpExecArray | null; let m: RegExpExecArray | null;
while ((m = rx.exec(text))) { while ((m = rx.exec(text))) {
@@ -386,7 +420,7 @@ async function requestModuleTree(
// .map(seg => (seg.startsWith("u_") ? seg : "u_" + seg)) // .map(seg => (seg.startsWith("u_") ? seg : "u_" + seg))
// .join("/"); // .join("/");
(moduleTree[modType] ??= []).push(rawPath); ((moduleTree[modType] ??= { module: [], last: 0 }).module).push(rawPath);
} }
console.log(moduleTree); console.log(moduleTree);