mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-27 02:59:00 +02:00
plugins/treesitter: add parsersToFiletypes option
This commit is contained in:
parent
fb4118fc84
commit
fce6a33488
2 changed files with 32 additions and 2 deletions
|
@ -80,6 +80,20 @@ in {
|
||||||
|
|
||||||
folding = mkEnableOption "tree-sitter based folding";
|
folding = mkEnableOption "tree-sitter based folding";
|
||||||
|
|
||||||
|
languageRegister = mkOption {
|
||||||
|
type = with types; attrsOf (either str (listOf str));
|
||||||
|
description = ''
|
||||||
|
This is a wrapping of the `vim.treesitter.language.register` function.
|
||||||
|
Register specific parsers to one or several filetypes.
|
||||||
|
The keys are the parser names and the values are either one or several filetypes.
|
||||||
|
'';
|
||||||
|
default = {};
|
||||||
|
example = {
|
||||||
|
cpp = "onelab";
|
||||||
|
python = ["myFiletype" "anotherFiletype"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
grammarPackages = mkOption {
|
grammarPackages = mkOption {
|
||||||
type = with types; listOf package;
|
type = with types; listOf package;
|
||||||
default = cfg.package.passthru.allGrammars;
|
default = cfg.package.passthru.allGrammars;
|
||||||
|
@ -150,7 +164,14 @@ in {
|
||||||
'')
|
'')
|
||||||
+ ''
|
+ ''
|
||||||
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
|
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
|
||||||
'';
|
''
|
||||||
|
+ (optionalString (cfg.languageRegister != null) ''
|
||||||
|
__parserFiltypeMappings = ${helpers.toLuaObject cfg.languageRegister}
|
||||||
|
|
||||||
|
for parser_name, ft in pairs(__parserFiltypeMappings) do
|
||||||
|
require('vim.treesitter.language').register(parser_name, ft)
|
||||||
|
end
|
||||||
|
'');
|
||||||
|
|
||||||
extraFiles = mkIf cfg.nixvimInjections {
|
extraFiles = mkIf cfg.nixvimInjections {
|
||||||
"queries/nix/injections.scm" = ''
|
"queries/nix/injections.scm" = ''
|
||||||
|
@ -178,7 +199,11 @@ in {
|
||||||
if cfg.nixGrammars
|
if cfg.nixGrammars
|
||||||
then [(cfg.package.withPlugins (_: cfg.grammarPackages))]
|
then [(cfg.package.withPlugins (_: cfg.grammarPackages))]
|
||||||
else [cfg.package];
|
else [cfg.package];
|
||||||
extraPackages = [pkgs.tree-sitter pkgs.nodejs pkgs.gcc];
|
extraPackages = with pkgs; [
|
||||||
|
tree-sitter
|
||||||
|
nodejs
|
||||||
|
gcc
|
||||||
|
];
|
||||||
|
|
||||||
options = mkIf cfg.folding {
|
options = mkIf cfg.folding {
|
||||||
foldmethod = "expr";
|
foldmethod = "expr";
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
plugins.treesitter = {
|
plugins.treesitter = {
|
||||||
enable = true;
|
enable = true;
|
||||||
nixvimInjections = true;
|
nixvimInjections = true;
|
||||||
|
|
||||||
|
languageRegister = {
|
||||||
|
cpp = "onelab";
|
||||||
|
python = ["foo" "bar"];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue