Lua for Nixvim plugins
Example: https://nix-community.github.io/nixvim/plugins/trouble/luaConfig.html
The keys are programs.nixvim.plugins.<words-including-dashes>.luaConfig.pre and .post.
; Lua
(binding
attrpath: (_) @_path
(#hmts-path? @_path "programs" "nixvim" "plugins" ".*" "luaConfig" "(post|pre)$")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "lua")
(#set! injection.combined)
)
Is the snippet above correct? (I just copied the Zsh section and changed the language and path.)
Usually programs.nixvim is not seen in the same file because it is imported under that key.
The snippet does look correct, although it would need to be tested to make sure.
As for split files, that's beyond the scope of what treesitter can manage, unfortunately. This should be handled at the LSP level, but there currently isn't any provision for injected languages in there.
I imagine we could manage with just the luaConfig node and those after, although it feels a bit dirty to me. Although I'm willing to debate this point as that's the approach taken by most of the "official" injections for nix in neovim-treesitter.
Anyway, I have ideas to streamline most of these "flat" queries into configuration options for the plugin. That way we could make them behave more or less strictly depending on what the user wishes. It would also make it trivial to add custom ones during setup.
Just luaConfig will do the job. I found no other config keys than would use lua within nixvim. Outside nixvim it might also be named luaConfig (i didn't check that). My guess is, that this key as the name says will always be lua code.
Custom configuration options sound good as well. And it would create a quick and documented way to test own injections before creating PRs.
How do you suggest I can test the above code today?