@@ -27,6 +27,7 @@ function readConfig(setConfig, turnMessagesOff, contextAbsolutePath) {
2727 args . push ( ...readModels ( ) ) ;
2828 args . push ( ...readCustomArgs ( ) ) ;
2929 args . push ( ...readFiles ( ) ) ;
30+ args . push ( ...readConstants ( ) ) ;
3031
3132 if ( ! turnMessagesOff ) {
3233 vscode . window . showInformationMessage (
@@ -42,6 +43,14 @@ function readConfig(setConfig, turnMessagesOff, contextAbsolutePath) {
4243 return args ;
4344}
4445
46+ function readConstants ( ) {
47+ if ( jsonConfig . args . constants != undefined ) {
48+ return jsonConfig . args . constants . map ( ( constant ) => `--const ${ constant } ` ) ;
49+ } else {
50+ return [ ] ;
51+ }
52+ }
53+
4554/**
4655 * @param {string } contextAbsolutePath
4756 * @param {string } pathToConfig
@@ -127,8 +136,30 @@ function readModels() {
127136
128137function readCustomArgs ( ) {
129138 if ( jsonConfig . args . customArgs != undefined ) {
130- return jsonConfig . args . customArgs . split ( " " ) ;
139+ const str = jsonConfig . args . customArgs ;
140+ // split custom args into seperate tokens
141+ const tokens = str . match ( / (?: [ ^ \s " ] + | " [ ^ " ] * " ) + / g) || [ ] ;
142+ const result = [ ] ;
143+ // process tokens as possible pairs
144+ for ( let i = 0 ; i < tokens . length ; i ++ ) {
145+ let token = tokens [ i ] ;
146+ if ( token . startsWith ( "-" ) && i + 1 < tokens . length ) {
147+ if ( tokens [ i + 1 ] . startsWith ( "-" ) ) {
148+ // next token is another flag, so current token is standalone
149+ result . push ( token ) ;
150+ continue ;
151+ }
152+ let next = tokens [ i + 1 ] ;
153+ result . push ( `${ token } ${ next } ` ) ;
154+ i ++ ;
155+ } else {
156+ // no possible pair remaining
157+ result . push ( token ) ;
158+ }
159+ }
160+ return result ;
131161 } else {
162+ // no custom args
132163 return [ ] ;
133164 }
134165}
0 commit comments