const assert = require('assert/strict'); const Module = require('module'); const disposables = () => ({ dispose() {} }); const posted = []; const copied = []; const opened = []; const shown = []; const warned = []; let requests = 0; let provider; let receive; let changed; class Range { constructor(startLine, startCharacter, endLine, endCharacter) { this.start = { line: startLine, character: startCharacter }; this.end = { line: endLine, character: endCharacter }; } } const vscode = { Uri: { parse(value) { return { value, fsPath: value.replace('file://', ''), toString: () => value }; }, joinPath(base, ...parts) { const value = [base.value || base.toString(), ...parts].join('/'); return { value, toString: () => value }; }, }, Range, ViewColumn: { Active: 1, Beside: 2 }, env: { clipboard: { async writeText(value) { copied.push(value); } } }, commands: { registerCommand() { return disposables(); } }, workspace: { asRelativePath(uri) { return uri.fsPath; }, async openTextDocument(uri) { opened.push(uri.value); return { uri, lineCount: 6, lineAt(line) { return { text: `line ${line + 1}` }; }, }; }, }, window: { registerWebviewViewProvider(_id, value) { provider = value; return disposables(); }, async showTextDocument(document, options) { shown.push({ document, options }); }, async showQuickPick(items) { return items[0]; }, showWarningMessage(text) { warned.push(text); }, }, }; const originalLoad = Module._load; Module._load = function load(request, parent, main) { if (request === 'vscode') return vscode; return originalLoad(request, parent, main); }; const { HierarchyView } = require('./hierarchyView'); Module._load = originalLoad; // The schema-2 wire: a file table and four-number ranges, no ids and no // per-instance `definitions` — `hierarchyModel.js` rebuilds all three. function place(file, line, start, end) { return { file, range: [line, 0, line, end + 2], selectionRange: [line, start, line, end] }; } const snapshot = { schemaVersion: 2, revision: 1, complete: true, files: ['file:///top.sv', 'file:///sub.sv'], modules: [ { moduleName: 'top', definition: place(0, 0, 7, 10), instances: [ { instanceName: 'u', moduleName: 'sub', site: place(0, 1, 6, 9) }, ] }, { moduleName: 'sub', definition: place(1, 0, 7, 10), instances: [] }, ], }; const state = new Map(); const context = { extensionUri: { value: 'file:///extension', toString: () => 'file:///extension' }, subscriptions: [], workspaceState: { get(key, fallback) { return state.has(key) ? state.get(key) : fallback; }, async update(key, value) { if (value === undefined) state.delete(key); else state.set(key, value); }, }, }; const client = { async sendRequest(method) { assert.equal(method, 'lucisv/moduleHierarchy'); requests += 1; return snapshot; }, onNotification(method, handler) { assert.equal(method, 'lucisv/moduleHierarchyChanged'); changed = handler; return disposables(); }, }; new HierarchyView(context, client); assert(provider, 'the webview provider is registered'); const webview = { cspSource: 'vscode-webview:', options: undefined, html: '', asWebviewUri(uri) { return uri.toString(); }, postMessage(message) { posted.push(message); }, onDidReceiveMessage(handler) { receive = handler; return disposables(); }, }; provider.resolveWebviewView({ webview, onDidDispose() { return disposables(); }, }); assert(webview.html.includes('Search module or instance')); assert(webview.html.includes('Content-Security-Policy')); async function run() { await receive({ type: 'ready' }); const rendered = () => posted.findLast((message) => message.type === 'render'); assert(rendered(), 'ready requests and renders a snapshot'); // Owner, 2026-08-29: everything starts collapsed — one row, the root. assert.equal(rendered().mode, 'tree'); assert.deepEqual(rendered().rows.map((row) => row.label), ['top']); const root = rendered().rows[0]; assert.equal(root.hasChildren, true); assert.equal(root.expanded, false); // Opening is the user's own act, and it is the only thing that builds the // level below. await receive({ type: 'toggle', id: root.id }); assert.deepEqual(rendered().rows.map((row) => row.label), ['top', 'u (sub)']); const instance = rendered().rows[1]; // A query swaps in a flat, capped result list; clearing it puts the tree // back with the same row open and no new snapshot request. const requestsBefore = requests; await receive({ type: 'search', query: 'u' }); assert.equal(rendered().mode, 'search'); assert(rendered().rows.some((row) => row.label === 'u (sub)')); assert.equal(rendered().truncated, 0); await receive({ type: 'search', query: '' }); assert.equal(rendered().mode, 'tree'); assert.deepEqual(rendered().rows.map((row) => row.label), ['top', 'u (sub)']); assert.equal(requests, requestsBefore, 'searching never asks the server again'); await receive({ type: 'context', action: 'copyPath', id: instance.id }); assert.deepEqual(copied, ['top.u']); await receive({ type: 'context', action: 'instance', id: instance.id }); assert.equal(opened.at(-1), 'file:///top.sv'); assert.equal(shown.at(-1).options.viewColumn, 1); await receive({ type: 'context', action: 'openRight', id: instance.id }); assert.equal(opened.at(-1), 'file:///sub.sv'); assert.equal(shown.at(-1).options.viewColumn, 2); assert.equal(shown.at(-1).options.preview, false); await receive({ type: 'context', action: 'bookmark', id: instance.id }); assert.equal(state.get('lucisv.hierarchy.bookmark'), 'top.u'); assert.equal(rendered().rows.find((row) => row.bookmarked).label, 'u (sub)'); // A search row navigates, but has no one path to copy or bookmark. await receive({ type: 'search', query: 'u' }); const hit = rendered().rows.find((row) => row.kind === 'instance'); await receive({ type: 'context', action: 'definition', id: hit.id }); assert.equal(opened.at(-1), 'file:///sub.sv'); const copiedBefore = copied.length; await receive({ type: 'context', action: 'copyPath', id: hit.id }); assert.equal(copied.length, copiedBefore, 'a flat hit has no full path to copy'); assert.equal(warned.at(-1), 'Clear the search to copy or bookmark an instance path.'); await receive({ type: 'search', query: '' }); // The source-line hover preview was removed at the owner's request // (2026-08-29): a `hover` message is now one the view does not answer, and // it must not resurrect the code that read a document behind the tree. const before = posted.length; await receive({ type: 'hover', id: instance.id }); assert.equal(posted.length, before, 'a hover posts nothing back'); assert(!posted.some((message) => message.type === 'preview'), 'no preview is ever posted'); assert(!webview.html.includes('id="preview"'), 'and the popover is gone from the markup'); assert.equal(typeof changed, 'function'); console.log('hierarchy view: OK — collapsed rows, lazy opening, search list, navigation, menu, bookmark, and no preview'); } run().catch((error) => { console.error(error); process.exitCode = 1; });