Skip to content

Commit f1747ee

Browse files
committed
Rename and document vscode env management declarations
1 parent e35634b commit f1747ee

File tree

5 files changed

+37
-49
lines changed

5 files changed

+37
-49
lines changed

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createClient } from './clients';
44
import { GnatTaskProvider } from './gnatTaskProvider';
55
import { GprTaskProvider } from './gprTaskProvider';
66
import { registerTaskProviders } from './taskProviders';
7-
import { getCustomEnvSettingName } from './helpers';
7+
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
88

99
/**
1010
* This class encapsulates all state that should be maintained throughout the
@@ -106,9 +106,7 @@ export class ExtensionState {
106106
// React to changes made in the environment variables, showing
107107
// a popup to reload the VS Code window and thus restart the
108108
// Ada extension.
109-
const env_config_name = getCustomEnvSettingName();
110-
111-
if (e.affectsConfiguration(env_config_name)) {
109+
if (e.affectsConfiguration(TERMINAL_ENV_SETTING_NAME)) {
112110
void this.showReloadWindowPopup();
113111
}
114112
};

integration/vscode/ada/src/clients.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
22
import * as vscode from 'vscode';
33
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
44
import { logger } from './extension';
5-
import { logErrorAndThrow, setCustomEnvironment } from './helpers';
5+
import { logErrorAndThrow, setTerminalEnvironment } from './helpers';
66

77
export function createClient(
88
context: vscode.ExtensionContext,
@@ -63,7 +63,7 @@ export function createClient(
6363
// Copy this process's environment
6464
const serverEnv: NodeJS.ProcessEnv = { ...process.env };
6565
// Set custom environment
66-
setCustomEnvironment(serverEnv);
66+
setTerminalEnvironment(serverEnv);
6767

6868
logger.debug(`Environment for ${name}:`);
6969
for (const key in serverEnv) {

integration/vscode/ada/src/debugConfigProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'assert';
22
import * as vscode from 'vscode';
33
import { adaExtState } from './extension';
4-
import { AdaMain, exe, getAdaMains, getEvaluatedCustomEnv, getProjectFile } from './helpers';
4+
import { AdaMain, exe, getAdaMains, getEvaluatedTerminalEnv, getProjectFile } from './helpers';
55
import { BUILD_PROJECT_TASK_NAME, getBuildTaskName } from './taskProviders';
66
import path from 'path';
77
import { existsSync } from 'fs';
@@ -97,7 +97,7 @@ function getOrFindGdb(): string | undefined {
9797
/**
9898
* If undefined yet, try to compute it.
9999
*/
100-
const env = getEvaluatedCustomEnv();
100+
const env = getEvaluatedTerminalEnv();
101101
let pathVal: string;
102102
if (env && 'PATH' in env) {
103103
pathVal = env.PATH;

integration/vscode/ada/src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import { initializeDebugging } from './debugConfigProvider';
3030
import { initializeTestView } from './gnattest';
3131
import {
3232
assertSupportedEnvironments,
33-
getCustomEnvSettingName,
34-
getEvaluatedCustomEnv,
33+
TERMINAL_ENV_SETTING_NAME,
34+
getEvaluatedTerminalEnv,
3535
startedInDebugMode,
3636
} from './helpers';
3737

@@ -127,15 +127,15 @@ async function activateExtension(context: vscode.ExtensionContext) {
127127
assertSupportedEnvironments(logger);
128128

129129
// Log the environment that the extension (and all VS Code) will be using
130-
const customEnv = getEvaluatedCustomEnv();
130+
const customEnv = getEvaluatedTerminalEnv();
131131
if (customEnv && Object.keys(customEnv).length > 0) {
132-
logger.info(`Custom environment variables from ${getCustomEnvSettingName()}`);
132+
logger.info(`Custom environment variables from ${TERMINAL_ENV_SETTING_NAME}`);
133133
for (const varName in customEnv) {
134134
const varValue: string = customEnv[varName];
135135
logger.info(`${varName}=${varValue}`);
136136
}
137137
} else {
138-
logger.debug('No custom environment variables set in %s', getCustomEnvSettingName());
138+
logger.debug('No custom environment variables set in %s', TERMINAL_ENV_SETTING_NAME);
139139
}
140140

141141
// Create the Ada and GPR clients.

integration/vscode/ada/src/helpers.ts

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,39 +109,33 @@ export function substituteVariables(str: string, recursive = false): string {
109109
return str;
110110
}
111111

112-
/*
113-
Environment setting helper functions
114-
*/
115-
116-
export function getCustomEnv() {
117-
const env_config_name = getCustomEnvSettingName();
112+
/**
113+
* Name of the `terminal.integrated.env.*` setting applicable to the current platform.
114+
*/
115+
export const TERMINAL_ENV_SETTING_NAME =
116+
'terminal.integrated.env.' +
117+
(platform() == 'darwin' ? 'osx' : platform() == 'win32' ? 'windows' : 'linux');
118118

119+
/**
120+
*
121+
* @returns the value of the applicable `terminal.integrated.env.*` setting,
122+
* without evaluation of macros such as `${env:...}`.
123+
*/
124+
export function getTerminalEnv() {
119125
const custom_env = vscode.workspace
120126
.getConfiguration()
121-
.get<{ [name: string]: string }>(env_config_name);
127+
.get<{ [name: string]: string }>(TERMINAL_ENV_SETTING_NAME);
122128

123129
return custom_env;
124130
}
125131

126-
export function getCustomEnvSettingName() {
127-
const user_platform = platform();
128-
let env_config_name = 'terminal.integrated.env';
129-
130-
switch (user_platform) {
131-
case 'darwin':
132-
env_config_name += '.osx';
133-
break;
134-
case 'win32':
135-
env_config_name += '.windows';
136-
break;
137-
default:
138-
env_config_name += '.linux';
139-
}
140-
return env_config_name;
141-
}
142-
143-
export function getEvaluatedCustomEnv() {
144-
const custom_env = getCustomEnv();
132+
/**
133+
*
134+
* @returns the value of the applicable `terminal.integrated.env.*` setting,
135+
* after evaluation of macros such as `${env:...}`.
136+
*/
137+
export function getEvaluatedTerminalEnv() {
138+
const custom_env = getTerminalEnv();
145139

146140
if (custom_env) {
147141
for (const var_name in custom_env) {
@@ -160,17 +154,13 @@ export function getEvaluatedCustomEnv() {
160154
* Read the environment variables specified in the vscode setting
161155
* `terminal.integrated.env.<os>` and set them in the given ProcessEnv object.
162156
*
163-
* If no targetEnv is given, `process.env` is used as a target environment.
157+
* The targetEnv can be `process.env` to apply the changes to the environment of
158+
* the running process.
164159
*/
165-
export function setCustomEnvironment(targetEnv?: NodeJS.ProcessEnv) {
166-
if (!targetEnv) {
167-
targetEnv = process.env;
168-
}
169-
160+
export function setTerminalEnvironment(targetEnv: NodeJS.ProcessEnv) {
170161
// Retrieve the user's custom environment variables if specified in their
171-
// settings/workspace: we'll then launch any child process with this custom
172-
// environment
173-
const custom_env = getEvaluatedCustomEnv();
162+
// settings/workspace
163+
const custom_env = getEvaluatedTerminalEnv();
174164

175165
if (custom_env) {
176166
for (const var_name in custom_env) {
@@ -183,7 +173,7 @@ export function setCustomEnvironment(targetEnv?: NodeJS.ProcessEnv) {
183173
export function assertSupportedEnvironments(mainChannel: winston.Logger) {
184174
// Get the ALS environment variable from the custom environment, or from the
185175
// process environment
186-
const customEnv = getEvaluatedCustomEnv();
176+
const customEnv = getEvaluatedTerminalEnv();
187177
const als = customEnv?.ALS ?? process.env.ALS;
188178
if (als) {
189179
// The User provided an external ALS executable. Do not perform any

0 commit comments

Comments
 (0)