Compare commits

...

10 commits

Author SHA1 Message Date
Snoweuph
4139469926
Merge pull request #1540 from snoweuph/feat/template-injecitons
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
Injections, Injections,... INJECTIONS!
2026-04-24 22:33:35 +02:00
Ching Pei Yang
16e8657179 treesitter: wording 2026-04-24 21:55:14 +02:00
Snoweuph
cee03d0c97 languages/nix: fix treesitter nvf query for vim.treesitter.queries 2026-04-24 21:55:14 +02:00
Snoweuph
10d7bb38ff languages/jinja: add injection 2026-04-24 21:55:14 +02:00
Snoweuph
e201640fc9 languages/yaml: add treesitter filetype mappings for yml 2026-04-24 21:55:14 +02:00
Snoweuph
2592c16878 languages/bash: add filetype mappings for ash, dash and zsh 2026-04-24 21:55:14 +02:00
Snoweuph
9ff0dcb60c treesitter: add filetype mappings 2026-04-24 21:55:14 +02:00
Snoweuph
27b4dc9fb0 treesitter: rename queries content to query 2026-04-24 21:55:14 +02:00
raf
95adf36ef5
Merge pull request #1541 from NotAShelf/dependabot/github_actions/cachix/install-nix-action-31.10.5
build(deps): bump cachix/install-nix-action from 31.10.4 to 31.10.5
2026-04-24 22:31:44 +03:00
dependabot[bot]
feca1f49c0 build(deps): bump cachix/install-nix-action from 31.10.4 to 31.10.5
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 31.10.4 to 31.10.5.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Changelog](https://github.com/cachix/install-nix-action/blob/master/RELEASE.md)
- [Commits](https://github.com/cachix/install-nix-action/compare/v31.10.4...v31.10.5)

---
updated-dependencies:
- dependency-name: cachix/install-nix-action
  dependency-version: 31.10.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-24 21:24:19 +02:00
16 changed files with 159 additions and 113 deletions

View file

@ -25,7 +25,7 @@ jobs:
name: Checkout
- name: Install Nix
uses: cachix/install-nix-action@v31.10.4
uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |

View file

@ -18,7 +18,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: cachix/install-nix-action@v31.10.4
- uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
@ -37,7 +37,7 @@ jobs:
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31.10.4
uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
@ -93,7 +93,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: cachix/install-nix-action@v31.10.4
- uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
@ -130,7 +130,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: cachix/install-nix-action@v31.10.4
- uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
@ -168,7 +168,7 @@ jobs:
cat "$HOME/changed_files"
- name: Install Nix
uses: cachix/install-nix-action@v31.10.4
uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |

View file

@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: cachix/install-nix-action@v31.10.4
- uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |

View file

@ -44,7 +44,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: cachix/install-nix-action@v31.10.4
- uses: cachix/install-nix-action@v31.10.5
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |

View file

@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v6
- name: "Install Nix"
uses: cachix/install-nix-action@v31.10.4
uses: cachix/install-nix-action@v31.10.5
- name: Set up Git
run: |

View file

@ -22,7 +22,7 @@ foo = mkLuaInline ''
vim.treesitter.queries = [{
type = "injections";
filetypes = ["nix"];
content = ''
query = ''
;; extends
((apply_expression

View file

@ -277,12 +277,24 @@
- 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.
- Added {option}`vim.languages.jinja.treesitter.injection` to configure, what
language the content is.
- Added {option}`vim.treesitter.filetypeMappings` to support mappings similar to
<https://github.com/nvim-treesitter/nvim-treesitter/blob/main/plugin/filetypes.lua>.
This is mostly use full for Markdown code block injections.
- Added some Tree-sitter filetype mappings for:
- `bash` = `ash`, `dash`, `zsh`
- `yaml` = `yaml`
- Added `vim.lsp.presets.<name>` 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.

View file

@ -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"];
});
};
})

View file

@ -287,7 +287,7 @@ in {
{
type = "injections";
filetypes = ["gotmpl"];
content = ''
query = ''
;; extends
((text) @injection.content

View file

@ -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 {

View file

@ -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))
'';
}
];

View file

@ -57,7 +57,7 @@ in {
{
type = "injections";
filetypes = ["tera"];
content = ''
query = ''
;; extends
((content) @injection.content

View file

@ -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 = [

View file

@ -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 {

View file

@ -24,78 +24,85 @@ 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
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

View file

@ -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 = {
@ -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.";
};
@ -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 = ''
For each parser, registers a list of alternative filetypes.
For more information see `:h vim.treesitter.language.register()`.
See treesitter builtin mappings here: <https://github.com/nvim-treesitter/nvim-treesitter/blob/main/plugin/filetypes.lua>
'';
};
};
}