Skip to content

feat(nix): add Nix list support#43

Merged
bennypowers merged 1 commit intomainfrom
feat/nix-support
Apr 18, 2026
Merged

feat(nix): add Nix list support#43
bennypowers merged 1 commit intomainfrom
feat/nix-support

Conversation

@bennypowers
Copy link
Copy Markdown
Owner

@bennypowers bennypowers commented Apr 18, 2026

Summary

  • Custom split/join handler for Nix list_expression nodes, which use space-delimited items instead of commas
  • Handles function calls with nested braces ((callPackage ./foo.nix {})), string items, path identifiers
  • Single-element lists are correctly skipped (no-op)

Test plan

  • Basic list split/rejoin (3 items)
  • Single element list (no-op, round-trips unchanged)
  • List with path-like identifiers (pkg-config)
  • List with parenthesized function calls and nested braces
  • List with string items
  • Indented list (inside attrset)
  • Full suite passes (250 tests)

Assisted-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Summary by CodeRabbit

New Features

  • Added Nix language support with automatic list expression formatting capabilities. Seamlessly converts between inline and multiline formats for Nix lists. Handles various list contents including single-element items, attribute paths, function calls, quoted string values, and deeply nested structures with consistent indentation. Includes comprehensive test coverage for all real-world formatting scenarios.

Custom split/join handler for space-delimited list_expression nodes,
since Nix lists use spaces instead of commas between items.

Handles function calls with nested braces, string items, and properly
skips single-element lists.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

📝 Walkthrough

Walkthrough

This pull request adds support for the Nix language to the splitjoin plugin. It introduces Nix-specific list split/join functions, configuration bindings, Tree-sitter query rules, and comprehensive test coverage. The implementation enables transforming between single-line and multi-line Nix list expressions.

Changes

Cohort / File(s) Summary
Core Implementation
lua/splitjoin/languages/nix/functions.lua, lua/splitjoin/languages/nix/defaults.lua
Added Nix language module with two functions: split_list converts inline lists to multi-line format using configurable indentation, and join_list collapses multi-line lists to single-line format. Configuration module registers these functions for list_expression nodes.
Tree-sitter Integration
queries/nix/splitjoin.scm
Added query rule capturing list_expression nodes as split/join targets.
Test Infrastructure
test/bootstrap.lua, test/helpers.lua
Extended Tree-sitter language installation list to include nix and added nix file extension mapping for test buffer setup.
Test Suite
test/nix_spec.lua
Added comprehensive test suite with 6 test cases covering inline-to-multi-line conversion, single-element lists, nested structures, quoted strings, attribute names, and function call expressions within lists.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A fluffy hop through Nix we go,
Lists splitting high and joining low,
With brackets neat and indent bright,
We made the code flow just right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(nix): add Nix list support' clearly and specifically describes the main change: adding support for splitting and joining Nix lists.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/nix-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/splitjoin/languages/nix/functions.lua`:
- Around line 5-25: The Nix.split_list function currently always prefixes items
with options.default_indent and writes the closing ']' at column 0, and it
doesn't handle default_indent when provided as a function; update Nix.split_list
to detect and preserve the node's base indentation (e.g., read indentation of
the node's starting line or previous sibling), normalize options.default_indent
if it's a function (call it to get a string), then build lines that insert the
base indentation before each item indent and emit the closing ']' aligned with
the base indentation; finally call Node.replace and Node.goto_node as before so
the replaced text keeps the surrounding indentation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99fab636-c0d1-441c-a2d0-c92884bd6628

📥 Commits

Reviewing files that changed from the base of the PR and between f8459af and 8eb89cd.

📒 Files selected for processing (6)
  • lua/splitjoin/languages/nix/defaults.lua
  • lua/splitjoin/languages/nix/functions.lua
  • queries/nix/splitjoin.scm
  • test/bootstrap.lua
  • test/helpers.lua
  • test/nix_spec.lua

Comment thread lua/splitjoin/languages/nix/functions.lua
@bennypowers bennypowers merged commit 75ad732 into main Apr 18, 2026
3 checks passed
@bennypowers bennypowers deleted the feat/nix-support branch April 18, 2026 17:40
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