refactor: treesitter config

nixos
Moritz Böhme 2023-12-08 16:06:00 +01:00
parent c17d3f21d7
commit 360c8b155e
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
2 changed files with 50 additions and 19 deletions

View File

@ -1,10 +1 @@
require("nvim-treesitter.configs").setup({ require("nvim-treesitter.configs").setup()
sync_install = false,
auto_install = false,
highlight = {
enable = true,
},
context_commentstring = {
enable = true,
},
})

View File

@ -6,22 +6,62 @@ with builtins;
{ {
plugin = nvim-treesitter; plugin = nvim-treesitter;
event = [ "BufReadPost" "BufNewFile" ]; event = [ "BufReadPost" "BufNewFile" ];
opts = {
sync_install = false;
auto_install = false;
highlight = {
enable = true;
};
context_commentstring = {
enable = true;
};
textobjects =
{
select =
{
enable = true;
# Automatically jump forward to textobj, similar to targets.vim
lookahead = false;
keymaps = {
# You can use the capture groups defined in textobjects.scm
"af" = {
query = "@function.outer";
desc = "Select outer part of a function region";
};
"if" = {
query = "@function.inner";
desc = "Select inner part of a function region";
};
"ac" = {
query = "@class.outer";
desc = "Select outer part of a class region";
};
"ic" = {
query = "@class.inner";
desc = "Select inner part of a class region";
};
};
};
};
};
conf = conf =
let let
parserDir = pkgs.symlinkJoin { parserDir = pkgs.symlinkJoin
{
name = "tresitter-grammars-all"; name = "tresitter-grammars-all";
paths = lib.attrValues (lib.filterAttrs (_: builtins.isAttrs) nvim-treesitter-parsers); paths = lib.attrValues (lib.filterAttrs (_: builtins.isAttrs) nvim-treesitter-parsers);
}; };
in in
readFile ./lua/nvim-treesitter.lua + '' ''
vim.opt.runtimepath:append("${parserDir}") vim.opt.runtimepath:append("${parserDir}")
local final_opts = vim.tbl_deep_extend("keep", opts, { parser_install_dir = "${parserDir}" })
require'nvim-treesitter.configs'.setup { require('nvim-treesitter.configs').setup(final_opts)
parser_install_dir = "${parserDir}",
}
''; '';
dependencies = [ dependencies = [
{ plugin = nvim-ts-context-commentstring; } { plugin = nvim-ts-context-commentstring; }
{ plugin = nvim-treesitter-textobjects; }
]; ];
} }
{ {