feat(nix): add Nix language support for nested scope detection#179
Open
parkers0405 wants to merge 2 commits into
Open
feat(nix): add Nix language support for nested scope detection#179parkers0405 wants to merge 2 commits into
parkers0405 wants to merge 2 commits into
Conversation
added 2 commits
January 28, 2026 21:20
- Add node_type field to Scope class to track treesitter node type
- Pass node_type from chunkHelper to render function
- Add node_type_styles config option for pattern-based style mapping
- Create dynamic highlight groups based on node type patterns
- Also includes virt_text_repeat_linebreak fix for wrapped lines
Example config:
node_type_styles = {
["^func"] = { fg = "#99aee5" }, -- functions: blue
["^if"] = { fg = "#c2a2e3" }, -- conditionals: purple
["^for"] = { fg = "#fbdf90" }, -- loops: yellow
}
This allows different colored chunk indicators for different scope types
(functions, loops, conditionals, etc.) when use_treesitter is enabled.
- Add nix.lua with Nix-specific treesitter node types - Enables chunk indicators for let expressions, attrsets, lambdas, etc. - Provides better visual feedback for Nix flake structure This allows hlchunk to show arrows/indicators for all nested scopes in Nix files (inputs, outputs, let blocks, attribute sets, etc.) instead of just top-level scopes.
There was a problem hiding this comment.
Pull request overview
This PR adds Nix Tree-sitter node-type coverage for chunk detection and introduces node-type-aware chunk highlighting so chunk indicators can be styled differently based on the matched Tree-sitter scope type.
Changes:
- Add
nix.luaTree-sitter node-type table and register it underts_node_type/init.lua. - Extend
HlChunk.Scope/ Tree-sitter chunk range detection to carry the matchednode_type. - Add
node_type_stylesconfiguration and apply it during chunk rendering via dynamically created highlight groups.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/hlchunk/utils/ts_node_type/nix.lua | Adds Nix-specific Tree-sitter node types to improve nested-scope detection. |
| lua/hlchunk/utils/ts_node_type/init.lua | Registers the new nix node-type map for filetype lookups. |
| lua/hlchunk/utils/scope.lua | Extends Scope to optionally store the Tree-sitter node_type. |
| lua/hlchunk/utils/chunkHelper.lua | Propagates node_type from Tree-sitter nodes into the returned Scope. |
| lua/hlchunk/mods/chunk/init.lua | Selects highlight group based on Scope.node_type and configured patterns. |
| lua/hlchunk/mods/chunk/chunk_conf.lua | Introduces node_type_styles config option for node-type-based styling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+143
to
+144
| -- Try to match node_type against configured patterns | ||
| for pattern, style in pairs(self.conf.node_type_styles) do |
Comment on lines
+146
to
+150
| -- Create a dynamic highlight group for this style | ||
| hl_group_counter = hl_group_counter + 1 | ||
| local hl_name = "HLChunkNodeType" .. hl_group_counter | ||
| api.nvim_set_hl(0, hl_name, style) | ||
| return hl_name |
Comment on lines
+43
to
+47
| -- Node type to style mapping (patterns matched against treesitter node type) | ||
| -- If a node type matches multiple patterns, first match wins | ||
| -- If no match, falls back to default style[1] | ||
| node_type_styles = { | ||
| -- Example config (users can override): |
Comment on lines
79
to
+83
| local node_type = cursor_node:type() | ||
| local node_start, _, node_end, _ = cursor_node:range() | ||
| if node_start ~= node_end and is_suit_type(node_type) then | ||
| return cursor_node:has_error() and chunkHelper.CHUNK_RANGE_RET.CHUNK_ERR or chunkHelper.CHUNK_RANGE_RET.OK, | ||
| Scope(pos.bufnr, node_start, node_end) | ||
| Scope(pos.bufnr, node_start, node_end, node_type) |
| rec_attrset_expression = true, -- rec { ... } | ||
| list_expression = true, -- [ ... ] | ||
| lambda_expression = true, -- arg: body | ||
| function_expression = true, -- { args }: body |
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
Adds Nix-specific treesitter node types for better chunk indicator support in Nix files.
Problem
Currently, hlchunk only shows chunk indicators for top-level scopes in Nix files. Nix has many nested scope types (let expressions, attribute sets, lambda functions, etc.) that weren't being detected.
Solution
Add
nix.luawith Nix-specific treesitter node types as a table (not array):let_expression-let ... in ...blocksattrset_expression-{ ... }attribute setsrec_attrset_expression-rec { ... }recursive setslist_expression-[ ... ]listslambda_expression-arg: bodyfunctionsfunction_expression-{ args }: bodyfunctionswith_expression-with ...; ...expressionsif_expression- conditionalsassert_expression- assertionsbinding-name = value;bindingsBenefits
Better visual feedback when editing Nix flakes and configurations. Users can now see chunk indicators for:
Especially useful for NixOS configurations and flake structures.
Testing
Tested on NixOS with Nix flakes and configuration files. Chunk indicators now appear for all nested scopes.