Every tracked file that can carry a comment (880 of them) now opens with "Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with "Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com", in the file's own comment syntax. No behaviour change: the diff outside the version bump and changelogs is comment lines only. - tools/stamp_author.py: writes the lines; idempotent, `--check` lists what is missing. Headers go under a shebang and under Markdown front matter. - Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the LICENSE files (already carry the copyright line). - tools/linux_check.sh: --help reads its header from line 3, now that the author line sits under the shebang. - tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
79 lines
3.4 KiB
JavaScript
79 lines
3.4 KiB
JavaScript
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
// The one thing "extract into module" needs that LSP has no request for:
|
|
// asking the user what to call the new module.
|
|
//
|
|
// The server offers the code action with a `Command` rather than an edit —
|
|
// `lucisv.extractModule [uri, range, defaultName]` — precisely so a client can
|
|
// step in between the click and the edit. This file is that step.
|
|
//
|
|
// **Through the language client's middleware, not through a second command.**
|
|
// `vscode-languageclient` registers every command the server advertises in
|
|
// `executeCommandProvider` with `vscode.commands.registerCommand`, so an
|
|
// extension that registered `lucisv.extractModule` itself would collide with
|
|
// it at activation. `middleware.executeCommand` is the seam the client provides
|
|
// for exactly this: it sees the command on its way out, may change the
|
|
// arguments, and hands them to `next`. One command id, one server contract,
|
|
// and every other client — Vim, a CLI — runs the same command with the default
|
|
// name and gets the same edit.
|
|
//
|
|
// Nothing here knows about `vscode`: the dependencies come in as an object, so
|
|
// `extract_test.js` drives the whole flow headlessly.
|
|
// See docs/features/extract-inline-module/README.md.
|
|
|
|
/** The command the server's code action carries. */
|
|
const EXTRACT_MODULE = 'lucisv.extractModule';
|
|
|
|
/**
|
|
* A plain SystemVerilog identifier, which is the only thing the engine will
|
|
* name a module — and a file — with. Checked here as well as in the engine so
|
|
* the user is told while the box is open rather than by an error afterwards.
|
|
*/
|
|
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
|
|
/**
|
|
* What the input box says about what has been typed so far, or `undefined`
|
|
* when it is a name lucisv would accept.
|
|
*
|
|
* The message is the one the engine would refuse with, in the present tense:
|
|
* an editor's validation is read while typing, not after.
|
|
*/
|
|
function validateModuleName(value) {
|
|
const name = (value || '').trim();
|
|
if (name === '') return 'The new module needs a name.';
|
|
if (!IDENTIFIER.test(name)) {
|
|
return 'A module name is a plain SystemVerilog identifier: a letter or `_`, then letters, digits, `_` or `$`.';
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
/**
|
|
* The language client's `executeCommand` middleware.
|
|
*
|
|
* - `deps.showInputBox` — `vscode.window.showInputBox`, which resolves to the
|
|
* typed string or to `undefined` when the user pressed Escape.
|
|
* - `command`, `args`, `next` — what the client hands every middleware.
|
|
*
|
|
* Every command but this one goes straight through. This one asks for a name,
|
|
* and a cancelled box resolves to `undefined` without ever reaching the
|
|
* server: an extraction nobody named is one nobody asked for.
|
|
*/
|
|
async function executeCommand(deps, command, args, next) {
|
|
if (command !== EXTRACT_MODULE) return next(command, args);
|
|
const [uri, range, suggested] = args || [];
|
|
const name = await deps.showInputBox({
|
|
title: 'Extract into module',
|
|
prompt: 'Name for the new module',
|
|
value: typeof suggested === 'string' ? suggested : '',
|
|
validateInput: validateModuleName,
|
|
});
|
|
if (name === undefined) return undefined;
|
|
const trimmed = name.trim();
|
|
if (validateModuleName(trimmed) !== undefined) return undefined;
|
|
return next(command, [uri, range, trimmed]);
|
|
}
|
|
|
|
module.exports = { EXTRACT_MODULE, executeCommand, validateModuleName };
|
|
|
|
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|