Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/manual/release-notes/rl-0.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@

[jtliang24](https://github.com/jtliang24):

- Updated nix language plugin to use pkgs.nixfmt instead of pkgs.nixfmt-rfc-style
- Updated nix language plugin to use pkgs.nixfmt instead of
pkgs.nixfmt-rfc-style
35 changes: 22 additions & 13 deletions modules/plugins/treesitter/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,36 @@ in {
pluginRC.treesitter-autocommands = entryAfter ["basic"] ''
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })

${lib.optionalString cfg.highlight.enable ''
-- Enable treesitter highlighting for all filetypes
vim.api.nvim_create_autocmd("FileType", {
group = "nvf_treesitter",
pattern = "*",
callback = function()
pcall(vim.treesitter.start)
end,
})
''}
local has_configs_module = pcall(require, 'nvim-treesitter.configs')

${lib.optionalString cfg.indent.enable ''
-- Enable treesitter highlighting for all filetypes
if has_configs_module then
-- nvim-treesitter master branch
require('nvim-treesitter.configs').setup(vim.tbl_deep_extend("force", {
${lib.optionalString cfg.highlight.enable ''
highlight = { enable = true },
''}${lib.optionalString cfg.indent.enable ''
indent = { enable = true },
''}
}, ${lib.nvim.lua.toLuaObject cfg.setupOpts}))
else
-- nvim-treesitter main branch
${lib.optionalString (cfg.setupOpts != {}) ''
require('nvim-treesitter').setup(${lib.nvim.lua.toLuaObject cfg.setupOpts})
''}
${lib.optionalString (cfg.highlight.enable || cfg.indent.enable) ''
vim.api.nvim_create_autocmd("FileType", {
group = "nvf_treesitter",
pattern = "*",
callback = function()
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
${lib.optionalString cfg.highlight.enable ''
pcall(vim.treesitter.start)
''}${lib.optionalString cfg.indent.enable ''
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
''}
end,
})
''}
end

${lib.optionalString cfg.fold ''
-- Enable treesitter folding for all filetypes
Expand Down
3 changes: 3 additions & 0 deletions modules/plugins/treesitter/treesitter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) listOf package bool;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
Expand Down Expand Up @@ -66,5 +67,7 @@ in {

indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};};
highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};};

setupOpts = mkPluginSetupOption "nvim-treesitter" {};
};
}
Loading