Home > Blockchain >  what's wrong with this chained snippet for visual studio code?
what's wrong with this chained snippet for visual studio code?

Time:09-30

i am trying to make a snippet to declare bemit components so when i create a new one, i just have to write the prefix "new-bemit-component" and then for example with the file "_c-indice" _ for partial element, c- for component and then the name, the snippet would write:

/* ========================================================================================= */
/* COMPONENT - C INDICE */
/* ========================================================================================= */

.c-indice{
    
}

/* ========================================================================================= */
/* END COMPONENT - C INDICE */
/* ========================================================================================= */

I'd done that the snippet writes

/* ========================================================================================= / / COMPONENT - C indice / / ========================================================================================= */

.c-indice{

}

/* ========================================================================================= / / END COMPONENT - C indice / / ========================================================================================= */

using

"body": [
          "/* ========================================================================================= */",
          "/* COMPONENT - C ${TM_FILENAME_BASE/_c-//} */",
          "/* ========================================================================================= */",
          "",
          ".${TM_FILENAME_BASE/[\\\\_]//}{",
          "",
          "}",
          "",
          "/* ========================================================================================= */",
          "/* END COMPONENT - C ${TM_FILENAME_BASE/_c-//} */",
          "/* ========================================================================================= */"
        ],

but now i am trying to chain another regex so the result ends in upper-case, using this

"body": [
          "/* ========================================================================================= */",
          "/* COMPONENT - C ${TM_FILENAME_BASE/(_c-)(\\(?!_\\w\b)\b\\w )/${1:  }/g ${2:/capitalize/}} */",
          "/* ========================================================================================= */",
          "",
          ".${TM_FILENAME_BASE/[\\\\_]//}{",
          "",
          "}",
          "",
          "/* ========================================================================================= */",
          "/* END COMPONENT - C ${TM_FILENAME_BASE/_c-//} */",
          "/* ========================================================================================= */"
        ],

Just like they did here VSCode chaining regex transforms in a snippet

But must be there something wrong with the regex and i get this:

/* ========================================================================================= */
/* COMPONENT - C ${TM_FILENAME_BASE/(_c-)(\(?!_\w)\w )/  /g /capitalize/} */
/* ========================================================================================= */

.c-indice{

}

/* ========================================================================================= */
/* END COMPONENT - C indice */
/* ========================================================================================= */

I tested the regex with https://regex101.com

CodePudding user response:

You need to capture only the part after _c- and uppercase it:

${TM_FILENAME_BASE/_c-(.*)/${1:/upcase}/}

The _c- in the TM_FILENAME_BASE variable will be matched, and the rest will be captured into Group 1.

Then, all matched text will be replaced (once, no g flag) with the contents of Group 1 turned to upper case with upcase.

  • Related