Sebastian Nemeth
Sebastian Nemeth

Reputation: 6175

In VSCode snippets, how can I capitalize the value of another user-defined variable?

I'm in VSCode trying to make snippets and get my head around some of the new regex replacement syntax.

What I want to do is populate parts of my template based on the filename. I can strip the unwanted extensions okay, but I can't capitalize the same value in the next variable.

I have these two lines:

"@Controller('/${1:${TM_FILENAME_BASE/(.*)\\.controller/$1/}}')", "export class ${1/(.*)/${1:/capitalize}/}Controller {",

The first strips filename and captures the value as $1 for the template. In the second line, I'm trying to use the value from $1 and run it through the capitalize filter.

Nothing I've tried works, although bashing my head against the keyboard feels kind of nice.

Has anyone cracked this nut?

Upvotes: 3

Views: 3692

Answers (1)

Mark
Mark

Reputation: 182791

This works at least as of v1.25:

"@Controller('/${TM_FILENAME_BASE/(.*)\\.controller/$1/}')",
"export class ${TM_FILENAME_BASE/(.*)$/${1:/capitalize}/}Controller {",

yields:

@Controller('/myGlobalSnippets')
export class MyGlobalSnippetsController {

Upvotes: 12

Related Questions