fix: resolve lazy.nvim lock crash and erb treesitter crash

Move lazy.nvim's own install outside the lazy plugin root so it's
treated as local and skipped during git-based lock file writes -
installing it as a tarball left it without a .git dir, which crashed
lazy's lock.update() on every sync (assert on Git.info of a non-git
dir).

Also patch nvim-treesitter's set-lang-from-mimetype! directive, which
crashes on any <script type="..."> tag because it reads match[id] as
a single node when Neovim core now always returns an array there.
Hooked on LazyDone so it overrides nvim-treesitter's own registration
instead of being clobbered by it. Added ruby/html/embedded_template
to ensure_installed so TSUpdate actually keeps those parsers current
instead of relying on one-time auto_install.
This commit is contained in:
Buddy 2026-10-24 14:45:14 -07:00
parent c16ad74d91
commit 3e0402178c
3 changed files with 46 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# chezmoi:template:left-delimiter=#{{ # chezmoi:template:left-delimiter=#{{
#{{- /* vim: set filetype=toml: */ -}} #{{- /* vim: set filetype=toml: */ -}}
[".local/share/nvim/lazy/lazy.nvim"] [".local/share/nvim/lazy.nvim"]
type = "archive" type = "archive"
url = "https://github.com/folke/lazy.nvim/archive/refs/tags/v11.17.5.tar.gz" url = "https://github.com/folke/lazy.nvim/archive/refs/tags/v11.17.5.tar.gz"
exact = true exact = true

View File

@ -1,5 +1,5 @@
require("core.config") require("core.config")
vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/lazy/lazy.nvim") vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/lazy.nvim")
require("lazy").setup({ require("lazy").setup({
spec = { spec = {
{ import = "plugins" }, { import = "plugins" },

View File

@ -14,11 +14,55 @@ function M.treesitter_configs()
require("nvim-treesitter.configs").setup(M.treesitter_config_setup) require("nvim-treesitter.configs").setup(M.treesitter_config_setup)
end end
-- Works around a crash in nvim-treesitter's bundled `set-lang-from-mimetype!`
-- directive (queries/html_tags/injections.scm, used by html/erb/vue/svelte):
-- it reads `match[capture_id]` as a single TSNode, but current Neovim core
-- always returns an array of nodes there, so `<script type="...">` tags
-- crash the whole buffer's treesitter parse. Re-register the directive with
-- the same behavior, reading the first node out of the array instead.
--
-- Must run after nvim-treesitter's own `plugin/query_predicates.lua` has
-- registered its (broken) version, or that clobbers this one right back.
-- `LazyDone` fires once after all plugins (incl. nvim-treesitter's own
-- plugin/ scripts) have finished loading, so it's the reliable hook.
vim.api.nvim_create_autocmd("User", {
pattern = "LazyDone",
once = true,
callback = function()
M.patch_mimetype_directive()
end,
})
function M.patch_mimetype_directive()
local html_script_type_languages = {
["importmap"] = "json",
["module"] = "javascript",
["application/ecmascript"] = "javascript",
["text/ecmascript"] = "javascript",
}
vim.treesitter.query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, metadata)
local nodes = match[pred[2]]
local node = nodes and nodes[1]
if not node then
return
end
local type_attr_value = vim.treesitter.get_node_text(node, bufnr)
local configured = html_script_type_languages[type_attr_value]
if configured then
metadata["injection.language"] = configured
else
local parts = vim.split(type_attr_value, "/", {})
metadata["injection.language"] = parts[#parts]
end
end, { force = true })
end
M.treesitter_config_setup = { M.treesitter_config_setup = {
-- Add languages to be installed here that you want installed for treesitter -- Add languages to be installed here that you want installed for treesitter
ensure_installed = { ensure_installed = {
"bash", "c", "cpp", "go", "lua", "python", "rust", "bash", "c", "cpp", "go", "lua", "python", "rust",
"tsx", "javascript", "typescript", "vimdoc", "vim", "tsx", "javascript", "typescript", "vimdoc", "vim",
"ruby", "html", "embedded_template",
}, },
auto_install = true, auto_install = true,