mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 19:00:02 -04:00
chore: use vim.ui.select for TSEditQuery if available
This commit is contained in:
parent
44d4d07dbf
commit
98ada316c3
1 changed files with 36 additions and 19 deletions
|
|
@ -212,6 +212,29 @@ local function config_info(process_function)
|
||||||
print(vim.inspect(config, { process = process_function }))
|
print(vim.inspect(config, { process = process_function }))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not vim.ui then
|
||||||
|
vim.ui = {
|
||||||
|
select = function(items, opts, on_choice)
|
||||||
|
vim.validate {
|
||||||
|
items = { items, "table", false },
|
||||||
|
on_choice = { on_choice, "function", false },
|
||||||
|
}
|
||||||
|
opts = opts or {}
|
||||||
|
local choices = { opts.prompt or "Select one of:" }
|
||||||
|
local format_item = opts.format_item or tostring
|
||||||
|
for i, item in pairs(items) do
|
||||||
|
table.insert(choices, string.format("%d: %s", i, format_item(item)))
|
||||||
|
end
|
||||||
|
local choice = vim.fn.inputlist(choices)
|
||||||
|
if choice < 1 or choice > #items then
|
||||||
|
on_choice(nil, nil)
|
||||||
|
else
|
||||||
|
on_choice(items[choice], choice)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
function M.edit_query_file(query_group, lang)
|
function M.edit_query_file(query_group, lang)
|
||||||
lang = lang or parsers.get_buf_lang()
|
lang = lang or parsers.get_buf_lang()
|
||||||
local files = ts_query.get_query_files(lang, query_group, true)
|
local files = ts_query.get_query_files(lang, query_group, true)
|
||||||
|
|
@ -221,18 +244,11 @@ function M.edit_query_file(query_group, lang)
|
||||||
elseif #files == 1 then
|
elseif #files == 1 then
|
||||||
vim.cmd(":edit " .. files[1])
|
vim.cmd(":edit " .. files[1])
|
||||||
else
|
else
|
||||||
local counter = 0
|
vim.ui.select(files, { prompt = "Select a file:" }, function(file)
|
||||||
local choices = {
|
if file then
|
||||||
"Select a file:",
|
vim.cmd(":edit " .. file)
|
||||||
unpack(vim.tbl_map(function(f)
|
end
|
||||||
counter = counter + 1
|
end)
|
||||||
return counter .. ". " .. f
|
|
||||||
end, files)),
|
|
||||||
}
|
|
||||||
local choice = vim.fn.inputlist(choices)
|
|
||||||
if choice > 0 and choice <= #files then
|
|
||||||
vim.cmd(":edit " .. files[choice])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -241,14 +257,15 @@ function M.edit_query_file_user_after(query_group, lang)
|
||||||
local folder = utils.join_path(vim.fn.stdpath "config", "after", "queries", lang)
|
local folder = utils.join_path(vim.fn.stdpath "config", "after", "queries", lang)
|
||||||
local file = utils.join_path(folder, query_group .. ".scm")
|
local file = utils.join_path(folder, query_group .. ".scm")
|
||||||
if vim.fn.isdirectory(folder) ~= 1 then
|
if vim.fn.isdirectory(folder) ~= 1 then
|
||||||
local choice = vim.fn.inputlist { '"' .. folder .. " does not exist. Create it?", "1. Yes", "2. No" }
|
vim.ui.select({ "Yes", "No" }, { prompt = '"' .. folder .. '" does not exist. Create it?' }, function(choice)
|
||||||
if choice == 1 then
|
if choice == "Yes" then
|
||||||
vim.fn.mkdir(folder, "p", "0755")
|
vim.fn.mkdir(folder, "p", "0755")
|
||||||
else
|
vim.cmd(":edit " .. file)
|
||||||
return
|
end
|
||||||
end
|
end)
|
||||||
|
else
|
||||||
|
vim.cmd(":edit " .. file)
|
||||||
end
|
end
|
||||||
vim.cmd(":edit " .. file)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue