fixed folding -- again
This commit is contained in:
@@ -10,20 +10,45 @@
|
||||
- vim.go.* for global option shorthand
|
||||
]]
|
||||
|
||||
-- ============================================================================
|
||||
-- TREESITTER (Built-in Neovim 0.10+ features)
|
||||
-- ============================================================================
|
||||
-- Enable Treesitter syntax highlighting (native in Neovim 0.10+)
|
||||
-- This replaces the old nvim-treesitter highlight module
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
if vim.bo.buftype == "" and vim.bo.filetype ~= "" then
|
||||
pcall(vim.treesitter.start)
|
||||
end
|
||||
end,
|
||||
desc = "Enable Treesitter highlighting",
|
||||
})
|
||||
|
||||
-- ============================================================================
|
||||
-- FOLDING SETTINGS (Code folding)
|
||||
-- ============================================================================
|
||||
-- Foldmethod determines how code blocks are detected and folded
|
||||
-- "expr" means folds are based on expressions (we use treesitter for this)
|
||||
vim.opt.foldmethod = "expr"
|
||||
|
||||
-- Foldexpr is the expression used to determine fold level
|
||||
-- v:lua.vim.treesitter.foldexpr() uses Treesitter to calculate folds
|
||||
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||
-- NOTE: In Neovim 0.10+, Treesitter folding must be set per-buffer via FileType autocmd
|
||||
-- Setting it globally causes the foldexpr to evaluate before Treesitter attaches
|
||||
|
||||
-- Foldlevel: Higher number = more folds are open by default
|
||||
-- 99 means almost all folds are open when opening a file
|
||||
vim.opt.foldlevel = 99
|
||||
-- 1-2 means you'll see folds by default; 99 means all folds are open
|
||||
vim.opt.foldlevel = 1
|
||||
vim.opt.foldlevelstart = 1
|
||||
|
||||
-- Setup Treesitter folding for each buffer after filetype is detected
|
||||
-- This ensures the parser is loaded before foldexpr evaluates
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
-- Only set folding for file buffers with Treesitter support
|
||||
if vim.bo.buftype == "" then
|
||||
vim.wo.foldmethod = "expr"
|
||||
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||
end
|
||||
end,
|
||||
desc = "Setup Treesitter folding per filetype",
|
||||
})
|
||||
|
||||
-- ============================================================================
|
||||
-- LINE NUMBERS
|
||||
|
||||
@@ -3,36 +3,56 @@ return {
|
||||
build = ":TSUpdate",
|
||||
event = { "BufReadPost", "BufNewFile" },
|
||||
config = function()
|
||||
-- Ensure nvim-treesitter queries are preferred over runtime queries
|
||||
-- This fixes the "except*" syntax error with updated parsers
|
||||
vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/lazy/nvim-treesitter")
|
||||
-- In the latest nvim-treesitter (post-refactor), the plugin only handles
|
||||
-- parser installation. Highlighting, folding, and indenting are handled
|
||||
-- by native Neovim Treesitter integration.
|
||||
|
||||
local ok, configs = pcall(require, "nvim-treesitter.configs")
|
||||
-- CRITICAL: Add nvim-treesitter/runtime to runtimepath so queries are found
|
||||
local ts_runtime = vim.fn.stdpath("data") .. "/lazy/nvim-treesitter/runtime"
|
||||
vim.opt.runtimepath:prepend(ts_runtime)
|
||||
|
||||
-- Setup nvim-treesitter (minimal config for parser installation)
|
||||
require("nvim-treesitter").setup({
|
||||
-- Parser installation directory (default: stdpath('data')/site)
|
||||
install_dir = vim.fn.stdpath("data") .. "/site",
|
||||
})
|
||||
|
||||
-- Auto-install parsers for these languages when opening a file
|
||||
local ensure_installed = {
|
||||
"python",
|
||||
"lua",
|
||||
"json",
|
||||
"yaml",
|
||||
"javascript",
|
||||
"typescript",
|
||||
"tsx",
|
||||
"vue",
|
||||
"html",
|
||||
"css",
|
||||
"bash",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
}
|
||||
|
||||
-- Install parsers
|
||||
local ok, install = pcall(require, "nvim-treesitter.install")
|
||||
if ok then
|
||||
configs.setup({
|
||||
auto_install = true,
|
||||
ensure_installed = {
|
||||
"python",
|
||||
"lua",
|
||||
"json",
|
||||
"yaml",
|
||||
"javascript",
|
||||
"typescript",
|
||||
"tsx",
|
||||
"vue",
|
||||
"html",
|
||||
"css",
|
||||
"bash",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
},
|
||||
highlight = {
|
||||
enable = true,
|
||||
-- Disable additional_vim_regex_highlighting to avoid conflicts
|
||||
additional_vim_regex_highlighting = false,
|
||||
},
|
||||
indent = { enable = true },
|
||||
})
|
||||
for _, lang in ipairs(ensure_installed) do
|
||||
vim.schedule(function()
|
||||
install.install({ lang })
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Enable Treesitter-based indenting (natively supported by Neovim)
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
if vim.bo.buftype == "" and vim.bo.filetype ~= "" then
|
||||
vim.bo.indentexpr = "v:lua.vim.treesitter.indentexpr()"
|
||||
end
|
||||
end,
|
||||
desc = "Enable Treesitter indenting",
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user