Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Jan 31, 2024
2 parents 04c4892 + 8225f5c commit 475e2de
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 377 deletions.
700 changes: 414 additions & 286 deletions integration/vscode/ada/package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions integration/vscode/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "AdaCore",
"license": "GPL-3.0",
"engines": {
"vscode": "^1.71.2"
"vscode": "^1.83.1"
},
"categories": [
"Programming Languages",
Expand All @@ -16,8 +16,6 @@
"ms-vscode.cpptools"
],
"activationEvents": [
"onLanguage:ada",
"onLanguage:gpr",
"workspaceContains:*.gpr",
"workspaceContains:*/*.gpr",
"workspaceContains:*.ad[bs]",
Expand Down Expand Up @@ -856,7 +854,7 @@
"devDependencies": {
"@types/mocha": "10.0.1",
"@types/node": "16.18.16",
"@types/vscode": "1.71.0",
"@types/vscode": "1.83.3",
"@types/ws": "8.5.4",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.55.0",
Expand Down Expand Up @@ -891,8 +889,8 @@
"fast-xml-parser": "4.2.5",
"fp-ts": "2.12.0",
"process": "0.11.10",
"vscode-languageclient": "7.0.0",
"vscode-languageclient": "9.0.1",
"winston": "3.10.0",
"ws": "8.13.0"
}
}
}
9 changes: 2 additions & 7 deletions integration/vscode/ada/src/ExtensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class ExtensionState {
public readonly gprClient: LanguageClient;
public readonly context: vscode.ExtensionContext;

private clientsDisposables: Disposable[];
private registeredTaskProviders: Disposable[];

constructor(context: vscode.ExtensionContext) {
Expand All @@ -39,20 +38,16 @@ export class ExtensionState {
[],
'**/.{adb,ads,adc,ada}'
);
this.clientsDisposables = [];
this.registeredTaskProviders = [];
}

public start = () => {
this.clientsDisposables = [this.gprClient.start(), this.adaClient.start()];
public start = async () => {
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
this.registerTaskProviders();
};

public dispose = () => {
this.unregisterTaskProviders();
this.clientsDisposables.forEach((clientDisposable: Disposable) =>
clientDisposable.dispose()
);
};

public registerTaskProviders = (): void => {
Expand Down
17 changes: 17 additions & 0 deletions integration/vscode/ada/src/alsClientFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import {
ClientCapabilities,
DocumentSelector,
FeatureState,
InitializeParams,
ServerCapabilities,
StaticFeature,
Expand Down Expand Up @@ -77,10 +78,26 @@ export class ALSClientFeatures implements StaticFeature {
// eslint-disable-next-line @typescript-eslint/no-empty-function
}

/**
* Returns the state the feature is in.
*/
getState(): FeatureState {
return { kind: 'static' };
}

/**
* Unused since there are no necessary actions when disposing an object of this class
*/
dispose(): void {
// eslint-disable-next-line @typescript-eslint/no-empty-function
}

/**
* Called when the client is stopped or re-started to clear this feature.
* Usually a feature un-registers listeners registered hooked up with the
* VS Code extension host.
*/
clear(): void {
// eslint-disable-next-line @typescript-eslint/no-empty-function
}
}
2 changes: 1 addition & 1 deletion integration/vscode/ada/src/debugConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function getOrFindGdb(): string | undefined {
const env = getEvaluatedTerminalEnv();
let pathVal: string;
if (env && 'PATH' in env) {
pathVal = env.PATH;
pathVal = env.PATH ?? '';
} else if ('PATH' in process.env) {
pathVal = process.env.PATH ?? '';
} else {
Expand Down
8 changes: 3 additions & 5 deletions integration/vscode/ada/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ async function activateExtension(context: vscode.ExtensionContext) {
if (customEnv && Object.keys(customEnv).length > 0) {
logger.info(`Custom environment variables from ${TERMINAL_ENV_SETTING_NAME}`);
for (const varName in customEnv) {
const varValue: string = customEnv[varName];
logger.info(`${varName}=${varValue}`);
const varValue = customEnv[varName];
logger.info(`${varName}=${varValue ?? '<null>'}`);
}
} else {
logger.debug('No custom environment variables set in %s', TERMINAL_ENV_SETTING_NAME);
Expand All @@ -148,7 +148,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
adaExtState.adaClient.clientOptions.middleware = alsMiddleware;
adaExtState.adaClient.registerFeature(new ALSClientFeatures());

adaExtState.start();
await adaExtState.start();

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

await Promise.all([adaExtState.adaClient.onReady(), adaExtState.gprClient.onReady()]);

await vscode.commands.executeCommand('setContext', ADA_CONTEXT, true);

await initializeTestView(context, adaExtState);
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/src/gnattest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export async function initializeTestView(
);
context.subscriptions.push(controller);

await clients.adaClient.onReady();
// Getting Paths Information from the server
const projectFile = await getProjectFile(clients.adaClient);
const objectDir: string = await getObjectDir(clients.adaClient);
Expand Down
50 changes: 36 additions & 14 deletions integration/vscode/ada/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ export const TERMINAL_ENV_SETTING_NAME =
* @returns the value of the applicable `terminal.integrated.env.*` setting,
* without evaluation of macros such as `${env:...}`.
*/
export function getTerminalEnv() {
export function getTerminalEnv(): { [name: string]: string | null } {
const custom_env = vscode.workspace
.getConfiguration()
.get<{ [name: string]: string }>(TERMINAL_ENV_SETTING_NAME);
.get<{ [name: string]: string | null }>(TERMINAL_ENV_SETTING_NAME);

return custom_env;
return custom_env ?? {};
}

/**
Expand All @@ -139,11 +139,18 @@ export function getEvaluatedTerminalEnv() {

if (custom_env) {
for (const var_name in custom_env) {
// Substitute VS Code variable references that might be present
// in the JSON settings configuration (e.g: "PATH": "${workspaceFolder}/obj")
custom_env[var_name] = custom_env[var_name].replace(/(\$\{.*\})/, (substring) =>
substituteVariables(substring, false)
);
/**
* The User can specify `"VAR": null` in his settings, so we only
* apply substitution to non-null values.
*/
if (custom_env[var_name] != null) {
// Substitute VS Code variable references that might be present
// in the JSON settings configuration (e.g: "PATH": "${workspaceFolder}/obj")
custom_env[var_name] =
custom_env[var_name]?.replace(/(\$\{.*\})/, (substring) =>
substituteVariables(substring, false)
) ?? null;
}
}
}

Expand All @@ -157,15 +164,30 @@ export function getEvaluatedTerminalEnv() {
* The targetEnv can be `process.env` to apply the changes to the environment of
* the running process.
*/
export function setTerminalEnvironment(targetEnv: NodeJS.ProcessEnv) {
// Retrieve the user's custom environment variables if specified in their
// settings/workspace
const custom_env = getEvaluatedTerminalEnv();
export function setTerminalEnvironment(
targetEnv: NodeJS.ProcessEnv,
custom_env?: { [name: string]: string | null }
) {
if (custom_env == undefined) {
// Retrieve the user's custom environment variables if specified in their
// settings/workspace
custom_env = getEvaluatedTerminalEnv();
}

if (custom_env) {
for (const var_name in custom_env) {
const var_value: string = custom_env[var_name];
targetEnv[var_name] = var_value;
const var_value = custom_env[var_name];
if (var_value == null) {
/**
* If the value is null, delete it from the target env if it
* exists.
*/
if (var_name in targetEnv) {
delete targetEnv[var_name];
}
} else {
targetEnv[var_name] = var_value;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion integration/vscode/ada/src/taskProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class BuildAndRunExecution extends vscode.CustomExecution {
},
() => {
writeEmitter.fire('Failed to get list of tasks\r\n');
closeEmitter.fire(1);
return 1;
}
)
.then(
Expand Down
43 changes: 43 additions & 0 deletions integration/vscode/ada/test/suite/general/env.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from 'assert';
import { suite, test } from 'mocha';
import { setTerminalEnvironment } from '../../../src/helpers';

suite('Environment init', () => {
test('Env init', () => {
/**
* We want to test the cases [existing variable, non-existing variable]
* x [null value, empty string, non-empty string] exhaustively. So we
* should end up with 6 test cases.
*/

const targetEnv = {
VAR1: '',
VAR2: '',
VAR3: '',
VAR7: 'Should be preserved',
};

const userEnv: { [name: string]: string | null } = {
// Existing variables
VAR1: null,
VAR2: '',
VAR3: 'Some new value',
// Non-existing variables
VAR4: null,
VAR5: '',
VAR6: 'Some other value',
};

setTerminalEnvironment(targetEnv, userEnv);

const expected = {
VAR2: '',
VAR3: 'Some new value',
VAR5: '',
VAR6: 'Some other value',
VAR7: 'Should be preserved',
};

assert.deepEqual(targetEnv, expected);
});
});
3 changes: 0 additions & 3 deletions integration/vscode/ada/test/suite/general/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ suite('Extensions Test Suite', function () {
});
test('Project File Response', async () => {
if (vscode.workspace.workspaceFolders !== undefined) {
await adaExtState.adaClient.onReady();
const result: string = await getProjectFile(adaExtState.adaClient);
const name = result.replace(/^.*[\\/]/, '');
assert.strictEqual(name, 'default.gpr');
Expand All @@ -23,7 +22,6 @@ suite('Extensions Test Suite', function () {
});
test('Object Directory Response', async () => {
if (vscode.workspace.workspaceFolders !== undefined) {
await adaExtState.adaClient.onReady();
const result: string = await getObjectDir(adaExtState.adaClient);
const name = result?.replace(/^.*[\\/]/, '');
assert.strictEqual(name, 'obj');
Expand All @@ -33,7 +31,6 @@ suite('Extensions Test Suite', function () {
});
test('Test Add Subprogram Box', async () => {
if (vscode.workspace.workspaceFolders !== undefined) {
await adaExtState.adaClient.onReady();
const cursorPositions: vscode.Position[] = [
new vscode.Position(9, 1),
new vscode.Position(4, 1),
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ suite('Syntax Check Test Suite', function () {
false_statement: string,
true_statement: string
) {
await adaExtState.adaClient.onReady();
const syntaxProvider = new AdaSyntaxCheckProvider(adaExtState.adaClient, [rule]);
let result = await syntaxProvider.sendCheckSyntaxRequest(true_statement);
assert.deepStrictEqual(result, undefined);
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim();
* Check that the list of offered SPARK tasks is expected.
*/
test('Spark tasks list', async () => {
await adaExtState.adaClient.onReady();
const prov = createSparkTaskProvider();
const tasks = await prov.provideTasks();
assert.notStrictEqual(tasks, undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ suite('GNATtest Integration Tests', function () {
await activate();
});
test('Generate Tests', async () => {
await adaExtState.adaClient.onReady();
const projectFile = await getProjectFile(adaExtState.adaClient);
// Generate tests and redirect the stderr to stdout if command failed
cp.execSync('gnattest -P ' + projectFile + ' 2>&1', { timeout: 60000 });
Expand Down
Loading

0 comments on commit 475e2de

Please sign in to comment.