Merge pull request #1536 from snoweuph/feat/injections
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Treewide Checks / Validate flake (push) Has been cancelled
Treewide Checks / Check formatting (push) Has been cancelled
Treewide Checks / Check source tree for typos (push) Has been cancelled
Treewide Checks / Validate documentation builds (push) Has been cancelled
Treewide Checks / Validate documentation builds-1 (push) Has been cancelled
Treewide Checks / Validate documentation builds-2 (push) Has been cancelled
Treewide Checks / Validate documentation builds-3 (push) Has been cancelled
Treewide Checks / Validate hyperlinks in documentation sources (push) Has been cancelled
Treewide Checks / Validate Editorconfig conformance (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled

Feat/injections 💉
This commit is contained in:
Snoweuph 2026-04-20 16:33:07 +02:00 committed by GitHub
commit 4de19e1209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 120 additions and 70 deletions

View file

@ -104,6 +104,10 @@
- Renamed `languages.ts` to `languages.typescript`. - Renamed `languages.ts` to `languages.typescript`.
- Added {option}`vim.languages.go.treesitter.gotmpl.injection` and Renamed
`languages.go.treesitter.gotmplPackage` to
{option}`vim.languages.go.treesitter.gotmpl.package`
## Changelog {#sec-release-0-9-changelog} ## Changelog {#sec-release-0-9-changelog}
[SecBear](https://github.com/SecBear): [SecBear](https://github.com/SecBear):
@ -274,7 +278,10 @@
- Added {option}`vim.treesitter.queries` to support adding custom queries. - Added {option}`vim.treesitter.queries` to support adding custom queries.
- Added injections for `vim.treesitter.queries.*.content` as `query` and - Added injections for `vim.treesitter.queries.*.content` as `query` and
`mkLualine ""` 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.<name>` to contain LSP configurations. This allows for - Added `vim.lsp.presets.<name>` to contain LSP configurations. This allows for
more flexibility in nvf and reuse of LSPs across languages. Dropped more flexibility in nvf and reuse of LSPs across languages. Dropped

View file

@ -362,6 +362,7 @@ in {
# 2026-04-19 # 2026-04-19
[ [
(mkRenamedOptionModule ["vim" "utility" "vim-wakatime" "cli-path"] ["vim" "utility" "vim-wakatime" "setupOpts" "cli_path"]) (mkRenamedOptionModule ["vim" "utility" "vim-wakatime" "cli-path"] ["vim" "utility" "vim-wakatime" "setupOpts" "cli_path"])
(mkRenamedOptionModule ["vim" "languages" "go" "treesitter" "gotmplPackage"] ["vim" "languages" "go" "treesitter" "gotmpl" "package"])
] ]
]; ];
} }

View file

@ -54,13 +54,10 @@ in {
# event = ["InsertEnter" "CmdlineEnter"]; # event = ["InsertEnter" "CmdlineEnter"];
after = after =
# lua optionalString (config.vim.lazy.enable && cmpCfg.enable)
'' (concatStringsSep "\n" (map
${optionalString (config.vim.lazy.enable && cmpCfg.enable) (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
(concatStringsSep "\n" (map cmpCfg.sourcePlugins));
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
cmpCfg.sourcePlugins))}
'';
}; };
}; };
@ -111,18 +108,16 @@ in {
next = [ next = [
"select_next" "select_next"
"snippet_forward" "snippet_forward"
(mkLuaInline (mkLuaInline ''
# lua function(cmp)
'' local line, col = unpack(vim.api.nvim_win_get_cursor(0))
function(cmp) has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
if has_words_before then if has_words_before then
return cmp.show() return cmp.show()
end
end end
'') end
'')
"fallback" "fallback"
]; ];
previous = [ previous = [

View file

@ -143,7 +143,14 @@ in {
gomodPackage = mkGrammarOption pkgs "gomod"; gomodPackage = mkGrammarOption pkgs "gomod";
gosumPackage = mkGrammarOption pkgs "gosum"; gosumPackage = mkGrammarOption pkgs "gosum";
goworkPackage = mkGrammarOption pkgs "gowork"; goworkPackage = mkGrammarOption pkgs "gowork";
gotmplPackage = mkGrammarOption pkgs "gotmpl"; gotmpl = {
package = mkGrammarOption pkgs "gotmpl";
injection = mkOption {
type = str;
default = "html";
description = "Treesitter language to inject in Go templates";
};
};
}; };
lsp = { lsp = {
@ -274,7 +281,21 @@ in {
cfg.treesitter.gomodPackage cfg.treesitter.gomodPackage
cfg.treesitter.gosumPackage cfg.treesitter.gosumPackage
cfg.treesitter.goworkPackage cfg.treesitter.goworkPackage
cfg.treesitter.gotmplPackage cfg.treesitter.gotmpl.package
];
queries = [
{
type = "injections";
filetypes = ["gotmpl"];
content = ''
;; extends
((text) @injection.content
(#set! injection.language "${cfg.treesitter.gotmpl.injection}")
(#set! injection.combined)
)
'';
}
]; ];
}; };
}) })

View file

@ -138,44 +138,43 @@ in {
filetypes = ["nix"]; filetypes = ["nix"];
content = '' content = ''
;; extends ;; 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
(binding_set attrpath: (attrpath
(binding (identifier) @_a
attrpath: (attrpath (identifier) @_b
(identifier) @_queries) (identifier)? @_c)
(#eq? @_queries "queries") (#eq? @_a "vim")
(#any-of? @_b "treesitter")
(#any-of? @_c "queries")
expression: (list_expression expression: (attrset_expression
(attrset_expression (binding_set
(binding_set (binding
(binding attrpath: (attrpath
attrpath: (attrpath (identifier) @_queries)
(identifier) @_field) (#eq? @_queries "queries")
(#eq? @_field "content")
expression: [ expression: (list_expression
(string_expression (attrset_expression
(string_fragment) @injection.content) (binding_set
(indented_string_expression (binding
(string_fragment) @injection.content) attrpath: (attrpath
] (identifier) @_field)
(#eq? @_field "content")
(#set! injection.language "query") expression: [
(#set! injection.combined))))))))) (string_expression
) (string_fragment) @injection.content)
(indented_string_expression
(string_fragment) @injection.content)
]
(#set! injection.language "query")
(#set! injection.combined))))))))))
''; '';
} }
# mkLuaInline = lua # mkLuaInline, entryAnywhere, entryBefore, entryAfter = lua
{ {
type = "injections"; type = "injections";
filetypes = ["nix"]; filetypes = ["nix"];
@ -185,13 +184,22 @@ in {
((apply_expression ((apply_expression
function: (variable_expression function: (variable_expression
name: (identifier) @_func name: (identifier) @_func
(#eq? @_func "mkLuaInline")) (#any-of? @_func "mkLuaInline" "entryAnywhere"))
argument: (indented_string_expression argument: (indented_string_expression
(string_fragment) @injection.content) (string_fragment) @injection.content))
(#set! injection.language "lua")
(#set! injection.combined))
(#set! injection.language "lua") ((apply_expression
(#set! injection.combined))) function: (apply_expression
function: (variable_expression
name: (identifier) @_func
(#any-of? @_func "entryBefore" "entryAfter"))
argument: (_))
argument: (indented_string_expression
(string_fragment) @injection.content))
(#set! injection.language "lua")
(#set! injection.combined))
''; '';
} }
]; ];

View file

@ -7,7 +7,7 @@
inherit (lib) genAttrs; inherit (lib) genAttrs;
inherit (lib.options) mkEnableOption literalExpression mkOption; inherit (lib.options) mkEnableOption literalExpression mkOption;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) enum listOf; inherit (lib.types) enum listOf str;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.tera; cfg = config.vim.languages.tera;
@ -26,6 +26,11 @@ in {
defaultText = literalExpression "config.vim.languages.enableTreesitter"; defaultText = literalExpression "config.vim.languages.enableTreesitter";
}; };
package = mkGrammarOption pkgs "tera"; package = mkGrammarOption pkgs "tera";
injection = mkOption {
type = str;
default = "html";
description = "Treesitter language to inject in Tera templates";
};
}; };
lsp = { lsp = {
@ -45,8 +50,24 @@ in {
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable { (mkIf cfg.treesitter.enable {
vim.treesitter.enable = true; vim.treesitter = {
vim.treesitter.grammars = [cfg.treesitter.package]; 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 { (mkIf cfg.lsp.enable {

View file

@ -11,12 +11,9 @@
uiKindSetupOpts = uiKindSetupOpts =
if config.vim.theme.enable && config.vim.theme.name == "catppuccin" if config.vim.theme.enable && config.vim.theme.name == "catppuccin"
then { then {
ui.kind = ui.kind = mkLuaInline ''
mkLuaInline require("catppuccin.groups.integrations.lsp_saga").custom_kind()
# lua '';
''
require("catppuccin.groups.integrations.lsp_saga").custom_kind()
'';
} }
else {}; else {};
in { in {