mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-26 19:37:36 +00:00
treesitter: add filetype mappings
This commit is contained in:
parent
27b4dc9fb0
commit
9ff0dcb60c
3 changed files with 64 additions and 40 deletions
|
|
@ -283,6 +283,10 @@
|
||||||
- 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.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 `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.
|
||||||
|
|
|
||||||
|
|
@ -24,49 +24,56 @@ in {
|
||||||
|
|
||||||
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
||||||
|
|
||||||
pluginRC.treesitter-autocommands = entryAfter ["basic"] ''
|
pluginRC = {
|
||||||
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })
|
treesitter-autocommands = entryAfter ["basic"] ''
|
||||||
|
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })
|
||||||
|
|
||||||
${lib.optionalString cfg.highlight.enable ''
|
${lib.optionalString cfg.highlight.enable ''
|
||||||
-- Enable treesitter highlighting for all filetypes
|
-- Enable treesitter highlighting for all filetypes
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = "nvf_treesitter",
|
group = "nvf_treesitter",
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
pcall(vim.treesitter.start)
|
pcall(vim.treesitter.start)
|
||||||
end,
|
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 ''
|
${lib.optionalString cfg.indent.enable ''
|
||||||
-- Enable treesitter folding for all filetypes
|
-- Enable treesitter highlighting for all filetypes
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = "nvf_treesitter",
|
group = "nvf_treesitter",
|
||||||
pattern = "*",
|
pattern = ${toLuaObject cfg.indent.pattern},
|
||||||
callback = function()
|
callback = function(args)
|
||||||
vim.wo[0][0].foldmethod = "expr"
|
${optionalString (builtins.length cfg.indent.excludes > 0) ''
|
||||||
vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
local ft = vim.bo[args.buf].filetype
|
||||||
end,
|
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 != []) [
|
additionalRuntimePaths = mkIf (cfg.queries != []) [
|
||||||
(let
|
(let
|
||||||
|
|
|
||||||
|
|
@ -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 = {
|
||||||
|
|
@ -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 = ''
|
||||||
|
Register alternative parser names for a filetype.
|
||||||
|
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