mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
fix(treesitter): indentexpr/foldexpr now work as intended and override ftplugin settings. Fixes #6447
This commit is contained in:
@@ -72,7 +72,7 @@ opt.foldexpr = "v:lua.LazyVim.treesitter.foldexpr()" -- treesitter folds
|
||||
opt.foldlevel = 99
|
||||
opt.foldmethod = "expr"
|
||||
opt.foldtext = ""
|
||||
opt.formatexpr = "v:lua.require'lazyvim.util'.format.formatexpr()"
|
||||
opt.formatexpr = "v:lua.LazyVim.format.formatexpr()"
|
||||
opt.formatoptions = "jcroqlnt" -- tcqj
|
||||
opt.grepformat = "%f:%l:%c:%m"
|
||||
opt.grepprg = "rg --vimgrep"
|
||||
|
||||
@@ -80,9 +80,18 @@ return {
|
||||
|
||||
-- treesitter highlighting
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }),
|
||||
callback = function(ev)
|
||||
if LazyVim.treesitter.have(ev.match) then
|
||||
pcall(vim.treesitter.start)
|
||||
|
||||
-- check if ftplugins changed foldexpr/indentexpr
|
||||
for _, option in ipairs({ "foldexpr", "indentexpr" }) do
|
||||
local expr = "v:lua.LazyVim.treesitter." .. option .. "()"
|
||||
if vim.opt_global[option]:get() == expr then
|
||||
vim.opt_local[option] = expr
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -22,12 +22,12 @@ end
|
||||
|
||||
function M.foldexpr()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
return M.have(vim.b[buf].filetype) and vim.treesitter.foldexpr() or "0"
|
||||
return M.have(vim.bo[buf].filetype) and vim.treesitter.foldexpr() or "0"
|
||||
end
|
||||
|
||||
function M.indentexpr()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
return M.have(vim.b[buf].filetype) and require("nvim-treesitter").indentexpr() or -1
|
||||
return M.have(vim.bo[buf].filetype) and require("nvim-treesitter").indentexpr() or -1
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user