Skip to content

fix(parse): zig symbol anchors never resolved — query targeted wrong grammar node names#33

Merged
laulauland merged 1 commit into
mainfrom
lau/fix-zig-symbol-anchors
Jun 10, 2026
Merged

fix(parse): zig symbol anchors never resolved — query targeted wrong grammar node names#33
laulauland merged 1 commit into
mainfrom
lau/fix-zig-symbol-anchors

Conversation

@laulauland

Copy link
Copy Markdown
Member

Problem

Symbol-level anchors on .zig files (drift link doc.md src/file.zig#Symbol) have never worked — every attempt fails with cannot compute fingerprint. The repo's own drift.lock contains zero #Symbol bindings, which is how this went unnoticed.

Root cause: src/queries/zig.scm targets maxxnino-style node names (TopLevelDecl, FnDecl, VarDecl, IDENTIFIER), but the grammar we build against is tree-sitter-grammars/tree-sitter-zig v1.1.1, which uses function_declaration, variable_declaration, identifier. The query never compiled — and fingerprintSymbolSyntax swallows ts.Query.create failures into null (symbols.zig), so the compile error surfaced as a generic fingerprint failure.

Fix

  • Rewrite src/queries/zig.scm for the actual grammar. variable_declaration has no name: field, so the pattern anchors the first named child (. (identifier) @name) to avoid matching initializer identifiers on the RHS.
  • Error message now names the failing target instead of the doc: error: cannot compute fingerprint for target: src/vcs.zig#noSuchSymbol (was: ...for anchor in '<doc-path>'). Contextual printing moved into link.zig next to the existing TargetNotFound/HeadingNotFound messages, covering both targeted and blanket relink paths.

Tests

  • symbol queries compile for every supported language — compiles all six .scm queries against their linked grammars; would have caught this bug and protects every future grammar bump.
  • zig fn/const symbol resolution, missing-symbol returns null, initializer identifiers don't false-positive.
  • Dogfood: drift.lock gains docs/DESIGN.md -> src/vcs.zig#getRepoIdentity and #GitCatFile — the first symbol-level zig bindings in the repo, both genuinely described in DESIGN.md. Stale-doc relinks for the code edits reviewed per the drift skill (prose unaffected).

Fixes DRIFT-ezbuwwor.

@laulauland laulauland merged commit 1c2cdaa into main Jun 10, 2026
5 checks passed
@laulauland laulauland deleted the lau/fix-zig-symbol-anchors branch June 10, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant