I am trying to create some vs code snippets for aura and LWC so I created one snippet file for javascript now it works in both the languages but is there a way I can restrict JS and html snippets to LWC only or also can someone please confirm how to create snippets for .cmp and .app files to be used on aura HTML, below is my js snippet which works in all sorts of js files and I and trying to restrict it to just lwc
"Print to console": {
"scope": "javascript",
"prefix": "gss",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
Best Answer
This is a question better asked on Stack Overflow, but I'll include the essentials here.
First, you would need to create some new languages, something like
javascript-lwc
andjavascript-aura
. They will both be associated with*.js
files.Once you create your languages, which can just be extended from JavaScript, you then associate those languages using
files.associations
to restrict them by path:**/lwc/**/*.js
and**/aura/**/*.js
.After this, you'll be able to associate snippets to each language. Some additional setup might also be necessary, but this should get you started.
Obviously, you can also do this for Aura and LWC markup as well.