fix: address Zig PR review feedback (#3180)

Check for the vendored package without loading its native binding so a
broken installed Zig grammar fails the parsing test instead of skipping.
Match the optional child descriptor in the Zig metadata declaration and
include Zig in the two optional/vendored grammar comments.

Validation: 159 targeted tests, TypeScript, metadata type fixture, and
formatting passed. Injected native-load failure now fails instead of
skipping; explicit Zig opt-out still skips.
This commit is contained in:
Gergo Magyar 2026-09-05 08:48:49 +00:00
parent fc0337146c
commit 1d9bc9391e
4 changed files with 7 additions and 13 deletions

View file

@ -109,7 +109,7 @@ interface NodeTypeEntry {
/** Resolve the on-disk directory of an installed package, or null if absent. */
function resolvePackageDir(pkg: string): string | null {
// Vendored grammars (c/dart/proto/swift/kotlin) are NOT in node_modules — they
// Vendored grammars (c/dart/proto/swift/kotlin/zig) are NOT in node_modules — they
// load from vendor/ by absolute path (vendored-grammars.ts / #2111), so resolve
// their node-types.json from there rather than via _require.resolve.
if (VENDORED_GRAMMAR_PACKAGES.has(pkg)) {

View file

@ -10,7 +10,7 @@ import {
import { SupportedLanguages, getLanguageFromFilename } from 'gitnexus-shared';
import { getProvider } from '../../src/core/ingestion/languages/index.js';
import Parser from 'tree-sitter';
import { requireVendoredGrammar } from '../../src/core/tree-sitter/vendored-grammars.js';
import { vendoredGrammarDir } from '../../src/core/tree-sitter/vendored-grammars.js';
const fixturesDir = path.resolve(__dirname, '..', 'fixtures', 'sample-code');
@ -690,15 +690,9 @@ describe('Tree-sitter multi-language parsing', () => {
// mismatch, bad export) must fail this test, not silently skip it. A
// deliberate `GITNEXUS_SKIP_OPTIONAL_GRAMMARS` opt-out in the environment
// is the one non-failure reason an installed grammar reports unavailable.
const zigPackageInstalled = (() => {
if (isGrammarRuntimeSkipped(SupportedLanguages.Zig)) return false;
try {
requireVendoredGrammar('tree-sitter-zig');
return true;
} catch {
return false;
}
})();
const zigPackageInstalled =
!isGrammarRuntimeSkipped(SupportedLanguages.Zig) &&
fs.existsSync(path.join(vendoredGrammarDir('tree-sitter-zig'), 'package.json'));
it.skipIf(!zigPackageInstalled)('parses functions, structs, enums, and imports', async () => {
expect(isLanguageAvailable(SupportedLanguages.Zig)).toBe(true);
await loadLanguage(SupportedLanguages.Zig);

View file

@ -6,7 +6,7 @@ import { SupportedLanguages } from '../../src/config/supported-languages.js';
*
* `GITNEXUS_SKIP_OPTIONAL_GRAMMARS` used to be an install-time-only env (the
* postinstall build scripts read it). `parser-loader` now also honors it at
* analyze time: when set, genuinely-optional grammars (swift/dart/kotlin)
* analyze time: when set, genuinely-optional grammars (swift/dart/kotlin/zig)
* report unavailable so the ingestion pipeline skips their files, mirroring a
* genuinely-absent binding. Grammars that are required `dependencies` routed
* through the optional machinery for ABI safety (C `severity: 'error'`) are

View file

@ -15,7 +15,7 @@ type NodeInfo =
})
| (BaseNode & {
fields: { [name: string]: ChildNode };
children: ChildNode[];
children?: ChildNode;
});
type Language = {