Migrate Neovim config to 0.12

This commit is contained in:
2026-05-28 07:38:39 +03:00
parent 632f3579ce
commit 5672967635
11 changed files with 103 additions and 31 deletions

View File

@@ -9,6 +9,7 @@ local M = {
M.group = vim.api.nvim_create_augroup('language-manager', { clear = true })
local cache_path = vim.fn.stdpath('cache') .. '/language-manager.json'
local cache_version = 2
local function wrap(item)
if type(item) == 'string' then
@@ -162,6 +163,14 @@ function M.generate_specs(specs_raw)
spec.ts = spec.ts or spec.ft
specs.add(spec.ts, 'ts_parsers')
local tree_sitter_filetypes = wrap(spec.ft)
if #tree_sitter_filetypes == 0 then
tree_sitter_filetypes = wrap(spec.ts)
end
for _, ft in ipairs(tree_sitter_filetypes) do
specs.add(spec.ts, 'ts_parsers_by_ft', ft)
end
install_spec.add(spec.lsp, 'code_tools')
local resolved_lsps = {}
for _, language_server in ipairs(wrap(spec.lsp)) do
@@ -209,11 +218,11 @@ function M.load_specs()
local specs_raw = require('modules.language-specs').get()
local hash = hash_spec(specs_raw)
local cache = load_cache()
if cache and cache.hash == hash then
if cache and cache.version == cache_version and cache.hash == hash then
M.general = cache.spec
else
M.general, M.mason = M.generate_specs(specs_raw)
save_cache({ hash = hash, spec = M.general })
save_cache({ version = cache_version, hash = hash, spec = M.general })
end
return M.general, M.mason
end
@@ -231,8 +240,13 @@ end
function M.ts.install()
vim.cmd.packadd('nvim-treesitter')
local ts_install = require('nvim-treesitter.install').ensure_installed_sync
ts_install(M.general.ts_parsers)
if vim.fn.executable('tree-sitter') == 0 then
error('tree-sitter CLI 0.26.1+ is required to install nvim-treesitter parsers')
end
require('nvim-treesitter').setup({
install_dir = vim.fn.stdpath('data') .. '/site',
})
require('nvim-treesitter').install(M.general.ts_parsers):wait(5 * 60 * 1000)
end
function M.mason_install()
@@ -287,9 +301,20 @@ function M.install()
end
function M.ts.setup()
require('nvim-treesitter.configs').setup({
highlight = { enable = true },
incremental_selection = { enable = true },
require('nvim-treesitter').setup({
install_dir = vim.fn.stdpath('data') .. '/site',
})
vim.api.nvim_create_autocmd('FileType', {
group = M.group,
callback = function(args)
local parsers = M.general
and M.general.ts_parsers_by_ft
and M.general.ts_parsers_by_ft[vim.bo[args.buf].filetype]
if parsers and #parsers > 0 then
vim.treesitter.start(args.buf)
end
end,
})
end