Skip to content

Commit 148f6af

Browse files
V119-052: pass custom env variables to the ALS
Use the already existing VS Code preferences to control the environment variables and pass them to all the child processes launched by the extension, including the ALS. This allows to set a custom PATH or GPR_PROJECT_PATH in a workspace file for a given project for instance, or control the scenario variables directly from the environment.
1 parent 8ff5864 commit 148f6af

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

integration/vscode/ada/src/extension.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import {
2222
LanguageClientOptions,
2323
Middleware,
2424
ServerOptions,
25+
ExecutableOptions
2526
} from 'vscode-languageclient/node';
27+
import { platform } from 'os';
2628
import * as process from 'process';
2729
import GPRTaskProvider from './gprTaskProvider';
2830
import cleanTaskProvider from './cleanTaskProvider';
@@ -91,10 +93,34 @@ export function activate(context: vscode.ExtensionContext): void {
9193
// let debugOptions = { execArgv: [] };
9294
// If the extension is launched in debug mode then the debug server options are used
9395
// Otherwise the run options are used
96+
97+
// Retrieve the user's custom environment variables if specified in their
98+
// settings/workspace: we'll then launch any child process with this custom
99+
// environment
100+
var user_platform = platform();
101+
var env_config_name: string = "terminal.integrated.env.linux";
102+
103+
switch (user_platform) {
104+
case 'darwin': env_config_name = "terminal.integrated.env.osx"
105+
break;
106+
case 'win32': env_config_name = "terminal.integrated.env.windows";
107+
break;
108+
default: env_config_name = "terminal.integrated.env.linux";
109+
}
110+
111+
const custom_env = vscode.workspace.getConfiguration().get(
112+
env_config_name) ?? Object.create(null)
113+
114+
for (let var_name in custom_env) {
115+
process.env[var_name] = custom_env[var_name];
116+
}
117+
118+
// Options to control the server
94119
const serverOptions: ServerOptions = {
95120
run: { command: serverModule, args: extra },
96-
debug: { command: serverModule, args: extra },
121+
debug: { command: serverModule, args: extra }
97122
};
123+
98124
// Options to control the language client
99125
const clientOptions: LanguageClientOptions = {
100126
// Register the server for ada sources documents

0 commit comments

Comments
 (0)