editor-packaging: a minimal VS Code extension (41-line plain JS on
vscode-languageclient =9.0.1, one setting vfmt.serverPath, languages
verilog/systemverilog) with a zero-dependency smoke.js that validates
the extension's exact spawn contract against the real binary, plus
Neovim/Vim/coc setup docs (including the load-bearing
vim.filetype.add — Vim maps *.v by content heuristic and *.vh not at
all). Everything headless-validatable was validated: the .vsix
builds, smoke passes with negative controls, npm ci reproduces.
vfmt-core-lift: config.rs and walk.rs moved to a new std-only
vfmt_core crate as byte-identical 100% renames (CLI suite untouched,
corpus TSV md5 equal from HEAD and lifted builds). The LSP server
now discovers vfmt.toml per document with precedence config > client
tabSize > built-in default (an editor default is not a deliberate
override), warns once per document change on a broken config while
formatting with defaults, and scans the workspace with the lifted
gitignore-aware walk. QA drove every claim live over stdio.
With these, every TODO §6 item is delivered: spans, tolerant
parsing, define table, single-file semantics, workspace index, the
server, and both editors. Lead trued up the caveats this round made
stale across five documents.
Dev: 2 Opus agents; QA: 2 Sonnet agents; reviews in
docs/features/{editor-packaging,vfmt-core-lift}/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
94 lines
3.9 KiB
JavaScript
94 lines
3.9 KiB
JavaScript
// Pre-publish smoke test: spawn the server exactly the way extension.js does
|
|
// and drive a whole LSP session at it over stdio. Plain node, no dependencies,
|
|
// hand-rolled framing — a check that reused a client library could not catch a
|
|
// framing or startup bug. Mirrors crates/vfmt_server/tests/e2e.rs.
|
|
//
|
|
// node smoke.js [path-to-vfmt-server] # default: `vfmt-server` on PATH
|
|
//
|
|
// Exits 0 on success, 1 on any failure.
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
const serverPath = process.argv[2] || 'vfmt-server';
|
|
|
|
/** Frame one JSON payload the way LSP wants it. */
|
|
function frame(payload) {
|
|
const body = Buffer.from(JSON.stringify(payload), 'utf8');
|
|
return Buffer.concat([Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii'), body]);
|
|
}
|
|
|
|
/** Split a stdout dump into its JSON payloads. */
|
|
function unframe(buffer) {
|
|
const messages = [];
|
|
let at = 0;
|
|
while (at < buffer.length) {
|
|
const headerEnd = buffer.indexOf('\r\n\r\n', at, 'ascii');
|
|
if (headerEnd < 0) break;
|
|
const headers = buffer.toString('ascii', at, headerEnd);
|
|
const match = /Content-Length: *(\d+)/i.exec(headers);
|
|
if (!match) break;
|
|
const start = headerEnd + 4;
|
|
const end = start + Number(match[1]);
|
|
if (end > buffer.length) break;
|
|
messages.push(JSON.parse(buffer.toString('utf8', start, end)));
|
|
at = end;
|
|
}
|
|
return messages;
|
|
}
|
|
|
|
function fail(message) {
|
|
console.error(`smoke: FAIL — ${message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// The same spawn contract extension.js uses: no arguments, inherited env, the
|
|
// workspace directory as cwd, LSP on stdin/stdout.
|
|
const server = spawn(serverPath, [], { cwd: process.cwd(), env: process.env, stdio: 'pipe' });
|
|
server.on('error', (error) => fail(`could not spawn "${serverPath}": ${error.message}`));
|
|
|
|
const chunks = [];
|
|
server.stdout.on('data', (chunk) => chunks.push(chunk));
|
|
server.stderr.on('data', (chunk) => process.stderr.write(chunk));
|
|
|
|
// Every message is written before anything is read: the server handles them in
|
|
// order and exits on `exit`, so stdout closes on its own and this can never
|
|
// deadlock waiting for a message that is not coming.
|
|
const uri = `file://${process.cwd()}/smoke_scratch.sv`;
|
|
server.stdin.end(
|
|
Buffer.concat([
|
|
frame({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { processId: process.pid, rootUri: null, capabilities: {} } }),
|
|
frame({ jsonrpc: '2.0', method: 'initialized', params: {} }),
|
|
frame({
|
|
jsonrpc: '2.0',
|
|
method: 'textDocument/didOpen',
|
|
params: { textDocument: { uri, languageId: 'systemverilog', version: 1, text: 'module top;\n wire a;\nendmodule\n' } },
|
|
}),
|
|
frame({ jsonrpc: '2.0', id: 2, method: 'shutdown', params: null }),
|
|
frame({ jsonrpc: '2.0', method: 'exit', params: null }),
|
|
]),
|
|
);
|
|
|
|
server.on('close', (code) => {
|
|
if (code !== 0) fail(`server exited with code ${code}`);
|
|
|
|
const messages = unframe(Buffer.concat(chunks));
|
|
const initialize = messages.find((m) => m.id === 1);
|
|
if (!initialize) fail('no initialize response');
|
|
if (initialize.error) fail(`initialize failed: ${JSON.stringify(initialize.error)}`);
|
|
|
|
const capabilities = initialize.result && initialize.result.capabilities;
|
|
if (!capabilities) fail('initialize response carries no capabilities');
|
|
for (const capability of ['documentFormattingProvider', 'definitionProvider', 'hoverProvider', 'semanticTokensProvider']) {
|
|
if (!capabilities[capability]) fail(`capability missing: ${capability}`);
|
|
}
|
|
|
|
const diagnostics = messages.find((m) => m.method === 'textDocument/publishDiagnostics');
|
|
if (!diagnostics) fail('the server pushed no diagnostics for the opened document');
|
|
|
|
const shutdown = messages.find((m) => m.id === 2);
|
|
if (!shutdown) fail('no shutdown response');
|
|
if (shutdown.error) fail(`shutdown failed: ${JSON.stringify(shutdown.error)}`);
|
|
|
|
console.log(`smoke: OK — "${serverPath}" completed initialize/didOpen/shutdown/exit (${messages.length} messages)`);
|
|
});
|