From 27b4dc9fb03297d03ae96ba2b242489d74f01d88 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:48:23 +0200 Subject: [PATCH 1/7] treesitter: rename queries content to query --- docs/manual/configuring/queries.md | 2 +- modules/plugins/languages/go.nix | 2 +- modules/plugins/languages/tera.nix | 2 +- modules/plugins/treesitter/config.nix | 12 ++++++------ modules/plugins/treesitter/treesitter.nix | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/manual/configuring/queries.md b/docs/manual/configuring/queries.md index e6e544f7..866fbd8e 100644 --- a/docs/manual/configuring/queries.md +++ b/docs/manual/configuring/queries.md @@ -22,7 +22,7 @@ foo = mkLuaInline '' vim.treesitter.queries = [{ type = "injections"; filetypes = ["nix"]; - content = '' + query = '' ;; extends ((apply_expression diff --git a/modules/plugins/languages/go.nix b/modules/plugins/languages/go.nix index afe9d1b2..1e644bac 100644 --- a/modules/plugins/languages/go.nix +++ b/modules/plugins/languages/go.nix @@ -287,7 +287,7 @@ in { { type = "injections"; filetypes = ["gotmpl"]; - content = '' + query = '' ;; extends ((text) @injection.content diff --git a/modules/plugins/languages/tera.nix b/modules/plugins/languages/tera.nix index 3135df9f..e9388f5f 100644 --- a/modules/plugins/languages/tera.nix +++ b/modules/plugins/languages/tera.nix @@ -57,7 +57,7 @@ in { { type = "injections"; filetypes = ["tera"]; - content = '' + query = '' ;; extends ((content) @injection.content diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index b2b4cc99..862a5ed8 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -73,29 +73,29 @@ in { grouped = foldl' ( - acc: query: + acc: entry: foldl' ( inner: filetype: let - path = "queries/${filetype}/${query.type}.scm"; + path = "queries/${filetype}/${entry.type}.scm"; prev = inner.${path} or ""; in inner // { - ${path} = prev + query.content; + ${path} = prev + entry.query; } ) acc - query.filetypes + entry.filetypes ) {} cfg.queries; files = mapAttrsToList - (path: content: { + (path: query: { name = path; - path = pkgs.writeText path content; + path = pkgs.writeText path query; }) grouped; in diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index d10a3eaf..9d543621 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -17,7 +17,7 @@ default = []; description = "The filetypes for which the query should be registered."; }; - content = mkOption { + query = mkOption { type = lines; description = "The queries scm script."; }; From 9ff0dcb60cf0878c44bcafc3eec7844ce84106f6 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:51:01 +0200 Subject: [PATCH 2/7] treesitter: add filetype mappings --- docs/manual/release-notes/rl-0.9.md | 4 ++ modules/plugins/treesitter/config.nix | 87 ++++++++++++----------- modules/plugins/treesitter/treesitter.nix | 15 +++- 3 files changed, 65 insertions(+), 41 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 04ba7acd..9c399f7a 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -283,6 +283,10 @@ - Added {option}`vim.languages.tera.treesitter.injection` to configure, what language the content is. +- Added {option}`vim.treesitter.filetypeMappings` to support mappings similar to + . + This is mostly use full for Markdown code block injections. + - Added `vim.lsp.presets.` to contain LSP configurations. This allows for more flexibility in nvf and reuse of LSPs across languages. Dropped `deprecatedSingleOrListOf` in favor of `listOf` for the affected LSP options. diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 862a5ed8..985a363d 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -24,49 +24,56 @@ in { treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; - pluginRC.treesitter-autocommands = entryAfter ["basic"] '' - vim.api.nvim_create_augroup("nvf_treesitter", { clear = true }) + pluginRC = { + treesitter-autocommands = entryAfter ["basic"] '' + vim.api.nvim_create_augroup("nvf_treesitter", { clear = true }) - ${lib.optionalString cfg.highlight.enable '' - -- Enable treesitter highlighting for all filetypes - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = "*", - callback = function() - pcall(vim.treesitter.start) - end, - }) - ''} - - ${lib.optionalString cfg.indent.enable '' - -- Enable treesitter highlighting for all filetypes - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = ${toLuaObject cfg.indent.pattern}, - callback = function(args) - ${optionalString (builtins.length cfg.indent.excludes > 0) '' - local ft = vim.bo[args.buf].filetype - if vim.tbl_contains(${toLuaObject cfg.indent.excludes}, ft) then - return - end + ${lib.optionalString cfg.highlight.enable '' + -- Enable treesitter highlighting for all filetypes + vim.api.nvim_create_autocmd("FileType", { + group = "nvf_treesitter", + pattern = "*", + callback = function() + pcall(vim.treesitter.start) + end, + }) ''} - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - end, - }) - ''} - ${lib.optionalString cfg.fold '' - -- Enable treesitter folding for all filetypes - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = "*", - callback = function() - vim.wo[0][0].foldmethod = "expr" - vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()" - end, - }) - ''} - ''; + ${lib.optionalString cfg.indent.enable '' + -- Enable treesitter highlighting for all filetypes + vim.api.nvim_create_autocmd("FileType", { + group = "nvf_treesitter", + pattern = ${toLuaObject cfg.indent.pattern}, + callback = function(args) + ${optionalString (builtins.length cfg.indent.excludes > 0) '' + local ft = vim.bo[args.buf].filetype + if vim.tbl_contains(${toLuaObject cfg.indent.excludes}, ft) then + return + end + ''} + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end, + }) + ''} + + ${lib.optionalString cfg.fold '' + -- Enable treesitter folding for all filetypes + vim.api.nvim_create_autocmd("FileType", { + group = "nvf_treesitter", + pattern = "*", + callback = function() + vim.wo[0][0].foldmethod = "expr" + vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()" + end, + }) + ''} + ''; + treesitter-filetype-mappings = entryAfter ["basic"] '' + for lang, ft in pairs(${toLuaObject cfg.filetypeMappings}) do + vim.treesitter.language.register(lang, ft) + end + ''; + }; additionalRuntimePaths = mkIf (cfg.queries != []) [ (let diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index 9d543621..11dda33e 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -4,7 +4,7 @@ ... }: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) listOf nullOr package bool str lines enum submodule oneOf; + inherit (lib.types) listOf nullOr package bool str lines enum submodule oneOf attrsOf; queriesType = submodule { options = { @@ -111,5 +111,18 @@ in { default = []; description = "A list of Neovim treesitter queries to be registered."; }; + + filetypeMappings = mkOption { + type = attrsOf (listOf str); + default = {}; + example = { + "sh" = ["ash" "dash"]; + }; + description = '' + Register alternative parser names for a filetype. + For more information see `:h vim.treesitter.language.register()`. + See treesitter builtin mappings here: + ''; + }; }; } From 2592c16878417b0227e9f6c7b0fb412ce68dc7d0 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:52:51 +0200 Subject: [PATCH 3/7] languages/bash: add filetype mappings for ash, dash and zsh --- docs/manual/release-notes/rl-0.9.md | 2 ++ modules/plugins/languages/bash.nix | 10 +++++++--- modules/plugins/languages/typescript.nix | 2 -- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 9c399f7a..f51f5cfa 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -287,6 +287,8 @@ . This is mostly use full for Markdown code block injections. +- Added some Tree-sitter filetype mappings for `ash`, `dash` and `zsh`. + - Added `vim.lsp.presets.` to contain LSP configurations. This allows for more flexibility in nvf and reuse of LSPs across languages. Dropped `deprecatedSingleOrListOf` in favor of `listOf` for the affected LSP options. diff --git a/modules/plugins/languages/bash.nix b/modules/plugins/languages/bash.nix index be1eaca9..6ae23d73 100644 --- a/modules/plugins/languages/bash.nix +++ b/modules/plugins/languages/bash.nix @@ -95,15 +95,19 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; + vim.treesitter = { + enable = true; + grammars = [cfg.treesitter.package]; + # not perfect mappings, but better than none + filetypeMappings.bash = ["ash" "dash" "zsh"]; + }; }) (mkIf cfg.lsp.enable { vim.lsp = { presets = genAttrs cfg.lsp.servers (_: {enable = true;}); servers = genAttrs cfg.lsp.servers (_: { - filetypes = ["bash" "sh" "zsh"]; + filetypes = ["bash" "sh" "ash" "dash" "zsh"]; }); }; }) diff --git a/modules/plugins/languages/typescript.nix b/modules/plugins/languages/typescript.nix index 90749358..297cc1c0 100644 --- a/modules/plugins/languages/typescript.nix +++ b/modules/plugins/languages/typescript.nix @@ -158,8 +158,6 @@ in { }; config = mkIf cfg.enable (mkMerge [ - {vim.globals.markdown_fenced_languages = ["ts=typescript"];} - (mkIf cfg.treesitter.enable { vim.treesitter.enable = true; vim.treesitter.grammars = [ From e201640fc94ecc99a9cba43e4501df0026233a9f Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:55:34 +0200 Subject: [PATCH 4/7] languages/yaml: add treesitter filetype mappings for yml --- docs/manual/release-notes/rl-0.9.md | 4 +++- modules/plugins/languages/yaml.nix | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index f51f5cfa..da8a8b24 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -287,7 +287,9 @@ . This is mostly use full for Markdown code block injections. -- Added some Tree-sitter filetype mappings for `ash`, `dash` and `zsh`. +- Added some Tree-sitter filetype mappings for: + - `bash` = `ash`, `dash`, `zsh` + - `yaml` = `yaml` - Added `vim.lsp.presets.` to contain LSP configurations. This allows for more flexibility in nvf and reuse of LSPs across languages. Dropped diff --git a/modules/plugins/languages/yaml.nix b/modules/plugins/languages/yaml.nix index bba0eba3..db84d346 100644 --- a/modules/plugins/languages/yaml.nix +++ b/modules/plugins/languages/yaml.nix @@ -46,8 +46,11 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; + vim.treesitter = { + enable = true; + grammars = [cfg.treesitter.package]; + filetypeMappings.yaml = ["yml"]; + }; }) (mkIf cfg.lsp.enable { From 10d7bb38ffea12a05da96bf524312ab4694006e1 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:58:32 +0200 Subject: [PATCH 5/7] languages/jinja: add injection --- docs/manual/release-notes/rl-0.9.md | 3 +++ modules/plugins/languages/jinja.nix | 33 +++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index da8a8b24..803bcc4a 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -283,6 +283,9 @@ - Added {option}`vim.languages.tera.treesitter.injection` to configure, what language the content is. +- Added {option}`vim.languages.jinja.treesitter.injection` to configure, what + language the content is. + - Added {option}`vim.treesitter.filetypeMappings` to support mappings similar to . This is mostly use full for Markdown code block injections. diff --git a/modules/plugins/languages/jinja.nix b/modules/plugins/languages/jinja.nix index ff32bc24..e8de65f9 100644 --- a/modules/plugins/languages/jinja.nix +++ b/modules/plugins/languages/jinja.nix @@ -7,7 +7,7 @@ inherit (lib) genAttrs; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) literalExpression mkEnableOption mkOption; - inherit (lib.types) enum listOf; + inherit (lib.types) enum listOf str; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.jinja; @@ -27,6 +27,11 @@ in { }; package = mkGrammarOption pkgs "jinja"; inlinePackage = mkGrammarOption pkgs "jinja_inline"; + injection = mkOption { + type = str; + default = "html"; + description = "Treesitter language to inject in Jinja templates"; + }; }; lsp = { @@ -46,11 +51,27 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [ - cfg.treesitter.package - cfg.treesitter.inlinePackage - ]; + vim.treesitter = { + enable = true; + grammars = [ + cfg.treesitter.package + cfg.treesitter.inlinePackage + ]; + queries = [ + { + type = "injections"; + filetypes = ["jinja"]; + query = '' + ;; extends + + ((content) @injection.content + (#set! injection.language "${cfg.treesitter.injection}") + (#set! injection.combined) + ) + ''; + } + ]; + }; }) (mkIf cfg.lsp.enable { From cee03d0c97ff63483a2791224944f9ab754a6ec6 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Thu, 23 Apr 2026 22:59:05 +0200 Subject: [PATCH 6/7] languages/nix: fix treesitter nvf query for vim.treesitter.queries --- docs/manual/release-notes/rl-0.9.md | 5 ++- modules/plugins/languages/nix.nix | 66 ++++++++++++----------------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 803bcc4a..995d74f0 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -277,8 +277,9 @@ - Added {option}`vim.treesitter.queries` to support adding custom queries. -- Added injections for `vim.treesitter.queries.*.content` as `query` and - `mkLualine`, `entryAnywhere`, `entryBefore`, `entryAfter` as `lua` in nix. +- Added injections for `query = '' ... ''` as `query` and `mkLualine '' ... ''`, + `entryAnywhere '' ... ''`, `entryBefore [] '' ... ''`, + `entryAfter [] '' ... ''` as `lua` in nix. - Added {option}`vim.languages.tera.treesitter.injection` to configure, what language the content is. diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 09507a55..3a992bb2 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -132,53 +132,41 @@ in { enable = true; grammars = [cfg.treesitter.package]; queries = [ - # vim.treesitter.queries.*.content + # query = ''; -> query { type = "injections"; filetypes = ["nix"]; - content = '' + query = '' ;; extends ((binding attrpath: (attrpath - (identifier) @_a - (identifier) @_b - (identifier)? @_c) - (#eq? @_a "vim") - (#any-of? @_b "treesitter") - (#any-of? @_c "queries") - - expression: (attrset_expression - (binding_set - (binding - attrpath: (attrpath - (identifier) @_queries) - (#eq? @_queries "queries") - - expression: (list_expression - (attrset_expression - (binding_set - (binding - attrpath: (attrpath - (identifier) @_field) - (#eq? @_field "content") - - expression: [ - (string_expression - (string_fragment) @injection.content) - (indented_string_expression - (string_fragment) @injection.content) - ] - - (#set! injection.language "query") - (#set! injection.combined)))))))))) + (identifier) @_path) + (#eq? @_path "query") + expression: [ + (string_expression + ((string_fragment) @injection.content + (#set! injection.language "query"))) + (indented_string_expression + ((string_fragment) @injection.content + (#set! injection.language "query"))) + (apply_expression + argument: [ + (string_expression + ((string_fragment) @injection.content + (#set! injection.language "query"))) + (indented_string_expression + ((string_fragment) @injection.content + (#set! injection.language "query"))) + ]) + ])) ''; } - # mkLuaInline, entryAnywhere, entryBefore, entryAfter = lua + # mkLuaInline, entryAnywhere, entryBefore, entryAfter -> lua { type = "injections"; filetypes = ["nix"]; - content = '' + query = '' ;; extends ((apply_expression @@ -187,8 +175,8 @@ in { (#any-of? @_func "mkLuaInline" "entryAnywhere")) argument: (indented_string_expression (string_fragment) @injection.content)) - (#set! injection.language "lua") - (#set! injection.combined)) + (#set! injection.language "lua") + (#set! injection.combined)) ((apply_expression function: (apply_expression @@ -198,8 +186,8 @@ in { argument: (_)) argument: (indented_string_expression (string_fragment) @injection.content)) - (#set! injection.language "lua") - (#set! injection.combined)) + (#set! injection.language "lua") + (#set! injection.combined)) ''; } ]; From 16e86571792eb86d457305974b9e36ce5848d719 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Fri, 24 Apr 2026 21:55:02 +0200 Subject: [PATCH 7/7] treesitter: wording --- modules/plugins/treesitter/treesitter.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index 11dda33e..a58fda45 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -119,7 +119,7 @@ in { "sh" = ["ash" "dash"]; }; description = '' - Register alternative parser names for a filetype. + For each parser, registers a list of alternative filetypes. For more information see `:h vim.treesitter.language.register()`. See treesitter builtin mappings here: '';