Skip to content

Commit bf06791

Browse files
committed
Merge branch 'topic/fix-vscode-env' into 'master'
Refactor passing environment from vscode to ALS Closes #1191 See merge request eng/ide/ada_language_server!1417
2 parents 2eb761e + 8059077 commit bf06791

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

integration/vscode/ada/src/clients.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { logger } from './extension';
1111
import GnatTaskProvider from './gnatTaskProvider';
1212
import GprTaskProvider from './gprTaskProvider';
13-
import { logErrorAndThrow } from './helpers';
13+
import { logErrorAndThrow, setCustomEnvironment } from './helpers';
1414
import { registerTaskProviders } from './taskProviders';
1515

1616
export class ContextClients {
@@ -145,15 +145,15 @@ function createClient(
145145

146146
logger.debug(`Using ALS at: ${serverExecPath}`);
147147

148-
// The debug options for the server
149-
// let debugOptions = { execArgv: [] };
150-
// If the extension is launched in debug mode then the debug server options are used
151-
// Otherwise the run options are used
148+
// Copy this process's environment
149+
const serverEnv: NodeJS.ProcessEnv = { ...process.env };
150+
// Set custom environment
151+
setCustomEnvironment(serverEnv);
152152

153153
// Options to control the server
154154
const serverOptions: ServerOptions = {
155-
run: { command: serverExecPath, args: extra },
156-
debug: { command: serverExecPath, args: extra },
155+
run: { command: serverExecPath, args: extra, options: { env: serverEnv } },
156+
debug: { command: serverExecPath, args: extra, options: { env: serverEnv } },
157157
};
158158

159159
// Options to control the language client

integration/vscode/ada/src/extension.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
assertSupportedEnvironments,
3434
getCustomEnvSettingName,
3535
getEvaluatedCustomEnv,
36-
setCustomEnvironment,
3736
startedInDebugMode,
3837
} from './helpers';
3938

@@ -124,9 +123,8 @@ async function activateExtension(context: vscode.ExtensionContext) {
124123

125124
// Log the environment that the extension (and all VS Code) will be using
126125
const customEnv = getEvaluatedCustomEnv();
127-
128126
if (customEnv && Object.keys(customEnv).length > 0) {
129-
logger.info('Setting environment variables:');
127+
logger.info('Custom environment variables:');
130128
for (const varName in customEnv) {
131129
const varValue: string = customEnv[varName];
132130
logger.info(`${varName}=${varValue}`);
@@ -135,13 +133,6 @@ async function activateExtension(context: vscode.ExtensionContext) {
135133
logger.debug('No custom environment variables set in %s', getCustomEnvSettingName());
136134
}
137135

138-
// Set the custom environment into the current node process. This must be
139-
// done before calling assertSupportedEnvironments in order to set the ALS
140-
// environment variable if provided.
141-
setCustomEnvironment();
142-
143-
assertSupportedEnvironments(logger);
144-
145136
// Create the Ada and GPR clients.
146137
contextClients = new ContextClients(context);
147138

integration/vscode/ada/src/helpers.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,15 @@ export function getEvaluatedCustomEnv() {
158158

159159
/**
160160
* Read the environment variables specified in the vscode setting
161-
* `terminal.integrated.env.<os>` and set them in the current node process so
162-
* that they become inherited by any child processes.
161+
* `terminal.integrated.env.<os>` and set them in the given ProcessEnv object.
162+
*
163+
* If no targetEnv is given, `process.env` is used as a target environment.
163164
*/
164-
export function setCustomEnvironment() {
165+
export function setCustomEnvironment(targetEnv?: NodeJS.ProcessEnv) {
166+
if (!targetEnv) {
167+
targetEnv = process.env;
168+
}
169+
165170
// Retrieve the user's custom environment variables if specified in their
166171
// settings/workspace: we'll then launch any child process with this custom
167172
// environment
@@ -170,13 +175,17 @@ export function setCustomEnvironment() {
170175
if (custom_env) {
171176
for (const var_name in custom_env) {
172177
const var_value: string = custom_env[var_name];
173-
process.env[var_name] = var_value;
178+
targetEnv[var_name] = var_value;
174179
}
175180
}
176181
}
177182

178183
export function assertSupportedEnvironments(mainChannel: winston.Logger) {
179-
if (process.env.ALS) {
184+
// Get the ALS environment variable from the custom environment, or from the
185+
// process environment
186+
const customEnv = getEvaluatedCustomEnv();
187+
const als = customEnv?.ALS ?? process.env.ALS;
188+
if (als) {
180189
// The User provided an external ALS executable. Do not perform any
181190
// platform support checks because we may be on an unsupported platform
182191
// where the User built and provided ALS.

0 commit comments

Comments
 (0)