Merge branch 'main' into dev

This commit is contained in:
chuyanlong 2025-09-18 16:15:46 +08:00
commit d38e2eb774
9 changed files with 109 additions and 34 deletions

View file

@ -1,3 +1,3 @@
{ {
".": "15.0.3" ".": "15.1.0"
} }

View file

@ -1,5 +1,18 @@
# Changelog # Changelog
## [15.1.0](https://github.com/LazyVim/LazyVim/compare/v15.0.3...v15.1.0) (2025-09-18)
### Features
* **treesitter:** automatically install and use mason's tree-sitter-cli if not installed on system ([725d048](https://github.com/LazyVim/LazyVim/commit/725d048e009b866425b2a0cc620ba2c413e8b65f))
* **treesitter:** refactored setting up treesitter indent/highlight/folds ([b93303d](https://github.com/LazyVim/LazyVim/commit/b93303d2339b1117171780cebed1d710fd3805d5))
### Bug Fixes
* **snacks:** safe wrapper around snacks statuscolumn to prevent errors when LazyVim is still installing ([5bf2378](https://github.com/LazyVim/LazyVim/commit/5bf237820d7938b1b6490164fbd75e4117d341c1))
## [15.0.3](https://github.com/LazyVim/LazyVim/compare/v15.0.2...v15.0.3) (2025-09-17) ## [15.0.3](https://github.com/LazyVim/LazyVim/compare/v15.0.2...v15.0.3) (2025-09-17)

View file

@ -1,4 +1,4 @@
*LazyVim.txt* For Neovim Last change: 2025 September 17 *LazyVim.txt* For Neovim Last change: 2025 September 18
============================================================================== ==============================================================================
Table of Contents *LazyVim-table-of-contents* Table of Contents *LazyVim-table-of-contents*

View file

@ -3,7 +3,7 @@ _G.LazyVim = require("lazyvim.util")
---@class LazyVimConfig: LazyVimOptions ---@class LazyVimConfig: LazyVimOptions
local M = {} local M = {}
M.version = "15.0.3" -- x-release-please-version M.version = "15.1.0" -- x-release-please-version
LazyVim.config = M LazyVim.config = M
---@class LazyVimOptions ---@class LazyVimOptions

View file

@ -68,9 +68,8 @@ opt.fillchars = {
diff = "", diff = "",
eob = " ", eob = " ",
} }
opt.foldexpr = "v:lua.LazyVim.treesitter.foldexpr()" -- treesitter folds
opt.foldlevel = 99 opt.foldlevel = 99
opt.foldmethod = "expr" opt.foldmethod = "indent"
opt.foldtext = "" opt.foldtext = ""
opt.formatexpr = "v:lua.LazyVim.format.formatexpr()" opt.formatexpr = "v:lua.LazyVim.format.formatexpr()"
opt.formatoptions = "jcroqlnt" -- tcqj opt.formatoptions = "jcroqlnt" -- tcqj
@ -78,7 +77,6 @@ opt.grepformat = "%f:%l:%c:%m"
opt.grepprg = "rg --vimgrep" opt.grepprg = "rg --vimgrep"
opt.ignorecase = true -- Ignore case opt.ignorecase = true -- Ignore case
opt.inccommand = "nosplit" -- preview incremental substitute opt.inccommand = "nosplit" -- preview incremental substitute
opt.indentexpr = "v:lua.LazyVim.treesitter.indentexpr()" -- treesitter indents
opt.jumpoptions = "view" opt.jumpoptions = "view"
opt.laststatus = 3 -- global statusline opt.laststatus = 3 -- global statusline
opt.linebreak = true -- Wrap lines at convenient points opt.linebreak = true -- Wrap lines at convenient points
@ -104,7 +102,7 @@ opt.spelllang = { "en" }
opt.splitbelow = true -- Put new windows below current opt.splitbelow = true -- Put new windows below current
opt.splitkeep = "screen" opt.splitkeep = "screen"
opt.splitright = true -- Put new windows right of current opt.splitright = true -- Put new windows right of current
opt.statuscolumn = [[%!v:lua.require'snacks.statuscolumn'.get()]] opt.statuscolumn = [[%!v:lua.LazyVim.statuscolumn()]]
opt.tabstop = 2 -- Number of spaces tabs count for opt.tabstop = 2 -- Number of spaces tabs count for
opt.termguicolors = true -- True color support opt.termguicolors = true -- True color support
opt.timeoutlen = vim.g.vscode and 1000 or 300 -- Lower than default (1000) to quickly trigger which-key opt.timeoutlen = vim.g.vscode and 1000 or 300 -- Lower than default (1000) to quickly trigger which-key

View file

@ -148,6 +148,7 @@ return {
LazyVim.lsp.on_supports_method("textDocument/foldingRange", function(client, buffer) LazyVim.lsp.on_supports_method("textDocument/foldingRange", function(client, buffer)
local win = vim.api.nvim_get_current_win() local win = vim.api.nvim_get_current_win()
vim.wo[win][0].foldexpr = "v:lua.vim.lsp.foldexpr()" vim.wo[win][0].foldexpr = "v:lua.vim.lsp.foldexpr()"
vim.wo[win][0].foldmethod = "expr"
end) end)
end end

View file

@ -13,7 +13,9 @@ return {
LazyVim.error("Please restart Neovim and run `:TSUpdate` to use the `nvim-treesitter` **main** branch.") LazyVim.error("Please restart Neovim and run `:TSUpdate` to use the `nvim-treesitter` **main** branch.")
return return
end end
TS.update(nil, { summary = true }) LazyVim.treesitter.ensure_treesitter_cli(function()
TS.update(nil, { summary = true })
end)
end, end,
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
event = { "LazyFile", "VeryLazy" }, event = { "LazyFile", "VeryLazy" },
@ -22,6 +24,9 @@ return {
---@class lazyvim.TSConfig: TSConfig ---@class lazyvim.TSConfig: TSConfig
opts = { opts = {
-- LazyVim config for treesitter -- LazyVim config for treesitter
indent = { enable = true },
highlight = { enable = true },
folds = { enable = true },
ensure_installed = { ensure_installed = {
"bash", "bash",
"c", "c",
@ -56,18 +61,12 @@ return {
-- some quick sanity checks -- some quick sanity checks
if not TS.get_installed then if not TS.get_installed then
return LazyVim.error("Please use `:Lazy` and update `nvim-treesitter`") return LazyVim.error("Please use `:Lazy` and update `nvim-treesitter`")
elseif vim.fn.executable("tree-sitter") == 0 then
return LazyVim.error({
"**treesitter-main** requires the `tree-sitter` CLI executable to be installed.",
"Run `:checkhealth nvim-treesitter` for more information.",
})
elseif type(opts.ensure_installed) ~= "table" then elseif type(opts.ensure_installed) ~= "table" then
return LazyVim.error("`nvim-treesitter` opts.ensure_installed must be a table") return LazyVim.error("`nvim-treesitter` opts.ensure_installed must be a table")
end end
-- setup treesitter -- setup treesitter
TS.setup(opts) TS.setup(opts)
LazyVim.treesitter.get_installed(true) -- initialize the installed langs LazyVim.treesitter.get_installed(true) -- initialize the installed langs
-- install missing parsers -- install missing parsers
@ -75,25 +74,34 @@ return {
return not LazyVim.treesitter.have(lang) return not LazyVim.treesitter.have(lang)
end, opts.ensure_installed or {}) end, opts.ensure_installed or {})
if #install > 0 then if #install > 0 then
TS.install(install, { summary = true }):await(function() LazyVim.treesitter.ensure_treesitter_cli(function()
LazyVim.treesitter.get_installed(true) -- refresh the installed langs TS.install(install, { summary = true }):await(function()
LazyVim.treesitter.get_installed(true) -- refresh the installed langs
end)
end) end)
end end
-- treesitter highlighting
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }), group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }),
callback = function(ev) callback = function(ev)
if LazyVim.treesitter.have(ev.match) then if not LazyVim.treesitter.have(ev.match) then
pcall(vim.treesitter.start) return
end
-- check if ftplugins changed foldexpr/indentexpr -- highlighting
for _, option in ipairs({ "foldexpr", "indentexpr" }) do if vim.tbl_get(opts, "highlight", "enable") ~= false then
local expr = "v:lua.LazyVim.treesitter." .. option .. "()" pcall(vim.treesitter.start)
if vim.opt_global[option]:get() == expr then end
vim.opt_local[option] = expr
end -- indents
end if vim.tbl_get(opts, "indent", "enable") ~= false then
vim.bo[ev.buf].indentexpr = "v:lua.LazyVim.treesitter.indentexpr()"
end
-- folds
if vim.tbl_get(opts, "folds", "enable") ~= false then
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "v:lua.LazyVim.treesitter.foldexpr()"
end end
end, end,
}) })

View file

@ -299,4 +299,9 @@ function M.memoize(fn)
end end
end end
-- Safe wrapper around snacks to prevent errors when LazyVim is still installing
function M.statuscolumn()
return package.loaded.snacks and require("snacks.statuscolumn").get() or ""
end
return M return M

View file

@ -14,20 +14,70 @@ function M.get_installed(update)
return M._installed or {} return M._installed or {}
end end
---@param ft string ---@param what string|number|nil
function M.have(ft) ---@overload fun(buf?:number):boolean
local lang = vim.treesitter.language.get_lang(ft) ---@overload fun(ft:string):boolean
return lang and M.get_installed()[lang] ---@return boolean
function M.have(what)
what = what or vim.api.nvim_get_current_buf()
what = type(what) == "number" and vim.bo[what].filetype or what --[[@as string]]
local lang = vim.treesitter.language.get_lang(what)
return lang ~= nil and M.get_installed()[lang] ~= nil
end end
function M.foldexpr() function M.foldexpr()
local buf = vim.api.nvim_get_current_buf() return M.have() and vim.treesitter.foldexpr() or "0"
return M.have(vim.bo[buf].filetype) and vim.treesitter.foldexpr() or "0"
end end
function M.indentexpr() function M.indentexpr()
local buf = vim.api.nvim_get_current_buf() return M.have() and require("nvim-treesitter").indentexpr() or -1
return M.have(vim.bo[buf].filetype) and require("nvim-treesitter").indentexpr() or -1 end
---@param cb fun()
function M.ensure_treesitter_cli(cb)
if vim.fn.executable("tree-sitter") == 1 then
return cb()
end
---@param msg? string
local function fail(msg)
return LazyVim.error({
"**treesitter-nvim** `main` requires the `tree-sitter` CLI executable to be installed.",
"Please install it manually from https://github.com/tree-sitter/tree-sitter/tree/master/crates/cli or",
"use your system package manager.",
"Run `:checkhealth nvim-treesitter` for more information.",
msg,
})
end
-- try installing with mason
if not pcall(require, "mason") then
return fail("`mason.nvim` is disabled in your config, so we cannot install it automatically.")
end
-- check again since we might have installed it already
if vim.fn.executable("tree-sitter") == 1 then
return cb()
end
local mr = require("mason-registry")
mr.refresh(function()
local p = mr.get_package("tree-sitter-cli")
if not p:is_installed() then
LazyVim.info("Installing `tree-sitter-cli` with `mason.nvim`...")
p:install(
nil,
vim.schedule_wrap(function(success)
if success then
LazyVim.info("Installed `tree-sitter-cli` with `mason.nvim`.")
cb()
else
fail("Failed to install `tree-sitter-cli` with `mason.nvim`.")
end
end)
)
end
end)
end end
return M return M