Skip to content

chore: add vscode highlight extension #228

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

Merged
merged 3 commits into from
Jun 13, 2021
Merged

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Jun 12, 2021

What do you think @lacolaco ?
I would love that you tried it out before I merge this in.
As far as I can see everything works except the emmet plugin, which I can take a look at later.
But it should be good enough for a MVP 🙂

It's already published in the marketplace as vscode-atl-render.

image

Closes #227

@lacolaco
Copy link
Contributor

It's happening so fast! I'll try it soon and give feedback.

@lacolaco
Copy link
Contributor

image

image

@lacolaco
Copy link
Contributor

image

@lacolaco
Copy link
Contributor

lacolaco commented Jun 13, 2021

  • Syntax Highlight as HTML: works!

Nice to Have (too much for MVP)

  • Formatting
  • Tag information on hover
  • Completion

},
"renderTemplate": {
"contentName": "text.html",
"begin": "\\G\\s*([`|'|\"])",
Copy link
Contributor

@lacolaco lacolaco Jun 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it disallows line breaks between render( and the arguments.

Note that the regular expressions are matched against only a single line of the document at a time. That means it is not possible to use a pattern that matches multiple lines. The reason for this is technical: being able to restart the parser at an arbitrary line and having to re-parse only the minimal number of lines affected by an edit. In most situations it is possible to use the begin/end model to overcome this limitation.

https://macromates.com/manual/en/language_grammars

How about just

([`|'|\"])

?

BTW, inline-template.ng also disallows line breaks.
image

Copy link
Contributor

@lacolaco lacolaco Jun 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\\G is "matching start position", so maybe it means \\G is the same line of render(.

@lacolaco
Copy link
Contributor

I've tried to fix the grammar.

  • simplify injectionSelector
  • add source.ts to patterns within renderMethod (fallback to the default TS grammar)
  • simplify delimiters for HTML string

image

{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "scopeName": "atl.render",
  "injectionSelector": "L:source.ts -comment",
  "name": "atl.render",
  "patterns": [
    {
      "include": "#renderMethod"
    }
  ],
  "repository": {
    "renderMethod": {
      "name": "renderMethod",
      "begin": "(?x)(\\b(?:\\w+\\.)*(?:render)\\s*)(\\()",
      "beginCaptures": {
        "1": {
          "name": "entity.name.function.ts"
        },
        "2": {
          "name": "meta.brace.round.ts"
        }
      },
      "end": "(\\))",
      "endCaptures": {
        "0": {
          "name": "meta.brace.round.ts"
        }
      },
      "patterns": [
        {
          "include": "#renderTemplate"
        },
        {
          "include": "source.ts"
        }
      ]
    },
    "renderTemplate": {
      "contentName": "text.html",
      "begin": "[`|'|\"]",
      "beginCaptures": {
        "0": {
          "name": "string"
        }
      },
      "end": "\\0",
      "endCaptures": {
        "0": {
          "name": "string"
        }
      },
      "patterns": [
        {
          "include": "text.html.derivative"
        },
        {
          "include": "template.ng"
        }
      ]
    }
  }
}

@timdeschryver
Copy link
Member Author

Thanks so much for the feedback! ♥
I'll try it out now and if publish the new version soonish!

@timdeschryver
Copy link
Member Author

@lacolaco there's a new version available with your fixes, thanks again!
About formatting and completion, I was hoping that this was somehow automatically handled...
But it seems like we'll have to write our own language service? I'm not sure if that would be worth it 😅

@lacolaco
Copy link
Contributor

lacolaco commented Jun 13, 2021

Syntax highlights seems perfect!
image

I think formatting and completion can be handled by our own TS plugin which communicates with language service. I found the lit-html extension, which includes its own TS plugin. The extension has formatting configuration and passing it to the plugin.

https://github.com/mjbvz/vscode-lit-html
https://github.com/microsoft/typescript-lit-html-plugin

@timdeschryver
Copy link
Member Author

Yea, I also using lit-html as an example 😅
I'm going to merge this one in already.

I will do some reading about it first and maybe in a couple of days/weeks play with it to see how easy or hard it's to support this feature.
If you want you can go ahead and try/start the plugin, if you don't want to that's also perfectly fine but please keep me updated so we don't do double work.

@timdeschryver timdeschryver changed the title feat: add vscode highlight extension chore: add vscode highlight extension Jun 13, 2021
@timdeschryver timdeschryver merged commit ba8fc76 into main Jun 13, 2021
@timdeschryver timdeschryver deleted the vscode-atl-render branch June 13, 2021 07:28
@github-actions
Copy link

🎉 This PR is included in version 10.8.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

render(template) syntax highlighting on IDE like vscode
2 participants