guillaumebrunerie / ultimate-js-mode

An major mode for working with JS/JSX/TS/TSX files in Emacs
4 stars 0 forks source link

Support for named template strings #2

Open ispringle opened 1 day ago

ispringle commented 1 day ago

Some frameworks, like lit, use template strings to define HTML and CSS. For example:

const element = html`<div class="foo">This is my new custom element!</div>`

Wondering what it would take to add support for that to this mode. Neovim is using treesitter to pull this off, they do it with the following query:

(call_expression
  function: (identifier) @injection.language
  arguments: [
    (arguments
      (template_string) @injection.content)
    (template_string) @injection.content
  ])

I've tested this in the treesitter playground and it highlights the correct portion of the above JS example. I'm not sure how to turn that query into its own set of nested highlighting though or else I'd make a PR

guillaumebrunerie commented 1 day ago

Hey! I'd love to have that as well (I use styled components in React a lot myself, and it would be great to have CSS syntax highlighting there), but I think that the last time I investigated it, my conclusion was that Emacs has no support whatsoever for injection queries. I might be wrong, or it might have changed, maybe I'll try again to make it work.