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
Snippet transforms do not handle regex with alternatives or optional matches #36089
Comments
I was looking how to change from |
Yeah, there is something off. It should be |
I used the Actually i tried |
Yeah, |
Let me know if I can help in some way. I haven't looked at the code at all, but I'm willing to help out. Thx |
I'm trying to do something similar with CapitalCase filename -> kebab-case. I have I tried wrapping it with another variable but get an Invalid Arguments warning.
and this result:
I'm not sure if I've just read the capability of this wrong, or if something is missing in VS Code. |
@dogoku I have pushed changes to make the format string smarter (that means not explode when having no match). You can now use this pattern: @ashclarke You need to apply the /downcase function on the match, so |
Thanks @jrieken - I will check it out! |
Thanks @jrieken, is this patch available in Insider's build? |
Yeah, should be available with todays insiders build |
@jrieken Sorry to do this again, but I found another bug :( In the latest insiders build (v1.18.0-86e057cd), transforms are working for optional matches, however not all the transforms are applied if you reused the same variable (e.g $1) in other parts of the snippet. Given the following simplified example: //TM_FILENAME_BASE: `my-awesome-module`
[
"function ${1:${TM_FILENAME_BASE/^(.)|-(.)/${1:/upcase}${2:/upcase}/gm}} () {}",
"module.exports = $1;"
]
//Expected
function MyAwesomeModule () {}
module.exports = MyAwesomeModule;
//Actual
function MyAwesomeModule () {}
module.exports = My-awesome-module; In case you missed it, the second use of $1 was not transformed properly, having only the first transform applied to it Should I open a new ticket for this? |
I noticed this too, before, but it isn’t limited to the insiders build. I noticed it happen in the
latest stable release.
|
Nothing to be sorry about except for not filing a new issue. |
Snippet transform functions (/upcase, /downcase, /capitalize) do not apply to optional capture groups, such as in case of a regex with alternatives, e.g. the regex in the example below (explanation). Instead the matches get replaced by the literal strings (i.e the string "/upcase").
I had a look at the grammar and it seems that the EBNF does not specify what
if
andelse
mean for theformat
rule, so I guess the implementation is not technically "wrong". But given that your intention for this feature is to be compatible with TM and ST snippets, then I see this as a bug, since this is possible in ST (albeit with a different format syntax).Steps to Reproduce:
my-awesome-module.js
hclass
and expand the snippetExpected result:
MyAwesomeModule
Actual result:
/upcasey/upcasewesome/upcaseodule
The text was updated successfully, but these errors were encountered: