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

Feature Request: vtl tag #9

Open
andrestone opened this issue Aug 26, 2020 · 3 comments
Open

Feature Request: vtl tag #9

andrestone opened this issue Aug 26, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@andrestone
Copy link

andrestone commented Aug 26, 2020

Hi!

It would be nice to be able to get the same code completion and syntax highlighting using a vtl tag on a template string like so:

// ts / js
const resolver = vtl`
#if($ctx.args.id)
  "true"
#else 
  "false"
#end
`;

I know this extension is for code completion only, but I'm assuming it uses the "velocity" language token / reference from another extension to be activated. Is it true?

I'm wondering what minimal work could be done in order to "enable" the language inside the string literal so both extensions would work.

Cheers!

EDIT:

How feasible is this?

package.json

    "contributions": {
      ...
      "grammar" : {
        "injectTo": [
          "source.js",
          "source.ts",
        ],
        "scopeName": "inline.velocity",
        "path": "./syntaxes/velocity.inline.json",
        "embeddedLanguages": {
          "meta.embedded.block.velocity": "velocity"
        }
      }
      ...

// syntaxes/velocity.inline.json

{
  "fileTypes": ["js", "ts"],
  "injectionSelector": "L:source -string -comment",
  "patterns": [
    {
      "name": "taggedTemplates",
      "contentName": "meta.embedded.block.velocity",
      "begin": "(`)(velocity|vtl)",
      "beginCaptures": {
        "1": {
          "name": "punctuation.definition.string.template.begin.js"
        },
        "2": {
          "name": "comment.line.velocity.js"
        }
      },
      "end": "`",
      "endCaptures": {
        "0": {
          "name": "punctuation.definition.string.template.end.js"
        }
      },
      "patterns": [
        { "include": "source.velocity" }
      ]
    }
  ],
  "scopeName": "inline.velocity"
}
@theBenForce
Copy link
Owner

@andrestone Thanks for suggesting this, and providing details on how to implement it. I'll take a look and get an update pushed out ASAP.

@andrestone
Copy link
Author

It's working here, but it depends on the name of the scope of the language extension.

For the one by "sodatea":

"embeddedLanguages": {
						"text.velocity": "velocity"
				}

I can open the PR if you confirm this is the extension you use.

One thing I couldn't fix is the autocompletion support (only the syntax is working). There's a related open issue: microsoft/vscode#98621

@theBenForce
Copy link
Owner

I use the extension by quidgest. If you create a PR I'll verify that it works with that extension too.

Thanks again for all the work!

@theBenForce theBenForce self-assigned this Dec 22, 2020
@theBenForce theBenForce added enhancement New feature or request good first issue Good for newcomers labels Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants