mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-16 18:30:06 -04:00
fix: adapt to Nvim 0.11 deprecations
This commit is contained in:
parent
19ac9e8b5c
commit
3d268f9db4
5 changed files with 20 additions and 7 deletions
|
|
@ -24,4 +24,16 @@ function M.get_node_text(node, bufnr)
|
||||||
return (ts.get_node_text or tsq.get_node_text)(node, bufnr)
|
return (ts.get_node_text or tsq.get_node_text)(node, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.require_language(lang, opts)
|
||||||
|
return (ts.language.add or ts.language.require_language)(lang, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.flatten(t)
|
||||||
|
if vim.fn.has "nvim-0.10" then
|
||||||
|
return vim.iter(t):flatten():totable()
|
||||||
|
else
|
||||||
|
return vim.tbl_flatten(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ local parsers = require "nvim-treesitter.parsers"
|
||||||
local info = require "nvim-treesitter.info"
|
local info = require "nvim-treesitter.info"
|
||||||
local configs = require "nvim-treesitter.configs"
|
local configs = require "nvim-treesitter.configs"
|
||||||
local shell = require "nvim-treesitter.shell_command_selectors"
|
local shell = require "nvim-treesitter.shell_command_selectors"
|
||||||
|
local compat = require "nvim-treesitter.compat"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
@ -59,7 +60,7 @@ local function reattach_if_possible_fn(lang, error_on_fail)
|
||||||
local ft = vim.bo[buf].filetype
|
local ft = vim.bo[buf].filetype
|
||||||
ok, err = pcall(vim.treesitter.language.add, lang, { filetype = ft })
|
ok, err = pcall(vim.treesitter.language.add, lang, { filetype = ft })
|
||||||
else
|
else
|
||||||
ok, err = pcall(vim.treesitter.language.require_language, lang)
|
ok, err = pcall(compat.require_language, lang)
|
||||||
end
|
end
|
||||||
if not ok and error_on_fail then
|
if not ok and error_on_fail then
|
||||||
vim.notify("Could not load parser for " .. lang .. ": " .. vim.inspect(err))
|
vim.notify("Could not load parser for " .. lang .. ": " .. vim.inspect(err))
|
||||||
|
|
@ -535,7 +536,7 @@ local function install(options)
|
||||||
languages = parsers.available_parsers()
|
languages = parsers.available_parsers()
|
||||||
ask = false
|
ask = false
|
||||||
else
|
else
|
||||||
languages = vim.tbl_flatten { ... }
|
languages = compat.flatten { ... }
|
||||||
ask = ask_reinstall
|
ask = ask_reinstall
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -573,7 +574,7 @@ function M.update(options)
|
||||||
reset_progress_counter()
|
reset_progress_counter()
|
||||||
if ... and ... ~= "all" then
|
if ... and ... ~= "all" then
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local languages = vim.tbl_flatten { ... }
|
local languages = compat.flatten { ... }
|
||||||
local installed = 0
|
local installed = 0
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
if (not is_installed(lang)) or (needs_update(lang)) then
|
if (not is_installed(lang)) or (needs_update(lang)) then
|
||||||
|
|
@ -616,7 +617,7 @@ function M.uninstall(...)
|
||||||
ensure_installed_parsers = utils.difference(ensure_installed_parsers, configs.get_ignored_parser_installs())
|
ensure_installed_parsers = utils.difference(ensure_installed_parsers, configs.get_ignored_parser_installs())
|
||||||
|
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local languages = vim.tbl_flatten { ... }
|
local languages = compat.flatten { ... }
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
local install_dir, err = configs.get_parser_install_dir()
|
local install_dir, err = configs.get_parser_install_dir()
|
||||||
if err then
|
if err then
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ function M.select_compile_command(repo, cc, compile_location)
|
||||||
info = "Compiling...",
|
info = "Compiling...",
|
||||||
err = "Error during compilation",
|
err = "Error during compilation",
|
||||||
opts = {
|
opts = {
|
||||||
args = vim.tbl_flatten(M.select_compiler_args(repo, cc)),
|
args = require("nvim-treesitter.compat").flatten(M.select_compiler_args(repo, cc)),
|
||||||
cwd = compile_location,
|
cwd = compile_location,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ function M.setup_commands(mod, commands)
|
||||||
local f_args = def.f_args or "<f-args>"
|
local f_args = def.f_args or "<f-args>"
|
||||||
local call_fn =
|
local call_fn =
|
||||||
string.format("lua require'nvim-treesitter.%s'.commands.%s['run<bang>'](%s)", mod, command_name, f_args)
|
string.format("lua require'nvim-treesitter.%s'.commands.%s['run<bang>'](%s)", mod, command_name, f_args)
|
||||||
local parts = vim.tbl_flatten {
|
local parts = require("nvim-treesitter.compat").flatten {
|
||||||
"command!",
|
"command!",
|
||||||
"-bar",
|
"-bar",
|
||||||
def.args,
|
def.args,
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ function Runner:whole_file(dirs, opts)
|
||||||
assert.is.same(1, vim.fn.isdirectory(dir.filename))
|
assert.is.same(1, vim.fn.isdirectory(dir.filename))
|
||||||
return dir.filename
|
return dir.filename
|
||||||
end, dirs)
|
end, dirs)
|
||||||
local files = vim.tbl_flatten(vim.tbl_map(scan_dir, dirs))
|
local files = require("nvim-treesitter.compat").flatten(vim.tbl_map(scan_dir, dirs))
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
local relpath = Path:new(file):make_relative(self.base_dir.filename)
|
local relpath = Path:new(file):make_relative(self.base_dir.filename)
|
||||||
self.it(relpath, function()
|
self.it(relpath, function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue