@@ -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
*
@@ -1535,10 +1578,15 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1535
1578
}
1536
1579
1537
1580
const sessionId = this . generateNewSessionId ( runtimeMetadata , sessionMode === LanguageRuntimeSessionMode . Notebook ) ;
1581
+
1582
+ // Resolve the working directory configuration
1583
+ const workingDirectory = await this . resolveWorkingDirectory ( notebookUri ) ;
1584
+
1538
1585
const sessionMetadata : IRuntimeSessionMetadata = {
1539
1586
sessionId,
1540
1587
sessionMode,
1541
1588
notebookUri,
1589
+ workingDirectory,
1542
1590
createdTimestamp : Date . now ( ) ,
1543
1591
startReason : source
1544
1592
} ;
@@ -1645,7 +1693,7 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
1645
1693
* @param runtime The runtime to get the manager for.
1646
1694
* @returns The session manager that manages the runtime.
1647
1695
*
1648
- * Throws an errror if no session manager is found for the runtime.
1696
+ * Throws an error if no session manager is found for the runtime.
1649
1697
*/
1650
1698
private async getManagerForRuntime ( runtime : ILanguageRuntimeMetadata ) : Promise < ILanguageRuntimeSessionManager > {
1651
1699
// Look for the session manager that manages the runtime.
0 commit comments