This commit is contained in:
Maria José Solano 2024-12-18 11:22:42 -08:00 committed by GitHub
commit 590f3cdada
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View File

@ -1433,16 +1433,26 @@ Query:iter_matches({node}, {source}, {start}, {stop}, {opts})
(`fun(): integer, table<integer, TSNode[]>, vim.treesitter.query.TSMetadata`)
pattern id, match, metadata
set({lang}, {query_name}, {text}) *vim.treesitter.query.set()*
set({lang}, {query_name}, {text}, {opts}) *vim.treesitter.query.set()*
Sets the runtime query named {query_name} for {lang}
This allows users to override any runtime files and/or configuration set
by plugins.
This allows users to override or extend any runtime files and/or
configuration set by plugins.
Parameters: ~
• {lang} (`string`) Language to use for the query
• {query_name} (`string`) Name of the query (e.g., "highlights")
• {text} (`string`) Query text (unparsed).
• {opts} (`table?`) A table with the following fields:
• {bufnr}? (`integer`) Buffer this query should apply to
(`0` for current buffer, `nil` for all buffers for
{lang}).
• {inherits}? (`string|string[]`) Language(s) this query
should inherit from (see
|treesitter-query-modeline-inherits|).
• {extends}? (`boolean`) Whether the query should be an
extension query (see
|treesitter-query-modeline-extends|).
==============================================================================

View File

@ -195,15 +195,28 @@ local explicit_queries = setmetatable({}, {
end,
})
--- @class vim.treesitter.query.set.Opts
--- @inlinedoc
---
--- Buffer this query should apply to (`0` for current buffer, `nil` for all buffers for {lang}).
--- @field bufnr? integer
---
--- Language(s) this query should inherit from (see |treesitter-query-modeline-inherits|).
--- @field inherits? string|string[]
---
--- Whether the query should be an extension query (see |treesitter-query-modeline-extends|).
--- @field extends? boolean
--- Sets the runtime query named {query_name} for {lang}
---
--- This allows users to override any runtime files and/or configuration
--- This allows users to override or extend any runtime files and/or configuration
--- set by plugins.
---
---@param lang string Language to use for the query
---@param query_name string Name of the query (e.g., "highlights")
---@param text string Query text (unparsed).
function M.set(lang, query_name, text)
---@param opts? vim.treesitter.query.set.Opts
function M.set(lang, query_name, text, opts)
explicit_queries[lang][query_name] = M.parse(lang, text)
end