mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-27 03:47:37 +00:00
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
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!
This commit is contained in:
commit
4139469926
11 changed files with 150 additions and 104 deletions
|
|
@ -22,7 +22,7 @@ foo = mkLuaInline ''
|
||||||
vim.treesitter.queries = [{
|
vim.treesitter.queries = [{
|
||||||
type = "injections";
|
type = "injections";
|
||||||
filetypes = ["nix"];
|
filetypes = ["nix"];
|
||||||
content = ''
|
query = ''
|
||||||
;; extends
|
;; extends
|
||||||
|
|
||||||
((apply_expression
|
((apply_expression
|
||||||
|
|
|
||||||
|
|
@ -277,12 +277,24 @@
|
||||||
|
|
||||||
- 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 `query = '' ... ''` as `query` and `mkLualine '' ... ''`,
|
||||||
`mkLualine`, `entryAnywhere`, `entryBefore`, `entryAfter` as `lua` in nix.
|
`entryAnywhere '' ... ''`, `entryBefore [] '' ... ''`,
|
||||||
|
`entryAfter [] '' ... ''` as `lua` in nix.
|
||||||
|
|
||||||
- Added {option}`vim.languages.tera.treesitter.injection` to configure, what
|
- Added {option}`vim.languages.tera.treesitter.injection` to configure, what
|
||||||
language the content is.
|
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
|
- 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
|
||||||
`deprecatedSingleOrListOf` in favor of `listOf` for the affected LSP options.
|
`deprecatedSingleOrListOf` in favor of `listOf` for the affected LSP options.
|
||||||
|
|
|
||||||
|
|
@ -95,15 +95,19 @@ 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];
|
||||||
|
# not perfect mappings, but better than none
|
||||||
|
filetypeMappings.bash = ["ash" "dash" "zsh"];
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp = {
|
vim.lsp = {
|
||||||
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
||||||
servers = genAttrs cfg.lsp.servers (_: {
|
servers = genAttrs cfg.lsp.servers (_: {
|
||||||
filetypes = ["bash" "sh" "zsh"];
|
filetypes = ["bash" "sh" "ash" "dash" "zsh"];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ in {
|
||||||
{
|
{
|
||||||
type = "injections";
|
type = "injections";
|
||||||
filetypes = ["gotmpl"];
|
filetypes = ["gotmpl"];
|
||||||
content = ''
|
query = ''
|
||||||
;; extends
|
;; extends
|
||||||
|
|
||||||
((text) @injection.content
|
((text) @injection.content
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
inherit (lib) genAttrs;
|
inherit (lib) genAttrs;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
||||||
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.jinja;
|
cfg = config.vim.languages.jinja;
|
||||||
|
|
@ -27,6 +27,11 @@ in {
|
||||||
};
|
};
|
||||||
package = mkGrammarOption pkgs "jinja";
|
package = mkGrammarOption pkgs "jinja";
|
||||||
inlinePackage = mkGrammarOption pkgs "jinja_inline";
|
inlinePackage = mkGrammarOption pkgs "jinja_inline";
|
||||||
|
injection = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "html";
|
||||||
|
description = "Treesitter language to inject in Jinja templates";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
lsp = {
|
lsp = {
|
||||||
|
|
@ -46,11 +51,27 @@ 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 = [
|
enable = true;
|
||||||
|
grammars = [
|
||||||
cfg.treesitter.package
|
cfg.treesitter.package
|
||||||
cfg.treesitter.inlinePackage
|
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 {
|
(mkIf cfg.lsp.enable {
|
||||||
|
|
|
||||||
|
|
@ -132,53 +132,41 @@ in {
|
||||||
enable = true;
|
enable = true;
|
||||||
grammars = [cfg.treesitter.package];
|
grammars = [cfg.treesitter.package];
|
||||||
queries = [
|
queries = [
|
||||||
# vim.treesitter.queries.*.content
|
# query = ''; -> query
|
||||||
{
|
{
|
||||||
type = "injections";
|
type = "injections";
|
||||||
filetypes = ["nix"];
|
filetypes = ["nix"];
|
||||||
content = ''
|
query = ''
|
||||||
;; extends
|
;; extends
|
||||||
|
|
||||||
((binding
|
((binding
|
||||||
attrpath: (attrpath
|
attrpath: (attrpath
|
||||||
(identifier) @_a
|
(identifier) @_path)
|
||||||
(identifier) @_b
|
(#eq? @_path "query")
|
||||||
(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: [
|
expression: [
|
||||||
(string_expression
|
(string_expression
|
||||||
(string_fragment) @injection.content)
|
((string_fragment) @injection.content
|
||||||
|
(#set! injection.language "query")))
|
||||||
(indented_string_expression
|
(indented_string_expression
|
||||||
(string_fragment) @injection.content)
|
((string_fragment) @injection.content
|
||||||
]
|
(#set! injection.language "query")))
|
||||||
|
(apply_expression
|
||||||
(#set! injection.language "query")
|
argument: [
|
||||||
(#set! injection.combined))))))))))
|
(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";
|
type = "injections";
|
||||||
filetypes = ["nix"];
|
filetypes = ["nix"];
|
||||||
content = ''
|
query = ''
|
||||||
;; extends
|
;; extends
|
||||||
|
|
||||||
((apply_expression
|
((apply_expression
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ in {
|
||||||
{
|
{
|
||||||
type = "injections";
|
type = "injections";
|
||||||
filetypes = ["tera"];
|
filetypes = ["tera"];
|
||||||
content = ''
|
query = ''
|
||||||
;; extends
|
;; extends
|
||||||
|
|
||||||
((content) @injection.content
|
((content) @injection.content
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,6 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{vim.globals.markdown_fenced_languages = ["ts=typescript"];}
|
|
||||||
|
|
||||||
(mkIf cfg.treesitter.enable {
|
(mkIf cfg.treesitter.enable {
|
||||||
vim.treesitter.enable = true;
|
vim.treesitter.enable = true;
|
||||||
vim.treesitter.grammars = [
|
vim.treesitter.grammars = [
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,11 @@ 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];
|
||||||
|
filetypeMappings.yaml = ["yml"];
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ in {
|
||||||
|
|
||||||
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
||||||
|
|
||||||
pluginRC.treesitter-autocommands = entryAfter ["basic"] ''
|
pluginRC = {
|
||||||
|
treesitter-autocommands = entryAfter ["basic"] ''
|
||||||
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })
|
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })
|
||||||
|
|
||||||
${lib.optionalString cfg.highlight.enable ''
|
${lib.optionalString cfg.highlight.enable ''
|
||||||
|
|
@ -67,35 +68,41 @@ in {
|
||||||
})
|
})
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
|
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 != []) [
|
additionalRuntimePaths = mkIf (cfg.queries != []) [
|
||||||
(let
|
(let
|
||||||
grouped =
|
grouped =
|
||||||
foldl'
|
foldl'
|
||||||
(
|
(
|
||||||
acc: query:
|
acc: entry:
|
||||||
foldl'
|
foldl'
|
||||||
(
|
(
|
||||||
inner: filetype: let
|
inner: filetype: let
|
||||||
path = "queries/${filetype}/${query.type}.scm";
|
path = "queries/${filetype}/${entry.type}.scm";
|
||||||
prev = inner.${path} or "";
|
prev = inner.${path} or "";
|
||||||
in
|
in
|
||||||
inner
|
inner
|
||||||
// {
|
// {
|
||||||
${path} = prev + query.content;
|
${path} = prev + entry.query;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
acc
|
acc
|
||||||
query.filetypes
|
entry.filetypes
|
||||||
)
|
)
|
||||||
{}
|
{}
|
||||||
cfg.queries;
|
cfg.queries;
|
||||||
|
|
||||||
files =
|
files =
|
||||||
mapAttrsToList
|
mapAttrsToList
|
||||||
(path: content: {
|
(path: query: {
|
||||||
name = path;
|
name = path;
|
||||||
path = pkgs.writeText path content;
|
path = pkgs.writeText path query;
|
||||||
})
|
})
|
||||||
grouped;
|
grouped;
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
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 {
|
queriesType = submodule {
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
default = [];
|
default = [];
|
||||||
description = "The filetypes for which the query should be registered.";
|
description = "The filetypes for which the query should be registered.";
|
||||||
};
|
};
|
||||||
content = mkOption {
|
query = mkOption {
|
||||||
type = lines;
|
type = lines;
|
||||||
description = "The queries scm script.";
|
description = "The queries scm script.";
|
||||||
};
|
};
|
||||||
|
|
@ -111,5 +111,18 @@ in {
|
||||||
default = [];
|
default = [];
|
||||||
description = "A list of Neovim treesitter queries to be registered.";
|
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>
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue