Skip to content

Commit 846a873

Browse files
authored
allow custom environment variables to be set when launching a kernel (#2208)
This also fixes a longstanding issue where we weren't properly refreshing the kernelLaunchArguments.
1 parent e1dee7b commit 846a873

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

src/dotnet-interactive-vscode-ads/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
],
114114
"description": "Command and arguments used to start a notebook session."
115115
},
116+
"dotnet-interactive.kernelEnvironmentVariables": {
117+
"type": "object",
118+
"default": {},
119+
"description": "Environment variables to set when starting a notebook session."
120+
},
116121
"dotnet-interactive.notebookParserArgs": {
117122
"type": "array",
118123
"default": [
@@ -529,4 +534,4 @@
529534
"uuid": "8.3.2",
530535
"rxjs": "7.5.6"
531536
}
532-
}
537+
}

src/dotnet-interactive-vscode-common/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext) {
100100
}
101101

102102
async function kernelChannelCreator(notebookUri: vscodeLike.Uri): Promise<KernelCommandAndEventChannel> {
103+
const config = vscode.workspace.getConfiguration('dotnet-interactive');
103104
const launchOptions = await getInteractiveLaunchOptions();
104105
if (!launchOptions) {
105106
throw new Error(`Unable to get interactive launch options. Please see the '${diagnosticsChannel.getName()}' output window for details.`);
@@ -120,7 +121,8 @@ export async function activate(context: vscode.ExtensionContext) {
120121

121122
const workspaceFolderUris = vscode.workspace.workspaceFolders?.map(folder => folder.uri) || [];
122123
const workingDirectory = getWorkingDirectoryForNotebook(notebookUri, workspaceFolderUris, fallbackWorkingDirectory);
123-
const processStart = processArguments(argsTemplate, workingDirectory, DotNetPathManager.getDotNetPath(), launchOptions!.workingDirectory);
124+
const environmentVariables = config.get<{ [key: string]: string }>('kernelEnvironmentVariables');
125+
const processStart = processArguments(argsTemplate, workingDirectory, DotNetPathManager.getDotNetPath(), launchOptions!.workingDirectory, environmentVariables);
124126
let notification = {
125127
displayError: async (message: string) => { await vscode.window.showErrorMessage(message, { modal: false }); },
126128
displayInfo: async (message: string) => { await vscode.window.showInformationMessage(message, { modal: false }); },

src/dotnet-interactive-vscode-common/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ProcessStart {
99
command: string;
1010
args: Array<string>;
1111
workingDirectory: string;
12+
env: { [key: string]: string };
1213
}
1314

1415
// interactive acquisition

src/dotnet-interactive-vscode-common/src/stdioDotnetInteractiveChannel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class StdioDotnetInteractiveChannel implements DotnetInteractiveChannel {
6666
let args = processStart.args;
6767
// launch the process
6868
this.diagnosticChannel.appendLine(`Starting kernel for '${notebookPath}' using: ${processStart.command} ${args.join(' ')}`);
69-
let childProcess = cp.spawn(processStart.command, args, { cwd: processStart.workingDirectory });
69+
let childProcess = cp.spawn(processStart.command, args, { cwd: processStart.workingDirectory, env: processStart.env });
7070
let pid = childProcess.pid;
7171

7272
this.childProcess = childProcess;

src/dotnet-interactive-vscode-common/src/utilities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function getDotNetVersionOrThrow(dotnetPath: string, outputChannel:
8989
return dotnetVersion;
9090
}
9191

92-
export function processArguments(template: { args: Array<string>, workingDirectory: string }, workingDirectory: string, dotnetPath: string, globalStoragePath: string): ProcessStart {
92+
export function processArguments(template: { args: Array<string>, workingDirectory: string }, workingDirectory: string, dotnetPath: string, globalStoragePath: string, env?: { [key: string]: string }): ProcessStart {
9393
let map: { [key: string]: string } = {
9494
'dotnet_path': dotnetPath,
9595
'global_storage_path': globalStoragePath,
@@ -100,7 +100,8 @@ export function processArguments(template: { args: Array<string>, workingDirecto
100100
return {
101101
command: processed[0],
102102
args: [...processed.slice(1)],
103-
workingDirectory: performReplacement(template.workingDirectory, map)
103+
workingDirectory: performReplacement(template.workingDirectory, map),
104+
env: env || {},
104105
};
105106
}
106107

src/dotnet-interactive-vscode-common/tests/misc.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ describe('Miscellaneous tests', () => {
9191
'--working-dir',
9292
'replacement-working-dir'
9393
],
94-
workingDirectory: 'replacement-global-storage-path'
94+
workingDirectory: 'replacement-global-storage-path',
95+
env: {}
9596
});
9697
});
9798

src/dotnet-interactive-vscode-insiders/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
],
125125
"description": "Command and arguments used to start a notebook session."
126126
},
127+
"dotnet-interactive.kernelEnvironmentVariables": {
128+
"type": "object",
129+
"default": {},
130+
"description": "Environment variables to set when starting a notebook session."
131+
},
127132
"dotnet-interactive.notebookParserArgs": {
128133
"type": "array",
129134
"default": [
@@ -552,4 +557,4 @@
552557
"uuid": "8.3.2",
553558
"rxjs": "7.5.6"
554559
}
555-
}
560+
}

src/dotnet-interactive-vscode/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
],
125125
"description": "Command and arguments used to start a notebook session."
126126
},
127+
"dotnet-interactive.kernelEnvironmentVariables": {
128+
"type": "object",
129+
"default": {},
130+
"description": "Environment variables to set when starting a notebook session."
131+
},
127132
"dotnet-interactive.notebookParserArgs": {
128133
"type": "array",
129134
"default": [
@@ -552,4 +557,4 @@
552557
"uuid": "8.3.2",
553558
"rxjs": "7.5.6"
554559
}
555-
}
560+
}

0 commit comments

Comments
 (0)