From fbb27a80c5e78f2ff2ec855c7d13009da6ea0e77 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 19 Apr 2026 19:02:24 +0200 Subject: [PATCH] languages/tera: add injection --- docs/manual/release-notes/rl-0.9.md | 5 ++++- modules/plugins/languages/tera.nix | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 1d5040c8..604a241b 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -278,7 +278,10 @@ - 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`. + `mkLualine`, `entryAnywhere`, `entryBefore`, `entryAfter` as `lua` in nix. + +- Added {option}`vim.languages.tera.treesitter.injection` to configure, what + language the content is. - 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/tera.nix b/modules/plugins/languages/tera.nix index 0a28014c..3135df9f 100644 --- a/modules/plugins/languages/tera.nix +++ b/modules/plugins/languages/tera.nix @@ -7,7 +7,7 @@ inherit (lib) genAttrs; inherit (lib.options) mkEnableOption literalExpression mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum listOf; + inherit (lib.types) enum listOf str; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.tera; @@ -26,6 +26,11 @@ in { defaultText = literalExpression "config.vim.languages.enableTreesitter"; }; package = mkGrammarOption pkgs "tera"; + injection = mkOption { + type = str; + default = "html"; + description = "Treesitter language to inject in Tera templates"; + }; }; lsp = { @@ -45,8 +50,24 @@ 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]; + queries = [ + { + type = "injections"; + filetypes = ["tera"]; + content = '' + ;; extends + + ((content) @injection.content + (#set! injection.language "${cfg.treesitter.injection}") + (#set! injection.combined) + ) + ''; + } + ]; + }; }) (mkIf cfg.lsp.enable {