Closed MoYuM closed 3 years ago
Oh. Those templates were not available at the time I was referring to that syntax in README. Some of them seem to work, but not all of them. Since it's not a classic VS Code snippet it won't work correctly. To get the result you are expecting you could use this:
{
"name": "test",
"body": "{{expr}}.test",
"description": "test",
"when": []
}
If that's not enough try explaining the exact thing you're trying to achieve.
I want to make a template to write useState
in React, such like this
{
"name": "useState",
"body": "const [{{expr}}, set{{expr}}] = React.useState();",
"description": "useState",
"when": []
}
but i can not transform the first letter of {{expr}}
to uppercase
the result is not good enough
const [count, setcount] = React.useState();
how can i make setcount
to setCount
?
Oh. I see. How was TM_CURRENT_LINE
supposed to help here? Even if it worked correctly it would still have the same case.
I do have an idea though and it's not that difficult to implement.
One could just use {{expr:lower}}
, {{expr:upper}}
, {{expr:title}}
so kind of filters for the replacement to give more flexibility.
TM_CURRENT_LINE
will help me to get the code before dot.
like {{expr}}
, but {{expr}}
do not support variable-transforms which TM_CURRENT_LINE
can.
then i can use regex to replace the first letter to uppercase, like docs say.
but your filters is much better way to do such stuff.
if you can support it , it will help a lot.
Ok, those transforms are pretty cool. TM_FILENAME works well even with the transforms but TM_CURRENT_LINE doesn't want to. I guess it's because it's not a regular snippet. This is code based completion which partially supports snippets syntax but apparently not everything works yet. As a workaround I can try with those filters I mentioned before. That will do the job for now. Maybe those snippets will start working one day, but I don't have time to deep dive into that now.
OK, thank you for your reply and your work of this stuff. it is very useful
Just released v1.9.4. Here is your template working:
{
"name": "useState",
"body": "const [{{expr}}, set{{expr:capitalize}}] = React.useState();",
"description": "const [{{expr}}, set{{expr:capitalize}}] = React.useState();",
"when": []
},
Thank you !
I want to get current line code by TM_CURRENT_LINE, but i get a wrong value
write a custom template like thie:
result is
it should be