From f7638cf027ca3b2af721bbc43fef15d3b547b8e5 Mon Sep 17 00:00:00 2001 From: mulatta <67085791+mulatta@users.noreply.github.com> Date: Sat, 26 Sep 2026 23:45:28 +0900 Subject: [PATCH] feat: add Nix language support Nix files are detected by CocoIndex but excluded from default project walks. Include them by default so semantic indexing and structural grep work without per-project pattern overrides. --- README.md | 1 + src/cocoindex_code/settings.py | 1 + tests/test_grep.py | 17 +++++++++++++++++ tests/test_settings.py | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 77bae52..77b8df2 100644 --- a/README.md +++ b/README.md @@ -857,6 +857,7 @@ embedding: | kotlin | | `.kt`, `.kts` | | lua | | `.lua` | | markdown | md | `.md`, `.mdx` | +| nix | | `.nix` | | pascal | pas, dpr, delphi | `.pas`, `.dpr` | | php | | `.php` | | python | | `.py` | diff --git a/src/cocoindex_code/settings.py b/src/cocoindex_code/settings.py index 0aa1faf..634fff5 100644 --- a/src/cocoindex_code/settings.py +++ b/src/cocoindex_code/settings.py @@ -54,6 +54,7 @@ "**/*.swift", # Swift "**/*.kt", # Kotlin "**/*.kts", # Kotlin script + "**/*.nix", # Nix "**/*.scala", # Scala "**/*.r", # R "**/*.html", # HTML diff --git a/tests/test_grep.py b/tests/test_grep.py index bb7e686..ec62199 100644 --- a/tests/test_grep.py +++ b/tests/test_grep.py @@ -137,6 +137,23 @@ def test_grep_language_filter(codebase: Path) -> None: assert {fm.path for fm in results} and all(fm.path.endswith(".rs") for fm in results) +def test_grep_nix_binding_with_default_patterns(tmp_path: Path) -> None: + nix_file = tmp_path / "default.nix" + nix_file.write_text("{ pkgs, ... }: { package-name = pkgs.callPackage ./package.nix {}; }\n") + req = g.GrepRequest( + pattern=r"package-name = \VALUE;", + root=tmp_path, + languages=frozenset({"nix"}), + ) + + results = run_grep(req) + + assert len(results) == 1 + assert results[0].path == nix_file.as_posix() + value = results[0].matches[0].captures["VALUE"][0].text + assert value == "pkgs.callPackage ./package.nix {}" + + def test_grep_single_file(codebase: Path) -> None: req = g.GrepRequest(pattern=r"def \NAME(\(ARGS*\)):", root=codebase / "a.py") results = run_grep(req) diff --git a/tests/test_settings.py b/tests/test_settings.py index abce8e2..bd58ead 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -82,6 +82,10 @@ def test_default_included_patterns_cover_elixir() -> None: assert "**/*.exs" in DEFAULT_INCLUDED_PATTERNS +def test_default_included_patterns_cover_nix() -> None: + assert "**/*.nix" in DEFAULT_INCLUDED_PATTERNS + + @pytest.mark.usefixtures("_patch_user_dir") def test_save_and_load_user_settings(tmp_path: Path) -> None: settings = UserSettings(