microsoft / vscode-html-languageservice

Language services for HTML
MIT License
229 stars 110 forks source link

Add support for template literal escaped attributes #148

Closed Matsuuu closed 1 year ago

Matsuuu commented 1 year ago

Heya,

I'm utilizing this language service together with the template decorator to provide custom element completions.

I however noticed that the scanner provided by languageService.createScanner(document.getText()); breaks when the html document has javascript escaped content inside the template literal.

e.g.

import { html } from "lit-html";

export const temp = html`

    <example-project 
        @my-custom-event=${() => console.log("foo")}
        pro
    ></example-project>
`

The scanner isn't analyzing the document like normal due to the line

  @my-custom-event=${() => {}}

and specially due to the dollar sign escaping of this template literal.

When that line of code is added, the scanner only hits one token and that token is TokenType.EOS.

I'm not sure if it would be in the scope of this project but being able to support escaped js in template literals would ease the adoption of the scanner in my custom elements language server project.

If this is out of scope however, I might end up forking this scanner and expanding it. Unless there is already a fork implementing this somewhere.

Happy to provide extra info if needed

Matsuuu commented 1 year ago

So it seems that my problem was in the way I was handling my Context, not in the language server scanner itself. Closing this