From 78b54eb7f6a9956d25a3911fa0dfd0cabfe2a4c5 Mon Sep 17 00:00:00 2001 From: Pham Huy Hoang Date: Wed, 3 May 2023 19:07:59 +0900 Subject: chore(injections)!: update injection syntax to 0.9 Since 0.9, @lang syntax is still available as fallback but will soon be deprecated. Because of that, new syntax should be adopted once 0.9 becomes the baseline requirements for nvim-treesitter - update health check - update doc --- lua/nvim-treesitter/query_predicates.lua | 37 +++----------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua index ff0e9999a..7f2b73c54 100644 --- a/lua/nvim-treesitter/query_predicates.lua +++ b/lua/nvim-treesitter/query_predicates.lua @@ -153,10 +153,10 @@ query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, m local type_attr_value = vim.treesitter.get_node_text(node, bufnr) local configured = html_script_type_languages[type_attr_value] if configured then - metadata.language = configured + metadata["injection.language"] = configured else local parts = vim.split(type_attr_value, "/", {}) - metadata.language = parts[#parts] + metadata["injection.language"] = parts[#parts] end end, true) @@ -172,7 +172,7 @@ query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred return end local injection_alias = vim.treesitter.get_node_text(node, bufnr) - metadata.language = get_parser_from_markdown_info_string(injection_alias) + metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias) end, true) -- Just avoid some annoying warnings for this directive @@ -211,37 +211,6 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata) end end, true) ----@param match (TSNode|nil)[] ----@param _pattern string ----@param _bufnr integer ----@param pred string[] ----@param metadata table ----@return boolean|nil -query.add_directive("exclude_children!", function(match, _pattern, _bufnr, pred, metadata) - local capture_id = pred[2] - local node = match[capture_id] - local start_row, start_col, end_row, end_col = node:range() - local ranges = {} - for i = 0, node:named_child_count() - 1 do - local child = node:named_child(i) ---@type TSNode - local child_start_row, child_start_col, child_end_row, child_end_col = child:range() - if child_start_row > start_row or child_start_col > start_col then - table.insert(ranges, { - start_row, - start_col, - child_start_row, - child_start_col, - }) - end - start_row = child_end_row - start_col = child_end_col - end - if end_row > start_row or end_col > start_col then - table.insert(ranges, { start_row, start_col, end_row, end_col }) - end - metadata.content = ranges -end, true) - -- Trim blank lines from end of the region -- Arguments are the captures to trim. ---@param match (TSNode|nil)[] -- cgit v1.2.3-70-g09d2