From cbfe8a20c76582b0f2532e94fbd7ea9c80f25455 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 5 Apr 2025 12:22:48 +0200 Subject: feat(html): use gsub for mimetype lookup --- SUPPORTED_LANGUAGES.md | 1 + lua/nvim-treesitter/parsers.lua | 2 +- plugin/filetypes.lua | 2 +- plugin/query_predicates.lua | 27 ------------------- runtime/queries/html_tags/injections.scm | 30 +++++++++++++++++++--- .../injections/html/test-html-injections.html | 6 ++--- 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")) -; + + @@ -27,8 +29,6 @@ - - @@ -40,7 +40,7 @@ - +
Test div to test css injections for style attributes -- cgit v1.2.3-70-g09d2