Skip to content

Commit 04dfdb6

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents bcceff7 + 9bbdea5 commit 04dfdb6

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

integration/vscode/ada/src/helpers.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import { existsSync } from 'fs';
2626
import { ExtensionState } from './ExtensionState';
2727
import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension';
2828

29+
/* Whether we are under Windows */
30+
const isWindows = process.platform === 'win32';
31+
2932
/**
3033
* Substitue any variable reference present in the given string. VS Code
3134
* variable references are listed here:
@@ -377,10 +380,22 @@ export const exe: '.exe' | '' = process.platform == 'win32' ? '.exe' : '';
377380
*/
378381
export async function findAdaMain(mainPath: string): Promise<AdaMain | undefined> {
379382
const projectMains = await getAdaMains();
380-
const adaMain = projectMains.find(
381-
(val) => val.mainRelPath() == mainPath || val.mainFullPath == mainPath
382-
);
383-
return adaMain;
383+
384+
if (isWindows) {
385+
/* Case-insensitive comparison under Windows */
386+
const lc_main = mainPath.toLowerCase();
387+
const adaMain = projectMains.find(
388+
(val) =>
389+
val.mainRelPath().toLowerCase() == lc_main ||
390+
val.mainFullPath.toLowerCase() == lc_main
391+
);
392+
return adaMain;
393+
} else {
394+
const adaMain = projectMains.find(
395+
(val) => val.mainRelPath() == mainPath || val.mainFullPath == mainPath
396+
);
397+
return adaMain;
398+
}
384399
}
385400
/**
386401
* Starting from an array of symbols {@link rootSymbols} (usually obtained for a

integration/vscode/ada/test/suite/general/helpers.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import assert from 'assert';
2-
import { envHasExec, getSymbols, which } from '../../../src/helpers';
2+
import { envHasExec, findAdaMain, getSymbols, which } from '../../../src/helpers';
33
import { DocumentSymbol, SymbolKind, Uri, commands, workspace } from 'vscode';
44
import { rangeToStr } from '../utils';
55

66
suite('which and envHasExec', function () {
77
test('existing', function () {
88
switch (process.platform) {
99
case 'win32':
10-
assert(which('where')?.endsWith('where.exe'));
10+
/* which() relies on PATHEXT which could contain .EXE or .exe.
11+
Lowercase the comparison for this test.
12+
*/
13+
assert(which('where')?.toLowerCase().endsWith('where.exe'));
1114
assert(envHasExec('where'));
1215
break;
1316

@@ -23,6 +26,27 @@ suite('which and envHasExec', function () {
2326
});
2427
});
2528

29+
suite('findAdaMain', function () {
30+
test('Find one main (simple case)', async function () {
31+
/* Test that findAdaMain works in a simple case */
32+
const uri = Uri.joinPath(workspace.workspaceFolders![0].uri, 'src', 'main1.adb');
33+
const adaMain = await findAdaMain(uri.fsPath);
34+
assert(adaMain);
35+
});
36+
test('Find one main (case sensitivity)', async function () {
37+
/* Test the behavior of findAdaMain with respect to case sensitivity */
38+
const uri_uppercase = Uri.joinPath(workspace.workspaceFolders![0].uri, 'src', 'MAIN1.ADB');
39+
const adaMain_from_uppercase = await findAdaMain(uri_uppercase.fsPath);
40+
41+
/* On Windows we should have a main here, otherwise we should not */
42+
if (process.platform === 'win32') {
43+
assert(adaMain_from_uppercase);
44+
} else {
45+
assert(!adaMain_from_uppercase);
46+
}
47+
});
48+
});
49+
2650
suite('getSymbols', function () {
2751
let symbols: DocumentSymbol[];
2852

0 commit comments

Comments
 (0)