mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 12:50:09 -04:00
fix(query): explicitly opt-in to legacy behavior
This commit is contained in:
parent
5b8b126de0
commit
3826d0c42a
1 changed files with 13 additions and 10 deletions
|
|
@ -15,6 +15,9 @@ local non_filetype_match_injection_language_aliases = {
|
||||||
ts = "typescript",
|
ts = "typescript",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- compatibility shim for breaking change on nightly/0.11
|
||||||
|
local opts = vim.fn.has "nvim-0.10" == 1 and { force = true, all = false } or true
|
||||||
|
|
||||||
local function get_parser_from_markdown_info_string(injection_alias)
|
local function get_parser_from_markdown_info_string(injection_alias)
|
||||||
local match = vim.filetype.match { filename = "a." .. injection_alias }
|
local match = vim.filetype.match { filename = "a." .. injection_alias }
|
||||||
return match or non_filetype_match_injection_language_aliases[injection_alias] or injection_alias
|
return match or non_filetype_match_injection_language_aliases[injection_alias] or injection_alias
|
||||||
|
|
@ -57,7 +60,7 @@ query.add_predicate("nth?", function(match, _pattern, _bufnr, pred)
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _pattern string
|
---@param _pattern string
|
||||||
|
|
@ -91,9 +94,9 @@ local function has_ancestor(match, _pattern, _bufnr, pred)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
query.add_predicate("has-ancestor?", has_ancestor, true)
|
query.add_predicate("has-ancestor?", has_ancestor, opts)
|
||||||
|
|
||||||
query.add_predicate("has-parent?", has_ancestor, true)
|
query.add_predicate("has-parent?", has_ancestor, opts)
|
||||||
|
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _pattern string
|
---@param _pattern string
|
||||||
|
|
@ -117,7 +120,7 @@ query.add_predicate("is?", function(match, _pattern, bufnr, pred)
|
||||||
local _, _, kind = locals.find_definition(node, bufnr)
|
local _, _, kind = locals.find_definition(node, bufnr)
|
||||||
|
|
||||||
return vim.tbl_contains(types, kind)
|
return vim.tbl_contains(types, kind)
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _pattern string
|
---@param _pattern string
|
||||||
|
|
@ -137,7 +140,7 @@ query.add_predicate("kind-eq?", function(match, _pattern, _bufnr, pred)
|
||||||
end
|
end
|
||||||
|
|
||||||
return vim.tbl_contains(types, node:type())
|
return vim.tbl_contains(types, node:type())
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _ string
|
---@param _ string
|
||||||
|
|
@ -158,7 +161,7 @@ query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, m
|
||||||
local parts = vim.split(type_attr_value, "/", {})
|
local parts = vim.split(type_attr_value, "/", {})
|
||||||
metadata["injection.language"] = parts[#parts]
|
metadata["injection.language"] = parts[#parts]
|
||||||
end
|
end
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _ string
|
---@param _ string
|
||||||
|
|
@ -173,10 +176,10 @@ query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred
|
||||||
end
|
end
|
||||||
local injection_alias = vim.treesitter.get_node_text(node, bufnr):lower()
|
local injection_alias = vim.treesitter.get_node_text(node, bufnr):lower()
|
||||||
metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
|
metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
-- Just avoid some annoying warnings for this directive
|
-- Just avoid some annoying warnings for this directive
|
||||||
query.add_directive("make-range!", function() end, true)
|
query.add_directive("make-range!", function() end, opts)
|
||||||
|
|
||||||
--- transform node text to lower case (e.g., to make @injection.language case insensitive)
|
--- transform node text to lower case (e.g., to make @injection.language case insensitive)
|
||||||
---
|
---
|
||||||
|
|
@ -197,7 +200,7 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
||||||
metadata[id] = {}
|
metadata[id] = {}
|
||||||
end
|
end
|
||||||
metadata[id].text = string.lower(text)
|
metadata[id].text = string.lower(text)
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
||||||
-- Trim blank lines from end of the region
|
-- Trim blank lines from end of the region
|
||||||
-- Arguments are the captures to trim.
|
-- Arguments are the captures to trim.
|
||||||
|
|
@ -235,4 +238,4 @@ query.add_directive("trim!", function(match, _, bufnr, pred, metadata)
|
||||||
metadata[id].range = { start_row, start_col, end_row, end_col }
|
metadata[id].range = { start_row, start_col, end_row, end_col }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, true)
|
end, opts)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue