aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-24 14:33:45 +0200
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commitf13420ccff1dfca4a2e42c43f56f66b240dd1d2e (patch)
treefa402b473e4665f9529bf30e90d2293fd0e3cfcf
parentfix: always normalize paths (diff)
downloadnvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar.gz
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar.bz2
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar.lz
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar.xz
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.tar.zst
nvim-treesitter-f13420ccff1dfca4a2e42c43f56f66b240dd1d2e.zip
fix: remove upstreamed directives
`#inject-lang!` and `#trim!`; fix `set-lang-from-mimetype`
-rw-r--r--plugin/query_predicates.lua102
-rw-r--r--runtime/queries/authzed/injections.scm24
-rw-r--r--runtime/queries/hcl/injections.scm3
-rw-r--r--runtime/queries/hurl/injections.scm3
-rw-r--r--runtime/queries/markdown/injections.scm5
-rw-r--r--runtime/queries/php_only/injections.scm6
-rw-r--r--runtime/queries/ruby/injections.scm3
7 files changed, 11 insertions, 135 deletions
diff --git a/plugin/query_predicates.lua b/plugin/query_predicates.lua
index 8c7685faf..7cd8fb618 100644
--- a/plugin/query_predicates.lua
+++ b/plugin/query_predicates.lua
@@ -30,12 +30,13 @@ local mimetype_aliases = {
---@param pred string[]
---@return boolean|nil
query.add_directive('set-lang-from-mimetype!', function(match, _, bufnr, pred, metadata)
- local capture_id = pred[2]
- local node = match[capture_id]
+ local id = pred[2]
+ local node = match[id]
if not node then
return
end
- local type_attr_value = vim.treesitter.get_node_text(node, bufnr)
+
+ local type_attr_value = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] })
local configured = mimetype_aliases[type_attr_value]
if configured then
metadata['injection.language'] = configured
@@ -44,98 +45,3 @@ query.add_directive('set-lang-from-mimetype!', function(match, _, bufnr, pred, m
metadata['injection.language'] = parts[#parts]
end
end, true)
-
-local injection_aliases = {
- ex = 'elixir',
- pl = 'perl',
- sh = 'bash',
- uxn = 'uxntal',
- ts = 'typescript',
-}
-
----@param match (TSNode|nil)[]
----@param _ string
----@param bufnr integer
----@param pred string[]
----@return boolean|nil
-query.add_directive('set-lang-from-info-string!', function(match, _, bufnr, pred, metadata)
- local capture_id = pred[2]
- local node = match[capture_id]
- if not node then
- return
- end
-
- local injection_alias = vim.treesitter.get_node_text(node, bufnr)
- local filetype = vim.filetype.match({ filename = 'a.' .. injection_alias })
- metadata['injection.language'] = filetype or injection_aliases[injection_alias] or injection_alias
-end, true)
-
-query.add_directive('downcase!', function(match, _, bufnr, pred, metadata)
- local text, key, value ---@type string|string[], string, string|integer
-
- if #pred == 3 then
- -- (#downcase! @capture "key")
- key = pred[3]
- value = metadata[pred[2]][key]
- else
- -- (#downcase! "key")
- key = pred[2]
- value = metadata[key]
- end
-
- if type(value) == 'string' then
- text = value
- else
- local node = match[value]
- text = vim.treesitter.get_node_text(node, bufnr) or ''
- end
-
- if #pred == 3 then
- metadata[pred[2]][key] = string.lower(text)
- else
- metadata[key] = string.lower(text)
- end
-end, true)
-
--- Trim blank lines from end of the region
--- Arguments are the captures to trim.
----@param match (TSNode|nil)[]
----@param _ string
----@param bufnr integer
----@param pred string[]
----@param metadata table
----TODO(clason): upstream
-query.add_directive('trim!', function(match, _, bufnr, pred, metadata)
- for _, id in ipairs({ select(2, unpack(pred)) }) do
- local node = match[id]
- if not node then
- return
- end
-
- local start_row, start_col, end_row, end_col = node:range()
-
- -- Don't trim if region ends in middle of a line
- if end_col ~= 0 then
- return
- end
-
- while true do
- -- As we only care when end_col == 0, always inspect one line above end_row.
- local end_line = vim.api.nvim_buf_get_lines(bufnr, end_row - 1, end_row, true)[1]
-
- if end_line ~= '' then
- break
- end
-
- end_row = end_row - 1
- end
-
- -- If this produces an invalid range, we just skip it.
- if start_row < end_row or (start_row == end_row and start_col <= end_col) then
- if not metadata[id] then
- metadata[id] = {}
- end
- metadata[id].range = { start_row, start_col, end_row, end_col }
- end
- end
-end, true)
diff --git a/runtime/queries/authzed/injections.scm b/runtime/queries/authzed/injections.scm
index 298a8d070..2f0e58eb6 100644
--- a/runtime/queries/authzed/injections.scm
+++ b/runtime/queries/authzed/injections.scm
@@ -1,26 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))
-
-((function_call
- name: (ident) @_name
- .
- (simplexpr)
- .
- (simplexpr
- (string
- (string_fragment) @injection.content)+))
- (#any-of? @_name "replace" "search" "matches" "captures")
- (#set! injection.language "regex")
- (#set! injection.combined))
-
-((function_call
- name: (ident) @_name
- .
- (simplexpr)
- .
- (simplexpr
- (string
- (string_fragment) @injection.content)+))
- (#eq? @_name "jq")
- (#set! injection.language "jq")
- (#set! injection.combined))
diff --git a/runtime/queries/hcl/injections.scm b/runtime/queries/hcl/injections.scm
index b68f4caea..5cb940c87 100644
--- a/runtime/queries/hcl/injections.scm
+++ b/runtime/queries/hcl/injections.scm
@@ -3,5 +3,4 @@
(heredoc_template
(template_literal) @injection.content
- (heredoc_identifier) @injection.language
- (#downcase! @injection.language))
+ (heredoc_identifier) @injection.language)
diff --git a/runtime/queries/hurl/injections.scm b/runtime/queries/hurl/injections.scm
index 41abb387b..bd5385663 100644
--- a/runtime/queries/hurl/injections.scm
+++ b/runtime/queries/hurl/injections.scm
@@ -9,7 +9,6 @@
(#set! injection.language "xml"))
(multiline_string
- (multiline_string_type) @_lang
+ (multiline_string_type) @injection.language
(multiline_string_content) @injection.content
- (#set-lang-from-info-string! @_lang)
(#set! injection.combined))
diff --git a/runtime/queries/markdown/injections.scm b/runtime/queries/markdown/injections.scm
index 8ed205296..1f33c30b6 100644
--- a/runtime/queries/markdown/injections.scm
+++ b/runtime/queries/markdown/injections.scm
@@ -1,8 +1,7 @@
(fenced_code_block
(info_string
- (language) @_lang)
- (code_fence_content) @injection.content
- (#set-lang-from-info-string! @_lang))
+ (language) @injection.language)
+ (code_fence_content) @injection.content)
((html_block) @injection.content
(#set! injection.language "html")
diff --git a/runtime/queries/php_only/injections.scm b/runtime/queries/php_only/injections.scm
index 368177643..42ee2d67d 100644
--- a/runtime/queries/php_only/injections.scm
+++ b/runtime/queries/php_only/injections.scm
@@ -4,14 +4,12 @@
(heredoc
(heredoc_body) @injection.content
(heredoc_end) @injection.language
- (#set! injection.include-children)
- (#downcase! @injection.language))
+ (#set! injection.include-children))
(nowdoc
(nowdoc_body) @injection.content
(heredoc_end) @injection.language
- (#set! injection.include-children)
- (#downcase! @injection.language))
+ (#set! injection.include-children))
; regex
((function_call_expression
diff --git a/runtime/queries/ruby/injections.scm b/runtime/queries/ruby/injections.scm
index 12b2c32a5..e998e2bd7 100644
--- a/runtime/queries/ruby/injections.scm
+++ b/runtime/queries/ruby/injections.scm
@@ -3,8 +3,7 @@
(heredoc_body
(heredoc_content) @injection.content
- (heredoc_end) @injection.language
- (#downcase! @injection.language))
+ (heredoc_end) @injection.language)
(regex
(string_content) @injection.content