mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
2003d7360c
4 changed files with 92 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
*LazyVim.txt* For Neovim Last change: 2025 October 14
|
||||
*LazyVim.txt* For Neovim Last change: 2025 October 15
|
||||
|
||||
==============================================================================
|
||||
Table of Contents *LazyVim-table-of-contents*
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ local start = vim.health.start or vim.health.report_start
|
|||
local ok = vim.health.ok or vim.health.report_ok
|
||||
local warn = vim.health.warn or vim.health.report_warn
|
||||
local error = vim.health.error or vim.health.report_error
|
||||
local info = vim.health.info or vim.health.report_info
|
||||
|
||||
function M.check()
|
||||
start("LazyVim")
|
||||
|
|
@ -33,6 +34,23 @@ function M.check()
|
|||
warn(("`%s` is not installed"):format(name))
|
||||
end
|
||||
end
|
||||
|
||||
start("LazyVim nvim-treesitter")
|
||||
local tsok, health = LazyVim.treesitter.check()
|
||||
local keys = vim.tbl_keys(health) ---@type string[]
|
||||
table.sort(keys)
|
||||
for _, k in pairs(keys) do
|
||||
(health[k] and ok or error)(("`%s` is %s"):format(k, health[k] and "installed" or "not installed"))
|
||||
end
|
||||
if not tsok then
|
||||
info(
|
||||
"See the requirements at [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter/tree/main?tab=readme-ov-file#requirements)"
|
||||
)
|
||||
info("Run `:checkhealth nvim-treesitter` for more information.")
|
||||
if vim.fn.has("win32") == 1 and not health["C compiler"] then
|
||||
info("Install a C compiler with `winget install --id=BrechtSanders.WinLibs.POSIX.UCRT -e`")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ return {
|
|||
LazyVim.error("Please restart Neovim and run `:TSUpdate` to use the `nvim-treesitter` **main** branch.")
|
||||
return
|
||||
end
|
||||
LazyVim.treesitter.ensure_treesitter_cli(function()
|
||||
LazyVim.treesitter.build(function()
|
||||
TS.update(nil, { summary = true })
|
||||
end)
|
||||
end,
|
||||
|
|
@ -90,7 +90,7 @@ return {
|
|||
return not LazyVim.treesitter.have(lang)
|
||||
end, opts.ensure_installed or {})
|
||||
if #install > 0 then
|
||||
LazyVim.treesitter.ensure_treesitter_cli(function()
|
||||
LazyVim.treesitter.build(function()
|
||||
TS.install(install, { summary = true }):await(function()
|
||||
LazyVim.treesitter.get_installed(true) -- refresh the installed langs
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -51,31 +51,85 @@ function M.indentexpr()
|
|||
return M.have(nil, "indents") 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()
|
||||
---@return string?
|
||||
local function win_find_cl()
|
||||
local path = "C:/Program Files (x86)/Microsoft Visual Studio"
|
||||
local pattern = "*/*/VC/Tools/MSVC/*/bin/Hostx64/x64/cl.exe"
|
||||
return vim.fn.globpath(path, pattern, true, true)[1]
|
||||
end
|
||||
|
||||
---@return boolean ok, lazyvim.util.treesitter.Health health
|
||||
function M.check()
|
||||
local is_win = vim.fn.has("win32") == 1
|
||||
---@param tool string
|
||||
---@param win boolean?
|
||||
local function have(tool, win)
|
||||
return (win == nil or is_win == win) and vim.fn.executable(tool) == 1
|
||||
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,
|
||||
})
|
||||
local have_cc = vim.env.CC ~= nil or have("cc", false) or have("cl", true) or (is_win and win_find_cl() ~= nil)
|
||||
|
||||
if not have_cc and is_win and vim.fn.executable("gcc") == 1 then
|
||||
vim.env.CC = "gcc"
|
||||
have_cc = true
|
||||
end
|
||||
|
||||
---@class lazyvim.util.treesitter.Health: table<string,boolean>
|
||||
local ret = {
|
||||
["tree-sitter (CLI)"] = have("tree-sitter"),
|
||||
["C compiler"] = have_cc,
|
||||
tar = have("tar"),
|
||||
curl = have("curl"),
|
||||
node = have("node"),
|
||||
}
|
||||
local ok = true
|
||||
for _, v in pairs(ret) do
|
||||
ok = ok and v
|
||||
end
|
||||
return ok, ret
|
||||
end
|
||||
|
||||
---@param cb fun()
|
||||
function M.build(cb)
|
||||
M.ensure_treesitter_cli(function(_, err)
|
||||
local ok, health = M.check()
|
||||
if ok then
|
||||
return cb()
|
||||
else
|
||||
local lines = { "Unmet requirements for **nvim-treesitter** `main`:" }
|
||||
local keys = vim.tbl_keys(health) ---@type string[]
|
||||
table.sort(keys)
|
||||
for _, k in pairs(keys) do
|
||||
lines[#lines + 1] = ("- %s `%s`"):format(health[k] and "✅" or "❌", k)
|
||||
end
|
||||
vim.list_extend(lines, {
|
||||
"",
|
||||
"See the requirements at [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter/tree/main?tab=readme-ov-file#requirements)",
|
||||
"Run `:checkhealth nvim-treesitter` for more information.",
|
||||
})
|
||||
if vim.fn.has("win32") == 1 and not health["C compiler"] then
|
||||
lines[#lines + 1] = "Install a C compiler with `winget install --id=BrechtSanders.WinLibs.POSIX.UCRT -e`"
|
||||
end
|
||||
vim.list_extend(lines, err and { "", err } or {})
|
||||
LazyVim.error(lines, { title = "LazyVim Treesitter" })
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---@param cb fun(ok:boolean, err?:string)
|
||||
function M.ensure_treesitter_cli(cb)
|
||||
if vim.fn.executable("tree-sitter") == 1 then
|
||||
return cb(true)
|
||||
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.")
|
||||
return cb(false, "`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()
|
||||
return cb(true)
|
||||
end
|
||||
|
||||
local mr = require("mason-registry")
|
||||
|
|
@ -88,9 +142,9 @@ function M.ensure_treesitter_cli(cb)
|
|||
vim.schedule_wrap(function(success)
|
||||
if success then
|
||||
LazyVim.info("Installed `tree-sitter-cli` with `mason.nvim`.")
|
||||
cb()
|
||||
cb(true)
|
||||
else
|
||||
fail("Failed to install `tree-sitter-cli` with `mason.nvim`.")
|
||||
cb(false, "Failed to install `tree-sitter-cli` with `mason.nvim`.")
|
||||
end
|
||||
end)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue