Skip to content

Commit 475e2de

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 04c4892 + 8225f5c commit 475e2de

File tree

15 files changed

+526
-377
lines changed

15 files changed

+526
-377
lines changed

integration/vscode/ada/package-lock.json

Lines changed: 414 additions & 286 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/vscode/ada/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "AdaCore",
77
"license": "GPL-3.0",
88
"engines": {
9-
"vscode": "^1.71.2"
9+
"vscode": "^1.83.1"
1010
},
1111
"categories": [
1212
"Programming Languages",
@@ -16,8 +16,6 @@
1616
"ms-vscode.cpptools"
1717
],
1818
"activationEvents": [
19-
"onLanguage:ada",
20-
"onLanguage:gpr",
2119
"workspaceContains:*.gpr",
2220
"workspaceContains:*/*.gpr",
2321
"workspaceContains:*.ad[bs]",
@@ -856,7 +854,7 @@
856854
"devDependencies": {
857855
"@types/mocha": "10.0.1",
858856
"@types/node": "16.18.16",
859-
"@types/vscode": "1.71.0",
857+
"@types/vscode": "1.83.3",
860858
"@types/ws": "8.5.4",
861859
"@typescript-eslint/eslint-plugin": "5.54.0",
862860
"@typescript-eslint/parser": "5.55.0",
@@ -891,8 +889,8 @@
891889
"fast-xml-parser": "4.2.5",
892890
"fp-ts": "2.12.0",
893891
"process": "0.11.10",
894-
"vscode-languageclient": "7.0.0",
892+
"vscode-languageclient": "9.0.1",
895893
"winston": "3.10.0",
896894
"ws": "8.13.0"
897895
}
898-
}
896+
}

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export class ExtensionState {
2020
public readonly gprClient: LanguageClient;
2121
public readonly context: vscode.ExtensionContext;
2222

23-
private clientsDisposables: Disposable[];
2423
private registeredTaskProviders: Disposable[];
2524

2625
constructor(context: vscode.ExtensionContext) {
@@ -39,20 +38,16 @@ export class ExtensionState {
3938
[],
4039
'**/.{adb,ads,adc,ada}'
4140
);
42-
this.clientsDisposables = [];
4341
this.registeredTaskProviders = [];
4442
}
4543

46-
public start = () => {
47-
this.clientsDisposables = [this.gprClient.start(), this.adaClient.start()];
44+
public start = async () => {
45+
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
4846
this.registerTaskProviders();
4947
};
5048

5149
public dispose = () => {
5250
this.unregisterTaskProviders();
53-
this.clientsDisposables.forEach((clientDisposable: Disposable) =>
54-
clientDisposable.dispose()
55-
);
5651
};
5752

5853
public registerTaskProviders = (): void => {

integration/vscode/ada/src/alsClientFeatures.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import {
2323
ClientCapabilities,
2424
DocumentSelector,
25+
FeatureState,
2526
InitializeParams,
2627
ServerCapabilities,
2728
StaticFeature,
@@ -77,10 +78,26 @@ export class ALSClientFeatures implements StaticFeature {
7778
// eslint-disable-next-line @typescript-eslint/no-empty-function
7879
}
7980

81+
/**
82+
* Returns the state the feature is in.
83+
*/
84+
getState(): FeatureState {
85+
return { kind: 'static' };
86+
}
87+
8088
/**
8189
* Unused since there are no necessary actions when disposing an object of this class
8290
*/
8391
dispose(): void {
8492
// eslint-disable-next-line @typescript-eslint/no-empty-function
8593
}
94+
95+
/**
96+
* Called when the client is stopped or re-started to clear this feature.
97+
* Usually a feature un-registers listeners registered hooked up with the
98+
* VS Code extension host.
99+
*/
100+
clear(): void {
101+
// eslint-disable-next-line @typescript-eslint/no-empty-function
102+
}
86103
}

integration/vscode/ada/src/debugConfigProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function getOrFindGdb(): string | undefined {
100100
const env = getEvaluatedTerminalEnv();
101101
let pathVal: string;
102102
if (env && 'PATH' in env) {
103-
pathVal = env.PATH;
103+
pathVal = env.PATH ?? '';
104104
} else if ('PATH' in process.env) {
105105
pathVal = process.env.PATH ?? '';
106106
} else {

integration/vscode/ada/src/extension.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ async function activateExtension(context: vscode.ExtensionContext) {
131131
if (customEnv && Object.keys(customEnv).length > 0) {
132132
logger.info(`Custom environment variables from ${TERMINAL_ENV_SETTING_NAME}`);
133133
for (const varName in customEnv) {
134-
const varValue: string = customEnv[varName];
135-
logger.info(`${varName}=${varValue}`);
134+
const varValue = customEnv[varName];
135+
logger.info(`${varName}=${varValue ?? '<null>'}`);
136136
}
137137
} else {
138138
logger.debug('No custom environment variables set in %s', TERMINAL_ENV_SETTING_NAME);
@@ -148,7 +148,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
148148
adaExtState.adaClient.clientOptions.middleware = alsMiddleware;
149149
adaExtState.adaClient.registerFeature(new ALSClientFeatures());
150150

151-
adaExtState.start();
151+
await adaExtState.start();
152152

153153
context.subscriptions.push(
154154
vscode.workspace.onDidChangeConfiguration(adaExtState.configChanged)
@@ -160,8 +160,6 @@ async function activateExtension(context: vscode.ExtensionContext) {
160160
*/
161161
registerCommands(context, adaExtState);
162162

163-
await Promise.all([adaExtState.adaClient.onReady(), adaExtState.gprClient.onReady()]);
164-
165163
await vscode.commands.executeCommand('setContext', ADA_CONTEXT, true);
166164

167165
await initializeTestView(context, adaExtState);

integration/vscode/ada/src/gnattest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export async function initializeTestView(
6363
);
6464
context.subscriptions.push(controller);
6565

66-
await clients.adaClient.onReady();
6766
// Getting Paths Information from the server
6867
const projectFile = await getProjectFile(clients.adaClient);
6968
const objectDir: string = await getObjectDir(clients.adaClient);

integration/vscode/ada/src/helpers.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ export const TERMINAL_ENV_SETTING_NAME =
121121
* @returns the value of the applicable `terminal.integrated.env.*` setting,
122122
* without evaluation of macros such as `${env:...}`.
123123
*/
124-
export function getTerminalEnv() {
124+
export function getTerminalEnv(): { [name: string]: string | null } {
125125
const custom_env = vscode.workspace
126126
.getConfiguration()
127-
.get<{ [name: string]: string }>(TERMINAL_ENV_SETTING_NAME);
127+
.get<{ [name: string]: string | null }>(TERMINAL_ENV_SETTING_NAME);
128128

129-
return custom_env;
129+
return custom_env ?? {};
130130
}
131131

132132
/**
@@ -139,11 +139,18 @@ export function getEvaluatedTerminalEnv() {
139139

140140
if (custom_env) {
141141
for (const var_name in custom_env) {
142-
// Substitute VS Code variable references that might be present
143-
// in the JSON settings configuration (e.g: "PATH": "${workspaceFolder}/obj")
144-
custom_env[var_name] = custom_env[var_name].replace(/(\$\{.*\})/, (substring) =>
145-
substituteVariables(substring, false)
146-
);
142+
/**
143+
* The User can specify `"VAR": null` in his settings, so we only
144+
* apply substitution to non-null values.
145+
*/
146+
if (custom_env[var_name] != null) {
147+
// Substitute VS Code variable references that might be present
148+
// in the JSON settings configuration (e.g: "PATH": "${workspaceFolder}/obj")
149+
custom_env[var_name] =
150+
custom_env[var_name]?.replace(/(\$\{.*\})/, (substring) =>
151+
substituteVariables(substring, false)
152+
) ?? null;
153+
}
147154
}
148155
}
149156

@@ -157,15 +164,30 @@ export function getEvaluatedTerminalEnv() {
157164
* The targetEnv can be `process.env` to apply the changes to the environment of
158165
* the running process.
159166
*/
160-
export function setTerminalEnvironment(targetEnv: NodeJS.ProcessEnv) {
161-
// Retrieve the user's custom environment variables if specified in their
162-
// settings/workspace
163-
const custom_env = getEvaluatedTerminalEnv();
167+
export function setTerminalEnvironment(
168+
targetEnv: NodeJS.ProcessEnv,
169+
custom_env?: { [name: string]: string | null }
170+
) {
171+
if (custom_env == undefined) {
172+
// Retrieve the user's custom environment variables if specified in their
173+
// settings/workspace
174+
custom_env = getEvaluatedTerminalEnv();
175+
}
164176

165177
if (custom_env) {
166178
for (const var_name in custom_env) {
167-
const var_value: string = custom_env[var_name];
168-
targetEnv[var_name] = var_value;
179+
const var_value = custom_env[var_name];
180+
if (var_value == null) {
181+
/**
182+
* If the value is null, delete it from the target env if it
183+
* exists.
184+
*/
185+
if (var_name in targetEnv) {
186+
delete targetEnv[var_name];
187+
}
188+
} else {
189+
targetEnv[var_name] = var_value;
190+
}
169191
}
170192
}
171193
}

integration/vscode/ada/src/taskProviders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ class BuildAndRunExecution extends vscode.CustomExecution {
863863
},
864864
() => {
865865
writeEmitter.fire('Failed to get list of tasks\r\n');
866-
closeEmitter.fire(1);
866+
return 1;
867867
}
868868
)
869869
.then(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import assert from 'assert';
2+
import { suite, test } from 'mocha';
3+
import { setTerminalEnvironment } from '../../../src/helpers';
4+
5+
suite('Environment init', () => {
6+
test('Env init', () => {
7+
/**
8+
* We want to test the cases [existing variable, non-existing variable]
9+
* x [null value, empty string, non-empty string] exhaustively. So we
10+
* should end up with 6 test cases.
11+
*/
12+
13+
const targetEnv = {
14+
VAR1: '',
15+
VAR2: '',
16+
VAR3: '',
17+
VAR7: 'Should be preserved',
18+
};
19+
20+
const userEnv: { [name: string]: string | null } = {
21+
// Existing variables
22+
VAR1: null,
23+
VAR2: '',
24+
VAR3: 'Some new value',
25+
// Non-existing variables
26+
VAR4: null,
27+
VAR5: '',
28+
VAR6: 'Some other value',
29+
};
30+
31+
setTerminalEnvironment(targetEnv, userEnv);
32+
33+
const expected = {
34+
VAR2: '',
35+
VAR3: 'Some new value',
36+
VAR5: '',
37+
VAR6: 'Some other value',
38+
VAR7: 'Should be preserved',
39+
};
40+
41+
assert.deepEqual(targetEnv, expected);
42+
});
43+
});

0 commit comments

Comments
 (0)