mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
feat: Add TSEditQuery
This commit is contained in:
parent
b6fc47d5f1
commit
4214646953
3 changed files with 44 additions and 0 deletions
|
|
@ -18,6 +18,10 @@ function! nvim_treesitter#available_modules(arglead, cmdline, cursorpos) abort
|
||||||
return join(luaeval("require'nvim-treesitter.configs'.available_modules()"), "\n")
|
return join(luaeval("require'nvim-treesitter.configs'.available_modules()"), "\n")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#available_query_groups(arglead, cmdline, cursorpos) abort
|
||||||
|
return join(luaeval("require'nvim-treesitter.query'.available_query_groups()"), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! nvim_treesitter#indent() abort
|
function! nvim_treesitter#indent() abort
|
||||||
return luaeval(printf('require"nvim-treesitter.indent".get_indent(%d)', v:lnum))
|
return luaeval(printf('require"nvim-treesitter.indent".get_indent(%d)', v:lnum))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
local queries = require'nvim-treesitter.query'
|
local queries = require'nvim-treesitter.query'
|
||||||
|
local nvim_query = require'vim.treesitter.query'
|
||||||
local parsers = require'nvim-treesitter.parsers'
|
local parsers = require'nvim-treesitter.parsers'
|
||||||
local utils = require'nvim-treesitter.utils'
|
local utils = require'nvim-treesitter.utils'
|
||||||
local caching = require'nvim-treesitter.caching'
|
local caching = require'nvim-treesitter.caching'
|
||||||
|
|
@ -196,6 +197,25 @@ local function config_info(process_function)
|
||||||
print(vim.inspect(config, {process = process_function}))
|
print(vim.inspect(config, {process = process_function}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.edit_query_file(query_group, lang)
|
||||||
|
lang = lang or parsers.get_buf_lang()
|
||||||
|
local files = nvim_query.get_query_files(lang, query_group, true)
|
||||||
|
if #files == 0 then
|
||||||
|
local folder = utils.join_path(vim.fn.stdpath('config'), 'after', 'queries', lang)
|
||||||
|
local file = utils.join_path(folder, query_group..'.scm')
|
||||||
|
pcall(vim.fn.mkdir, folder, "p", "0755")
|
||||||
|
vim.cmd(':edit '..file)
|
||||||
|
elseif #files == 1 then
|
||||||
|
vim.cmd(':edit '..files[1])
|
||||||
|
else
|
||||||
|
local counter = 0
|
||||||
|
local choice = vim.fn.inputlist(vim.tbl_map(function(f) counter = counter + 1;return counter..'. '..f end, files))
|
||||||
|
if choice > 0 then
|
||||||
|
vim.cmd(':edit '..files[choice])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.commands = {
|
M.commands = {
|
||||||
TSBufEnable = {
|
TSBufEnable = {
|
||||||
run = enable_module,
|
run = enable_module,
|
||||||
|
|
@ -245,6 +265,13 @@ M.commands = {
|
||||||
"-nargs=0",
|
"-nargs=0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
TSEditQuery = {
|
||||||
|
run = M.edit_query_file,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_query_groups",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @param mod: module (string)
|
-- @param mod: module (string)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,19 @@ for _, query in ipairs(M.built_in_query_groups) do
|
||||||
M["has_" .. query] = get_query_guard(query)
|
M["has_" .. query] = get_query_guard(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.available_query_groups()
|
||||||
|
local query_files = api.nvim_get_runtime_file('queries/*/*.scm', true)
|
||||||
|
local groups = {}
|
||||||
|
for _, f in ipairs(query_files) do
|
||||||
|
groups[vim.fn.fnamemodify(f, ':t:r')] = true
|
||||||
|
end
|
||||||
|
local list = {}
|
||||||
|
for k, _ in pairs(groups) do
|
||||||
|
table.insert(list, k)
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local query_cache = caching.create_buffer_cache()
|
local query_cache = caching.create_buffer_cache()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue