// Checks for the VS Code semantic-highlighting manifest contract: // `configurationDefaults` enables semantic highlighting for both language ids, // `semanticTokenScopes` covers both language ids identically, every mapped key // exists in `crates/lucisv_server/src/tokens.rs`'s legend, and the five module // instantiation roles map to distinct primary TextMate scopes. // // node semanticTokens_test.js // // See docs/features/instantiation-highlighting/README.md. const fs = require('fs'); const path = require('path'); let checks = 0; function fail(what) { console.error(`semanticTokens_test: FAIL — ${what}`); process.exit(1); } function ok(condition, what) { checks += 1; if (!condition) fail(what); } const manifestPath = path.join(__dirname, 'package.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); const vscodeignore = fs.readFileSync(path.join(__dirname, '.vscodeignore'), 'utf8'); const tokensRust = fs.readFileSync( path.join(__dirname, '..', '..', 'crates', 'lucisv_server', 'src', 'tokens.rs'), 'utf8', ); // 1. `.vscodeignore` keeps this test out of packaged `.vsix` archives. ok( vscodeignore.split(/\r?\n/).includes('semanticTokens_test.js'), 'semanticTokens_test.js is listed in .vscodeignore', ); // 2. Both language ids turn semantic highlighting on by default so themes with // `semanticHighlighting: false` or unset still render server tokens. const defaults = manifest.contributes.configurationDefaults; ok(defaults && typeof defaults === 'object', 'configurationDefaults exists'); for (const lang of ['[verilog]', '[systemverilog]']) { ok( defaults[lang] && defaults[lang]['editor.semanticHighlighting.enabled'] === true, `${lang} sets editor.semanticHighlighting.enabled = true`, ); } // 3. Extract the advertised legend names from `tokens.rs::token_types()`. const legendMap = { NAMESPACE: 'namespace', CLASS: 'class', TYPE: 'type', ENUM_MEMBER: 'enumMember', PARAMETER: 'parameter', VARIABLE: 'variable', PROPERTY: 'property', FUNCTION: 'function', MACRO: 'macro', KEYWORD: 'keyword', COMMENT: 'comment', STRING: 'string', NUMBER: 'number', DECORATOR: 'decorator', }; const fnBody = tokensRust.split('pub fn token_types()')[1].split('}')[0]; const advertised = [...fnBody.matchAll(/SemanticTokenType::([A-Z_]+)/g)].map(([, id]) => { ok(legendMap[id], `known SemanticTokenType::${id}`); return legendMap[id]; }); ok(advertised.length === 14, `legend stays at 14 types, got ${advertised.length}`); // 4. `semanticTokenScopes` is registered identically for `verilog` and `systemverilog`, // and every key is in the server's advertised legend. const entries = manifest.contributes.semanticTokenScopes; ok(Array.isArray(entries) && entries.length === 2, 'two semanticTokenScopes entries'); ok(entries[0].language === 'verilog', 'first entry is verilog'); ok(entries[1].language === 'systemverilog', 'second entry is systemverilog'); ok( JSON.stringify(entries[0].scopes) === JSON.stringify(entries[1].scopes), 'verilog and systemverilog share identical semanticTokenScopes', ); const scopes = entries[0].scopes; for (const [tokenType, chain] of Object.entries(scopes)) { ok(advertised.includes(tokenType), `${tokenType} is in tokens::token_types()`); ok(Array.isArray(chain) && chain.length > 0, `${tokenType} has a non-empty scope fallback chain`); for (const scope of chain) { ok(typeof scope === 'string' && scope.length > 0, `${tokenType} scope is non-empty string`); } } // 5. All five module-instantiation roles map to pairwise-distinct primary scopes. const instantiationRoles = ['class', 'parameter', 'function', 'property', 'variable']; const primaryScopes = instantiationRoles.map((role) => { ok(Array.isArray(scopes[role]) && scopes[role].length > 0, `${role} is mapped`); return scopes[role][0]; }); ok( new Set(primaryScopes).size === instantiationRoles.length, `instantiation roles have distinct primary scopes: ${primaryScopes.join(', ')}`, ); console.log(`semanticTokens_test: ${checks} checks passed`);