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:
parent
c16ad74d91
commit
3e0402178c
@ -1,6 +1,6 @@
|
||||
# chezmoi:template:left-delimiter=#{{
|
||||
#{{- /* vim: set filetype=toml: */ -}}
|
||||
[".local/share/nvim/lazy/lazy.nvim"]
|
||||
[".local/share/nvim/lazy.nvim"]
|
||||
type = "archive"
|
||||
url = "https://github.com/folke/lazy.nvim/archive/refs/tags/v11.17.5.tar.gz"
|
||||
exact = true
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
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({
|
||||
spec = {
|
||||
{ import = "plugins" },
|
||||
|
||||
@ -14,11 +14,55 @@ function M.treesitter_configs()
|
||||
require("nvim-treesitter.configs").setup(M.treesitter_config_setup)
|
||||
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 = {
|
||||
-- Add languages to be installed here that you want installed for treesitter
|
||||
ensure_installed = {
|
||||
"bash", "c", "cpp", "go", "lua", "python", "rust",
|
||||
"tsx", "javascript", "typescript", "vimdoc", "vim",
|
||||
"ruby", "html", "embedded_template",
|
||||
},
|
||||
|
||||
auto_install = true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user