fix(treesitter-main): set vim.bo.indentexpr in FileType autocmd (#6430)

## Description

Ref:
7aa24acae3/scripts/minimal_init.lua (L19-L24)

## Related Issue(s)

<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
This commit is contained in:
qw457812
2025-09-16 17:58:24 +08:00
committed by GitHub
parent cc4a3e5564
commit b926e7db41

View File

@@ -31,19 +31,21 @@ return {
vim.list_extend(installed, install)
end
-- backwards compatibility with the old treesitter config for indent
if vim.tbl_get(opts, "indent", "enable") then
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
-- backwards compatibility with the old treesitter config for highlight
if vim.tbl_get(opts, "highlight", "enable") then
-- backwards compatibility with the old treesitter config for highlight and indent
local highlight, indent = vim.tbl_get(opts, "highlight", "enable"), vim.tbl_get(opts, "indent", "enable")
if highlight or indent then
vim.api.nvim_create_autocmd("FileType", {
callback = function(ev)
local lang = vim.treesitter.language.get_lang(ev.match)
if vim.tbl_contains(installed, lang) then
if not vim.tbl_contains(installed, lang) then
return
end
if highlight then
pcall(vim.treesitter.start)
end
if indent then
vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end,
})
end