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 Jul 15, 2024
2 parents bcceff7 + 9bbdea5 commit 04dfdb6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
23 changes: 19 additions & 4 deletions integration/vscode/ada/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { existsSync } from 'fs';
import { ExtensionState } from './ExtensionState';
import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension';

/* Whether we are under Windows */
const isWindows = process.platform === 'win32';

/**
* Substitue any variable reference present in the given string. VS Code
* variable references are listed here:
Expand Down Expand Up @@ -377,10 +380,22 @@ export const exe: '.exe' | '' = process.platform == 'win32' ? '.exe' : '';
*/
export async function findAdaMain(mainPath: string): Promise<AdaMain | undefined> {
const projectMains = await getAdaMains();
const adaMain = projectMains.find(
(val) => val.mainRelPath() == mainPath || val.mainFullPath == mainPath
);
return adaMain;

if (isWindows) {
/* Case-insensitive comparison under Windows */
const lc_main = mainPath.toLowerCase();
const adaMain = projectMains.find(
(val) =>
val.mainRelPath().toLowerCase() == lc_main ||
val.mainFullPath.toLowerCase() == lc_main
);
return adaMain;
} else {
const adaMain = projectMains.find(
(val) => val.mainRelPath() == mainPath || val.mainFullPath == mainPath
);
return adaMain;
}
}
/**
* Starting from an array of symbols {@link rootSymbols} (usually obtained for a
Expand Down
28 changes: 26 additions & 2 deletions integration/vscode/ada/test/suite/general/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import assert from 'assert';
import { envHasExec, getSymbols, which } from '../../../src/helpers';
import { envHasExec, findAdaMain, getSymbols, which } from '../../../src/helpers';
import { DocumentSymbol, SymbolKind, Uri, commands, workspace } from 'vscode';
import { rangeToStr } from '../utils';

suite('which and envHasExec', function () {
test('existing', function () {
switch (process.platform) {
case 'win32':
assert(which('where')?.endsWith('where.exe'));
/* which() relies on PATHEXT which could contain .EXE or .exe.
Lowercase the comparison for this test.
*/
assert(which('where')?.toLowerCase().endsWith('where.exe'));
assert(envHasExec('where'));
break;

Expand All @@ -23,6 +26,27 @@ suite('which and envHasExec', function () {
});
});

suite('findAdaMain', function () {
test('Find one main (simple case)', async function () {
/* Test that findAdaMain works in a simple case */
const uri = Uri.joinPath(workspace.workspaceFolders![0].uri, 'src', 'main1.adb');
const adaMain = await findAdaMain(uri.fsPath);
assert(adaMain);
});
test('Find one main (case sensitivity)', async function () {
/* Test the behavior of findAdaMain with respect to case sensitivity */
const uri_uppercase = Uri.joinPath(workspace.workspaceFolders![0].uri, 'src', 'MAIN1.ADB');
const adaMain_from_uppercase = await findAdaMain(uri_uppercase.fsPath);

/* On Windows we should have a main here, otherwise we should not */
if (process.platform === 'win32') {
assert(adaMain_from_uppercase);
} else {
assert(!adaMain_from_uppercase);
}
});
});

suite('getSymbols', function () {
let symbols: DocumentSymbol[];

Expand Down

0 comments on commit 04dfdb6

Please sign in to comment.