aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2025-04-05 12:22:48 +0200
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commitcbfe8a20c76582b0f2532e94fbd7ea9c80f25455 (patch)
tree71353f2a474dafcb90bf0b9783e9c36d99d9a522
parentfix(install): skip tier 4 parsers when installing and updating (diff)
downloadnvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar.gz
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar.bz2
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar.lz
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar.xz
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.tar.zst
nvim-treesitter-cbfe8a20c76582b0f2532e94fbd7ea9c80f25455.zip
feat(html): use gsub for mimetype lookup
-rw-r--r--SUPPORTED_LANGUAGES.md1
-rw-r--r--lua/nvim-treesitter/parsers.lua2
-rw-r--r--plugin/filetypes.lua2
-rw-r--r--plugin/query_predicates.lua27
-rw-r--r--runtime/queries/html_tags/injections.scm30
-rw-r--r--tests/query/injections/html/test-html-injections.html6
6 files changed, 33 insertions, 35 deletions
diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md
index 8eac31b73..dbb2934bf 100644
--- a/SUPPORTED_LANGUAGES.md
+++ b/SUPPORTED_LANGUAGES.md
@@ -29,6 +29,7 @@ Language | Tier | Queries | Maintainer
[blade](https://github.com/EmranMR/tree-sitter-blade) | unstable | `HFIJ ` | @calebdw
[blueprint](https://gitlab.com/gabmus/tree-sitter-blueprint) | unstable | `H  J ` | @gabmus
[bp](https://github.com/ambroisie/tree-sitter-bp)[^bp] | unstable | `HFIJL` | @ambroisie
+[brightscript](https://github.com/ajdelcimmuto/tree-sitter-brightscript) | unstable | `HFIJ ` | @ajdelcimmuto
[c](https://github.com/tree-sitter/tree-sitter-c) | unstable | `HFIJL` | @amaanq
[c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) | unstable | `HF JL` | @amaanq
[caddy](https://github.com/opa-oz/tree-sitter-caddy) | unmaintained | `HFIJ ` | @opa-oz
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 263985ecf..01c78a63f 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -153,8 +153,8 @@ return {
},
brightscript = {
install_info = {
+ revision = '48ce1687125c6dfefcc7a1bef19fa0f0f00426cc',
url = 'https://github.com/ajdelcimmuto/tree-sitter-brightscript',
- files = { 'src/parser.c' },
},
maintainers = { '@ajdelcimmuto' },
tier = 2,
diff --git a/plugin/filetypes.lua b/plugin/filetypes.lua
index 82b2900ac..feb1194a6 100644
--- a/plugin/filetypes.lua
+++ b/plugin/filetypes.lua
@@ -22,7 +22,7 @@ local filetypes = {
haskell_persistent = { 'haskellpersistent' },
idris = { 'idris2' },
janet_simple = { 'janet' },
- javascript = { 'javascriptreact', 'ecma', 'jsx', 'js' },
+ javascript = { 'javascriptreact', 'ecma', 'ecmascript', 'jsx', 'js' },
javascript_glimmer = { 'javascript.glimmer' },
linkerscript = { 'ld' },
latex = { 'tex' },
diff --git a/plugin/query_predicates.lua b/plugin/query_predicates.lua
index 06bf957f8..1a500f591 100644
--- a/plugin/query_predicates.lua
+++ b/plugin/query_predicates.lua
@@ -39,30 +39,3 @@ end, { force = true })
query.add_predicate('any-kind-eq?', function(match, _, _, pred)
return predicates['kind-eq'](match, pred, true)
end, { force = true })
-
--- register custom directives
-
-local mimetype_aliases = {
- ['importmap'] = 'json',
- ['module'] = 'javascript',
- ['application/ecmascript'] = 'javascript',
- ['text/ecmascript'] = 'javascript',
-}
-
----@param match TSQueryMatch
----@param _ string
----@param bufnr integer
----@param pred string[]
----@return boolean|nil
-query.add_directive('set-lang-from-mimetype!', function(match, _, bufnr, pred, metadata)
- local id = pred[2]
- local node = match[id]
- 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
- else
- local parts = vim.split(type_attr_value, '/', {})
- metadata['injection.language'] = parts[#parts]
- end
-end, { force = true })
diff --git a/runtime/queries/html_tags/injections.scm b/runtime/queries/html_tags/injections.scm
index 5b78e37b4..1c8ce012b 100644
--- a/runtime/queries/html_tags/injections.scm
+++ b/runtime/queries/html_tags/injections.scm
@@ -32,16 +32,40 @@
(#not-lua-match? @_no_type_lang "%stype%s*=")
(#set! injection.language "javascript"))
-; <script type="mimetype-or-well-known-script-type">
+; <script type="foo/bar">
(script_element
(start_tag
(attribute
(attribute_name) @_attr
(#eq? @_attr "type")
(quoted_attribute_value
- (attribute_value) @_type)))
+ (attribute_value) @injection.language)))
(raw_text) @injection.content
- (#set-lang-from-mimetype! @_type))
+ (#gsub! @injection.language "(.+)/(.+)" "%2"))
+
+; <script type="importmap">
+((script_element
+ (start_tag
+ (attribute
+ (attribute_name) @_attr
+ (#eq? @_attr "type")
+ (quoted_attribute_value
+ (attribute_value) @_type)))
+ (raw_text) @injection.content)
+ (#eq? @_type "importmap")
+ (#set! injection.language "json"))
+
+; <script type="module">
+((script_element
+ (start_tag
+ (attribute
+ (attribute_name) @_attr
+ (#eq? @_attr "type")
+ (quoted_attribute_value
+ (attribute_value) @_type)))
+ (raw_text) @injection.content)
+ (#eq? @_type "module")
+ (#set! injection.language "javascript"))
; <a style="/* css */">
((attribute
diff --git a/tests/query/injections/html/test-html-injections.html b/tests/query/injections/html/test-html-injections.html
index 0df3bd420..8b08b3f38 100644
--- a/tests/query/injections/html/test-html-injections.html
+++ b/tests/query/injections/html/test-html-injections.html
@@ -19,6 +19,8 @@
<!-- ^ @javascript -->
<script async defer> const x = 1 </script>
<!-- ^ @javascript -->
+ <script type="module"> import { foo } from "bar" </script>
+ <!-- ^ @javascript -->
<script type="text/javascript"> const x = 1 </script>
<!-- ^ @javascript -->
<script type="text/ecmascript"> const x = 1 </script>
@@ -27,8 +29,6 @@
<!-- ^ @javascript -->
<script type="application/javascript"> const x = 1 </script>
<!-- ^ @javascript -->
- <script type="module"> import { foo } from "bar" </script>
- <!-- ^ @javascript -->
<script defer type="text/javascript"> const x = 1 </script>
<!-- ^ @javascript -->
<script type="text/markdown">## Hello *World*!</script>
@@ -40,7 +40,7 @@
<script type="application/json">{ "true": false }</script>
<!-- ^ @json -->
<script type="importmap">{ "true": false }</script>
- <!-- ^ @json -->
+ <!-- ^ @json -->
<div style="height: 100%">
<!-- ^ @css -->
Test div to test css injections for style attributes