Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing generic type parameters to html function? #96

Open
karlhorky opened this issue Apr 2, 2022 · 3 comments
Open

Support passing generic type parameters to html function? #96

karlhorky opened this issue Apr 2, 2022 · 3 comments

Comments

@karlhorky
Copy link

Hi @mjbvz, first of all, thanks for your effort creating this extension, very useful!

I wanted to find out if you'd be open to supporting passing TypeScript generic type parameters to the html function? Eg. both of:

  1. Single-line generic type parameters
  2. Multi-line generic type parameters

The extension currently doesn't highlight with either of these:

Screen Shot 2022-04-02 at 16 11 43

Code:

const withHighlight = html`<div></div>`;
const noHighlight = html<string>` <div></div> `;
const alsoNoHighlight = html<
  // longer generic type parameter
  ButtonHTMLAttributes<HTMLButtonElement>
>` <div></div> `;
@mjbvz
Copy link
Owner

mjbvz commented Apr 4, 2022

I'm open to it (if someone makes a PR :)

@karlhorky
Copy link
Author

karlhorky commented Nov 19, 2023

Looking at similar issues across other extensions, one problem with the example above is that the longer generic type argument spans multiple lines.

The root cause for this is a bit more of a problem, since TextMate grammars have limitations, as @sheetalkamat is familiar with:

VS Code itself somehow gets around the limitations and can do correct syntax highlighting over multiple lines, maybe with Semantic Highlighting by @aeschli and @alexdima.

I also see some changes with regular expressions, which @sheetalkamat has also been maintaining:

So maybe there is a way for a VS Code extension to also achieve this, by also using this Semantic Highlighting / these regular expressions.

The TextMate grammar limitations have also been explored in the following SQL tagged template literals VS Code extension, but no solution has yet appeared:

@karlhorky
Copy link
Author

Workaround (/* html */ comment)

Add a /* html */ comment after the multi-line generic

const alsoNoHighlight = html<
  // longer generic type parameter
  ButtonHTMLAttributes<HTMLButtonElement>
->` <div></div> `;
+>/* html */ ` <div></div> `;

Credit: @net in thebearingedge/vscode-sql-lit#13 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants