neovim configuration using rocks.nvim plugin manager

fix: add `set-lang-from-mimetype` for html

the following html code errors without this directive

<script type="module">

Signed-off-by: Seongmin Lee <git@boltless.me>

boltless.me 373ea279 99f28cc1

verified
Changed files
+29
+29
init.lua
··· 23 23 require("utils.format").setup() 24 24 25 25 require("utils").load_local_parser("norg", "norg") 26 + 27 + local query = require("vim.treesitter.query") 28 + local html_script_type_languages = { 29 + ["importmap"] = "json", 30 + ["module"] = "javascript", 31 + ["application/ecmascript"] = "javascript", 32 + ["text/ecmascript"] = "javascript", 33 + } 34 + 35 + ---@param match (TSNode|nil)[] 36 + ---@param _ string 37 + ---@param bufnr integer 38 + ---@param pred string[] 39 + ---@return boolean|nil 40 + query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, metadata) 41 + local capture_id = pred[2] 42 + local node = match[capture_id] 43 + if not node then 44 + return 45 + end 46 + local type_attr_value = vim.treesitter.get_node_text(node, bufnr) 47 + local configured = html_script_type_languages[type_attr_value] 48 + if configured then 49 + metadata["injection.language"] = configured 50 + else 51 + local parts = vim.split(type_attr_value, "/", {}) 52 + metadata["injection.language"] = parts[#parts] 53 + end 54 + end, { force = true, all = false })