Skip to content

Commit 08c94c3

Browse files
committed
Fix Windows-specific behaviors in VS Code extension
Closes eng/ide/ada_language_server#1366
1 parent 2897960 commit 08c94c3

File tree

5 files changed

+121
-114
lines changed

5 files changed

+121
-114
lines changed

integration/vscode/ada/src/AdaCodeLensProvider.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SymbolKind,
1010
TextDocument,
1111
commands,
12+
Uri,
1213
} from 'vscode';
1314
import { CMD_BUILD_AND_DEBUG_MAIN, CMD_BUILD_AND_RUN_MAIN } from './commands';
1415
import { getMains, getSymbols } from './helpers';
@@ -30,7 +31,14 @@ export class AdaCodeLensProvider implements CodeLensProvider {
3031
* For main procedures, provide Run and Debug CodeLenses.
3132
*/
3233
const res1 = getMains().then((mains) => {
33-
if (mains.some((m) => m == document.fileName)) {
34+
if (
35+
mains.some(
36+
(m) =>
37+
// Here we go through the Uri class to benefit from the normalization
38+
// of path casing on Windows. See Uri.fsPath documentation.
39+
Uri.file(m).fsPath == document.uri.fsPath
40+
)
41+
) {
3442
// It's a main file, so let's offer Run and Debug actions on the main subprogram
3543
return symbols.then((symbols) => {
3644
const functions = symbols.filter((s) => s.kind == SymbolKind.Function);

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

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import assert from 'assert';
22
import { Uri, window, workspace } from 'vscode';
33
import { adaExtState } from '../../../src/extension';
4-
import { activate } from '../utils';
4+
import { activate, closeAllEditors } from '../utils';
55

66
suite('CodeLens', function () {
77
this.beforeAll(async () => {
88
await activate();
99
});
1010

11+
this.beforeEach(async function () {
12+
await closeAllEditors();
13+
});
14+
1115
test('in main file offer run & debug', async () => {
1216
assert(workspace.workspaceFolders !== undefined);
1317
const rootUri = workspace.workspaceFolders[0].uri;
@@ -16,28 +20,29 @@ suite('CodeLens', function () {
1620
const codelenses = await adaExtState.codelensProvider.provideCodeLenses(
1721
textEditor.document
1822
);
19-
assert.equal(
23+
assert.deepEqual(
2024
/**
21-
* Check a string representation of the CodeLenses.
25+
* Check a subset of the fields in CodeLenses
2226
*/
23-
toString(codelenses),
24-
`
25-
[
26-
{
27-
"command": "ada.buildAndRunMain",
28-
"title": "$(run) Run",
29-
"arguments": [
30-
"src/main1.adb"
31-
]
32-
},
33-
{
34-
"command": "ada.buildAndDebugMain",
35-
"title": "$(debug-alt-small) Debug",
36-
"arguments": [
37-
"src/main1.adb"
38-
]
39-
}
40-
]`.trim()
27+
codelenses?.map((v) => ({
28+
...v.command,
29+
// The argument is expected to be a Uri, in which case use the
30+
// normalized fsPath for comparison with the expected result
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
32+
arguments: v.command?.arguments?.map((a) => (a instanceof Uri ? a.fsPath : a)),
33+
})),
34+
[
35+
{
36+
command: 'ada.buildAndRunMain',
37+
title: '$(run) Run',
38+
arguments: [mainUri.fsPath],
39+
},
40+
{
41+
command: 'ada.buildAndDebugMain',
42+
title: '$(debug-alt-small) Debug',
43+
arguments: [mainUri.fsPath],
44+
},
45+
]
4146
);
4247
});
4348

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

+82-89
Original file line numberDiff line numberDiff line change
@@ -10,83 +10,82 @@ import { activate } from '../utils';
1010
import { adaExtState } from '../../../src/extension';
1111

1212
suite('Debug Configurations', function () {
13-
let expectedConfigs: string;
13+
let expectedConfigs: AdaConfig[];
1414

1515
this.beforeAll(async () => {
1616
await activate();
17-
expectedConfigs = `
18-
[
19-
{
20-
"type": "cppdbg",
21-
"name": "Ada: Debug main - src/main1.adb",
22-
"request": "launch",
23-
"targetArchitecture": "x64",
24-
"cwd": "\${workspaceFolder}",
25-
"program": "\${workspaceFolder}/obj/main1exec${exe}",
26-
"stopAtEntry": false,
27-
"externalConsole": false,
28-
"args": [],
29-
"MIMode": "gdb",
30-
"preLaunchTask": "ada: Build main - src/main1.adb",
31-
"setupCommands": [
32-
{
33-
"description": "Catch all Ada exceptions",
34-
"text": "catch exception",
35-
"ignoreFailures": true
36-
},
37-
{
38-
"description": "Enable pretty-printing for gdb",
39-
"text": "-enable-pretty-printing",
40-
"ignoreFailures": true
41-
}
42-
],
43-
"miDebuggerPath": "${getOrFindGdb()?.replace(/\\/g, '\\\\') ?? '<undefined>'}"
44-
},
45-
{
46-
"name": "Ada: Attach debugger to running process - src/main1.adb",
47-
"type": "cppdbg",
48-
"request": "attach",
49-
"program": "\${workspaceFolder}/obj/main1exec${exe}",
50-
"processId": "\${command:pickProcess}",
51-
"MIMode": "gdb",
52-
"miDebuggerPath": "${getOrFindGdb()?.replace(/\\/g, '\\\\') ?? '<undefined>'}"
53-
},
54-
{
55-
"type": "cppdbg",
56-
"name": "Ada: Debug main - src/test.adb",
57-
"request": "launch",
58-
"targetArchitecture": "x64",
59-
"cwd": "\${workspaceFolder}",
60-
"program": "\${workspaceFolder}/obj/test${exe}",
61-
"stopAtEntry": false,
62-
"externalConsole": false,
63-
"args": [],
64-
"MIMode": "gdb",
65-
"preLaunchTask": "ada: Build main - src/test.adb",
66-
"setupCommands": [
67-
{
68-
"description": "Catch all Ada exceptions",
69-
"text": "catch exception",
70-
"ignoreFailures": true
71-
},
72-
{
73-
"description": "Enable pretty-printing for gdb",
74-
"text": "-enable-pretty-printing",
75-
"ignoreFailures": true
76-
}
77-
],
78-
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
79-
},
80-
{
81-
"name": "Ada: Attach debugger to running process - src/test.adb",
82-
"type": "cppdbg",
83-
"request": "attach",
84-
"program": "\${workspaceFolder}/obj/test${exe}",
85-
"processId": "\${command:pickProcess}",
86-
"MIMode": "gdb",
87-
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
88-
}
89-
]`;
17+
expectedConfigs = [
18+
{
19+
type: 'cppdbg',
20+
name: 'Ada: Debug main - src/main1.adb',
21+
request: 'launch',
22+
targetArchitecture: 'x64',
23+
cwd: '${workspaceFolder}',
24+
program: '${workspaceFolder}/obj/main1exec' + exe,
25+
stopAtEntry: false,
26+
externalConsole: false,
27+
args: [],
28+
MIMode: 'gdb',
29+
preLaunchTask: 'ada: Build main - src/main1.adb',
30+
setupCommands: [
31+
{
32+
description: 'Catch all Ada exceptions',
33+
text: 'catch exception',
34+
ignoreFailures: true,
35+
},
36+
{
37+
description: 'Enable pretty-printing for gdb',
38+
text: '-enable-pretty-printing',
39+
ignoreFailures: true,
40+
},
41+
],
42+
miDebuggerPath: getOrFindGdb() ?? '<undefined>',
43+
},
44+
{
45+
name: 'Ada: Attach debugger to running process - src/main1.adb',
46+
type: 'cppdbg',
47+
request: 'attach',
48+
program: '${workspaceFolder}/obj/main1exec' + exe,
49+
processId: '${command:pickProcess}',
50+
MIMode: 'gdb',
51+
miDebuggerPath: getOrFindGdb() ?? '<undefined>',
52+
},
53+
{
54+
type: 'cppdbg',
55+
name: 'Ada: Debug main - src/test.adb',
56+
request: 'launch',
57+
targetArchitecture: 'x64',
58+
cwd: '${workspaceFolder}',
59+
program: '${workspaceFolder}/obj/test' + exe,
60+
stopAtEntry: false,
61+
externalConsole: false,
62+
args: [],
63+
MIMode: 'gdb',
64+
preLaunchTask: 'ada: Build main - src/test.adb',
65+
setupCommands: [
66+
{
67+
description: 'Catch all Ada exceptions',
68+
text: 'catch exception',
69+
ignoreFailures: true,
70+
},
71+
{
72+
description: 'Enable pretty-printing for gdb',
73+
text: '-enable-pretty-printing',
74+
ignoreFailures: true,
75+
},
76+
],
77+
miDebuggerPath: getOrFindGdb() ?? '<undefined>',
78+
},
79+
{
80+
name: 'Ada: Attach debugger to running process - src/test.adb',
81+
type: 'cppdbg',
82+
request: 'attach',
83+
program: '${workspaceFolder}/obj/test' + exe,
84+
processId: '${command:pickProcess}',
85+
MIMode: 'gdb',
86+
miDebuggerPath: getOrFindGdb() ?? '<undefined>',
87+
},
88+
];
9089
});
9190

9291
test('GDB path is explicitely set in offered debug config', async () => {
@@ -136,24 +135,18 @@ All of the above - Create all of the above configurations in the launch.json fil
136135
expected.trim()
137136
);
138137

139-
assert.equal(
140-
JSON.stringify(
141-
quickpick
142-
.filter((e) => 'conf' in e)
143-
.map((e) => {
144-
assert('conf' in e);
145-
return e.conf;
146-
}),
147-
null,
148-
2
149-
).trim(),
150-
expectedConfigs.trim()
151-
);
138+
const actualConfigs = quickpick
139+
.filter((e) => 'conf' in e)
140+
.map((e) => {
141+
assert('conf' in e);
142+
return e.conf;
143+
});
144+
145+
assert.deepEqual(actualConfigs, expectedConfigs);
152146
});
153147

154148
test('Dynamic', async () => {
155149
const configs = await adaExtState.dynamicDebugConfigProvider.provideDebugConfigurations();
156-
157-
assert.equal(JSON.stringify(configs, undefined, 2).trim(), expectedConfigs.trim());
150+
assert.deepEqual(configs, expectedConfigs);
158151
});
159152
});

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import assert from 'assert';
33
import path from 'path';
44
import * as vscode from 'vscode';
55
import { getEnclosingSymbol, getSelectedRegion } from '../../../src/commands';
6-
import { getProjectFile } from '../../../src/helpers';
6+
import { exe, getProjectFile } from '../../../src/helpers';
77
import {
88
SimpleTaskDef,
99
createAdaTaskProvider,
@@ -60,9 +60,9 @@ ada: Create a report after a GNAT SAS analysis - gnatsas report sarif -P ${proje
6060
ada: Generate documentation from the project - gnatdoc -P ${projectPath}
6161
ada: Create/update test skeletons for the project - gnattest -P ${projectPath}
6262
ada: Build main - src/main1.adb - gprbuild -P ${projectPath} src/main1.adb -cargs:ada -gnatef
63-
ada: Run main - src/main1.adb - obj/main1exec
63+
ada: Run main - src/main1.adb - obj/main1exec${exe}
6464
ada: Build main - src/test.adb - gprbuild -P ${projectPath} src/test.adb -cargs:ada -gnatef
65-
ada: Run main - src/test.adb - obj/test
65+
ada: Run main - src/test.adb - obj/test${exe}
6666
`.trim();
6767

6868
const prov = createAdaTaskProvider();

integration/vscode/ada/test/workspaces/general/default_without_obj_dir/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/b__*.ad?
88
/*.bexch
99
/main1exec
10+
/main1exec.exe

0 commit comments

Comments
 (0)