@@ -27,6 +27,9 @@ import { INotificationService, Severity } from '../../../../platform/notificatio
27
27
import { localize } from '../../../../nls.js' ;
28
28
import { UiClientInstance } from '../../languageRuntime/common/languageRuntimeUiClient.js' ;
29
29
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js' ;
30
+ import { IConfigurationResolverService } from '../../configurationResolver/common/configurationResolver.js' ;
31
+ import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js' ;
32
+ import { NotebookSetting } from '../../../contrib/notebook/common/notebookCommon.js' ;
30
33
31
34
/**
32
35
* The maximum number of active sessions a user can have running at a time.
@@ -170,7 +173,9 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
170
173
@IExtensionService private readonly _extensionService : IExtensionService ,
171
174
@IStorageService private readonly _storageService : IStorageService ,
172
175
@IUpdateService private readonly _updateService : IUpdateService ,
173
- @IWorkbenchEnvironmentService private readonly _environmentService : IWorkbenchEnvironmentService
176
+ @IWorkbenchEnvironmentService private readonly _environmentService : IWorkbenchEnvironmentService ,
177
+ @IConfigurationResolverService private readonly _configurationResolverService : IConfigurationResolverService ,
178
+ @IWorkspaceContextService private readonly _workspaceContextService : IWorkspaceContextService
174
179
) {
175
180
176
181
super ( ) ;
@@ -387,6 +392,44 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
387
392
return Array . from ( this . _activeSessionsBySessionId . values ( ) ) ;
388
393
}
389
394
395
+ /**
396
+ * Resolves the working directory configuration with variable substitution.
397
+ *
398
+ * @param notebookUri The URI of the notebook, if any, for resource-scoped configuration
399
+ * @returns The resolved working directory or undefined if not configured
400
+ */
401
+ private async resolveWorkingDirectory ( notebookUri ?: URI ) : Promise < string | undefined > {
402
+ // Get the working directory configuration
403
+ const configValue = this . _configurationService . getValue < string > (
404
+ NotebookSetting . workingDirectory ,
405
+ notebookUri ? { resource : notebookUri } : { }
406
+ ) ;
407
+
408
+ // If no configuration value is set, return undefined
409
+ if ( ! configValue || configValue . trim ( ) === '' ) {
410
+ return undefined ;
411
+ }
412
+
413
+ // Get the workspace folder for variable resolution
414
+ const workspaceFolder = notebookUri
415
+ ? this . _workspaceContextService . getWorkspaceFolder ( notebookUri )
416
+ : this . _workspaceContextService . getWorkspace ( ) . folders [ 0 ] ;
417
+
418
+ try {
419
+ // Resolve variables in the configuration value
420
+ const resolvedValue = await this . _configurationResolverService . resolveAsync (
421
+ workspaceFolder || undefined ,
422
+ configValue
423
+ ) ;
424
+
425
+ return resolvedValue ;
426
+ } catch ( error ) {
427
+ // Log the error and return the original value as fallback
428
+ this . _logService . warn ( `Failed to resolve working directory variables in '${ configValue } ':` , error ) ;
429
+ return configValue ;
430
+ }
431
+ }
432
+
390
433
/**
391
434
* Select a session for the provided runtime.
392
435
*
@@ -466,6 +509,9 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
466
509
}
467
510
}
468
511
512
+ // Resolve the working directory configuration
513
+ const workingDirectory = await this . resolveWorkingDirectory ( notebookUri ) ;
514
+
469
515
// Wait for the selected runtime to start.
470
516
await this . startNewRuntimeSession (
471
517
runtime . runtimeId ,
@@ -474,7 +520,8 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
474
520
notebookUri ,
475
521
source ,
476
522
startMode ,
477
- true
523
+ true ,
524
+ workingDirectory
478
525
) ;
479
526
}
480
527
@@ -567,6 +614,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
567
614
* @param source The source of the request to start the runtime.
568
615
* @param startMode The mode in which to start the runtime.
569
616
* @param activate Whether to activate/focus the session after it is started.
617
+ * @param workingDirectory The working directory to use for the session, if any.
570
618
*/
571
619
async startNewRuntimeSession (
572
620
runtimeId : string ,
@@ -575,7 +623,8 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
575
623
notebookUri : URI | undefined ,
576
624
source : string ,
577
625
startMode = RuntimeStartMode . Starting ,
578
- activate : boolean ) : Promise < string > {
626
+ activate : boolean ,
627
+ workingDirectory ?: string ) : Promise < string > {
579
628
// See if we are already starting the requested session. If we
580
629
// are, return the promise that resolves when the session is ready to
581
630
// use. This makes it possible for multiple requests to start the same
@@ -611,7 +660,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
611
660
this . _logService . info (
612
661
`Starting session for language runtime ` +
613
662
`${ formatLanguageRuntimeMetadata ( languageRuntime ) } (Source: ${ source } )` ) ;
614
- return this . doCreateRuntimeSession ( languageRuntime , sessionName , sessionMode , source , startMode , activate , notebookUri ) ;
663
+ return this . doCreateRuntimeSession ( languageRuntime , sessionName , sessionMode , source , startMode , activate , notebookUri , workingDirectory ) ;
615
664
}
616
665
617
666
/**
@@ -1486,7 +1535,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1486
1535
}
1487
1536
}
1488
1537
1489
- return this . doCreateRuntimeSession ( metadata , metadata . runtimeName , sessionMode , source , RuntimeStartMode . Starting , activate , notebookUri ) ;
1538
+ return this . doCreateRuntimeSession ( metadata , metadata . runtimeName , sessionMode , source , RuntimeStartMode . Starting , activate , notebookUri , undefined ) ;
1490
1539
}
1491
1540
1492
1541
/**
@@ -1499,6 +1548,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1499
1548
* @param startMode The mode in which to start the runtime.
1500
1549
* @param activate Whether to activate/focus the session after it is started.
1501
1550
* @param notebookDocument The notebook document to attach to the session, if any.
1551
+ * @param workingDirectory The working directory to use for the session, if any.
1502
1552
*
1503
1553
* Returns a promise that resolves with the session ID when the runtime is
1504
1554
* ready to use.
@@ -1509,7 +1559,8 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1509
1559
source : string ,
1510
1560
startMode : RuntimeStartMode ,
1511
1561
activate : boolean ,
1512
- notebookUri ?: URI ) : Promise < string > {
1562
+ notebookUri ?: URI ,
1563
+ workingDirectory ?: string ) : Promise < string > {
1513
1564
this . setStartingSessionMaps ( sessionMode , runtimeMetadata , notebookUri ) ;
1514
1565
1515
1566
// Create a promise that resolves when the runtime is ready to use, if there isn't already one.
@@ -1539,6 +1590,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1539
1590
sessionId,
1540
1591
sessionMode,
1541
1592
notebookUri,
1593
+ workingDirectory,
1542
1594
createdTimestamp : Date . now ( ) ,
1543
1595
startReason : source
1544
1596
} ;
0 commit comments