feat: add Nix language support#330
Open
uxtechie wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add full Nix (
.nix) language support to CodeGraph, including symbol extraction, import resolution, and export detection.Closes #332
Related: #324 — While that issue requests distributing CodeGraph as a Nix flake (packaging), this PR adds support for parsing and indexing Nix source files as a new language in the extraction engine.
What this PR does
Symbol Extraction (
src/extraction/languages/nix.ts)y = arg: arg + 1;→ signature(arg)z = { name }: ...→ signature{ name }f = a: b: c: body→ signaturea : b : c@alias:{ x, y } @ argsandargs @ { x, y }patternsinheritandinherit (expr)as variable nodesapply_expression, distinguishingimportexpressions (emitted asimportsreferences) from regular callsisExportedNode()helper that traverses AST ancestors to determine if a symbol is in the top-level attribute set (exported) vs. inside aletbinding or nested attribute set (private)Import Resolution
src/resolution/import-resolver.ts: Registers.nixand/default.nixextensions inEXTENSION_RESOLUTIONsrc/resolution/index.ts: Adds file-level import resolution forimports-kind references — resolves directly tofile:node IDs instead of symbol name matching. Also adjusts the pre-filter to avoid discarding valid import referencesSupporting Files
src/extraction/grammars.ts: Registers tree-sitter-nix grammar (vendored WASM, loaded fromsrc/extraction/wasm/like Pascal, Scala, Lua, and Luau)src/extraction/languages/index.ts: Registers Nix extractorsrc/types.ts: Addsnixto theLanguagetypesrc/extraction/wasm/tree-sitter-nix.wasm: Bundled WASM parser (no new runtime or dev dependencies added — the grammar was compiled offline and vendored directly)Test Coverage
Extraction tests (
__tests__/extraction.test.ts)inheritandinherit (expr)handlingbuiltins.import)Resolution tests (
__tests__/resolution.test.ts)import ../core/ports.nix)Verification
npm run buildcompiles cleanly with no type errorsDependencies
No new runtime or dev dependencies. The tree-sitter-nix WASM grammar is vendored in
src/extraction/wasm/(same approach used for Pascal, Scala, Lua, and Luau). Thepackage.jsondependenciesanddevDependenciessections are unchanged frommain.Files Changed
src/extraction/languages/nix.tssrc/extraction/wasm/tree-sitter-nix.wasmsrc/extraction/grammars.tssrc/extraction/languages/index.tssrc/types.tsnixto Language typesrc/resolution/import-resolver.ts.nixextensionssrc/resolution/index.ts__tests__/extraction.test.ts__tests__/resolution.test.ts