1- import { QuickPickItem , WorkspaceConfiguration , DebugConfiguration , OutputChannel } from 'vscode' ;
1+ import { QuickPickItem , WorkspaceConfiguration , DebugConfiguration , OutputChannel , WorkspaceFolder , workspace } from 'vscode' ;
22import * as cp from 'child_process' ;
33import * as async from './novsc/async' ;
4+ import * as path from 'path' ;
5+ import * as os from 'os' ;
46import { Dict } from './novsc/commonTypes' ;
5- import { expandVariablesInObject } from './novsc/expand' ;
7+ import { expandVariables } from './novsc/expand' ;
68
79// Expands variable references of the form ${dbgconfig:name} in all properties of launch configuration.
810export function expandDbgConfig ( debugConfig : DebugConfiguration , dbgconfigConfig : WorkspaceConfiguration ) : DebugConfiguration {
@@ -27,12 +29,12 @@ export function expandDbgConfig(debugConfig: DebugConfiguration, dbgconfigConfig
2729 converged = true ;
2830 for ( let prop of Object . keys ( dbgconfig ) ) {
2931 expanding = prop ;
30- dbgconfig [ prop ] = expandVariablesInObject ( dbgconfig [ prop ] , expander ) ;
32+ dbgconfig [ prop ] = expandVariables ( dbgconfig [ prop ] , expander ) ;
3133 }
3234 } while ( ! converged ) ;
3335
3436 // Now expand dbgconfigs in the launch configuration.
35- debugConfig = expandVariablesInObject ( debugConfig , ( type , key ) => {
37+ debugConfig = expandVariables ( debugConfig , ( type , key ) => {
3638 if ( type == 'dbgconfig' ) {
3739 let value = dbgconfig [ key ] ;
3840 if ( value == undefined )
@@ -44,6 +46,30 @@ export function expandDbgConfig(debugConfig: DebugConfiguration, dbgconfigConfig
4446 return debugConfig ;
4547}
4648
49+ export function expandVSCodeVariables < T extends any > ( obj : T , folder ?: WorkspaceFolder ) : T {
50+ return expandVariables ( obj , ( type , key ) => {
51+ if ( type == null ) {
52+ if ( key == 'workspaceFolder' ) {
53+ return folder ? folder . uri . fsPath : '' ;
54+ } else if ( key == 'workspaceFolderBasename' ) {
55+ return folder ? path . basename ( folder . uri . fsPath ) : '' ;
56+ } else if ( key == 'userHome' ) {
57+ return os . homedir ( ) ;
58+ } else if ( key == 'pathSeparator' || key == '/' ) {
59+ return path . sep ;
60+ } else {
61+ return null ;
62+ }
63+ } else if ( type == 'env' ) {
64+ return process . env [ key ] ?? '' ;
65+ } else if ( type == 'config' ) {
66+ return workspace . getConfiguration ( undefined , folder ) . get < string > ( key ) ?? '' ;
67+ } else {
68+ return null ;
69+ }
70+ } ) ;
71+ }
72+
4773export function isEmpty ( obj : any ) : boolean {
4874 if ( obj === null || obj === undefined )
4975 return true ;
0 commit comments