ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
159 stars 43 forks source link

TM_CURRENT_LINE can not get correct value #45

Closed MoYuM closed 3 years ago

MoYuM commented 3 years ago

I want to get current line code by TM_CURRENT_LINE, but i get a wrong value

  1. write a custom template like thie:

    {
            "name": "test",
            "body": "${TM_CURRENT_LINE}",
            "description": "test",
            "when": []
    }
    1. use this template with this code
      someCode.test
  2. result is

    test
  3. it should be

    someCode.test
ipatalas commented 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.

MoYuM commented 3 years ago

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?

ipatalas commented 3 years ago

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.

MoYuM commented 3 years ago

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.

ipatalas commented 3 years ago

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.

MoYuM commented 3 years ago

OK, thank you for your reply and your work of this stuff. it is very useful

ipatalas commented 3 years ago

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": []
},
MoYuM commented 3 years ago

Thank you !