diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index a0860c60a6..de017adc4f 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -1433,16 +1433,26 @@ Query:iter_matches({node}, {source}, {start}, {stop}, {opts}) (`fun(): integer, table, 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|). ============================================================================== diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index dbe3d54c2f..57d3ed1c01 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -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