Skip to content

Commit 6ef03e2

Browse files
committed
Merge branch 'topic/vscode-tasks' into 'master'
Simplify VS Code tasks and add GNAT {SAS,doc,test} tasks Closes #1233, #1279, #1163, #1316, #1359, and #1292 See merge request eng/ide/ada_language_server!1521
2 parents c2eed0b + a7b2201 commit 6ef03e2

38 files changed

+1711
-2001
lines changed

.vscode/settings.json.tmpl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@
7878
// Allow GitLab-specific Yaml tags in .gitlab-ci.yml
7979
"yaml.customTags": ["!reference sequence"],
8080
"triggerTaskOnSave.tasks": {
81-
"ada: Compile current file": ["*.adb"],
82-
"ada: Check current file": ["*.ads"]
81+
// To work with automatically provided tasks, they
82+
// must be provided without the `ada: ` prefix.
83+
"Compile current file": ["*.adb"],
84+
"Check current file": ["*.ads"]
8385
},
8486
"triggerTaskOnSave.restart": true,
8587
"files.watcherExclude": {
@@ -89,16 +91,23 @@
8991
"**/.hg/store/**": true,
9092
".obj/": true
9193
},
92-
"extension-test-runner.extractSettings": {
93-
"suite": ["describe", "suite"],
94-
"test": ["it", "test"],
95-
"extractWith": "syntax"
96-
},
94+
// The Extension Test Runner extension loads VS Code Mocha tests into the GUI
95+
// by evaluating the JS test sources. If that fails, the following snippet
96+
// switches it to a syntactic extraction which might will likely miss
97+
// dynamically defined tests but might crashes in test loading.
98+
// "extension-test-runner.extractSettings": {
99+
// "suite": ["describe", "suite"],
100+
// "test": ["it", "test"],
101+
// "extractWith": "syntax"
102+
// },
97103
"extension-test-runner.debugOptions": {
98104
"outFiles": [
99105
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
100106
"!**/node_modules/**"
101107
],
108+
"env": {
109+
"MOCHA_TIMEOUT": "0"
110+
},
102111
"preLaunchTask": "npm: watch - integration/vscode/ada"
103112
}
104113
}

.vscode/tasks.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
"problemMatcher": ["$ada"],
99
"group": "test"
1010
},
11-
{
12-
"type": "ada",
13-
"configuration": {
14-
"kind": "checkFile",
15-
"projectFile": "${config:ada.projectFile}"
16-
},
17-
"problemMatcher": ["$ada"],
18-
"group": "build",
19-
"label": "ada: Check current file"
20-
},
2111
{
2212
"type": "npm",
2313
"script": "watch",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TESTER=$(ROOTDIR)/.obj/tester/tester-run$(EXE)
3535
MOCHA_ALS_UPDATE=
3636

3737
GPRBUILD_EXTRA=
38-
GPRBUILD_FLAGS=-m -j4 $(GPRBUILD_EXTRA)
38+
GPRBUILD_FLAGS=-m -j0 $(GPRBUILD_EXTRA)
3939
GPRBUILD=gprbuild $(GPRBUILD_FLAGS) -XSUPERPROJECT=
4040
GPRCLEAN_EXTRA=
4141
GPRCLEAN=gprclean -XSUPERPROJECT= $(GPRCLEAN_EXTRA)

README.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ extension at
5151
- [Refactoring](#refactoring)
5252
- [Tasks](#tasks)
5353
- [Task Customization](#task-customization)
54+
- [Tasks for Project Mains](#tasks-for-project-mains)
55+
- [ALIRE Support](#alire-support)
5456
- [Commands and Shortcuts](#commands-and-shortcuts)
5557
- [Ada: Go to other file](#ada-go-to-other-file)
5658
- [Ada: Add subprogram box](#ada-add-subprogram-box)
@@ -190,6 +192,10 @@ The extension provides the following auto-detected tasks
190192
* `spark: Prove selected region` - launch `gnatprove` on the selected region in the current editor
191193
* `spark: Prove line` - launch `gnatprove` on the cursor line in the current editor
192194
* `spark: Clean project for proof` - launch `gnatprove` on the current GPR project to clean proof artefacts
195+
* `ada: Analyze the project with GNAT SAS`
196+
* `ada: Analyze the current file with GNAT SAS`
197+
* `ada: Create a report after a GNAT SAS analysis`
198+
* `ada: Analyze the project with GNAT SAS and produce a report`
193199

194200
You can bind keyboard shortcuts to them by adding to the `keybindings.json` file:
195201

@@ -205,27 +211,78 @@ You can bind keyboard shortcuts to them by adding to the `keybindings.json` file
205211
#### Task Customization
206212

207213
You can [customize auto-detected tasks](https://code.visualstudio.com/docs/editor/tasks#_customizing-autodetected-tasks)
208-
by providing extra tool command line options via the `args` property of the `configuration` object in the `tasks.json`:
214+
by providing extra tool command line options via the `args` property of the object in the `tasks.json`:
209215

210216
```json
211217
{
212218
"version": "2.0.0",
213219
"tasks": [
214220
{
215221
"type": "ada",
216-
"configuration": {
217-
"kind": "buildProject",
218-
"projectFile": "${config:ada.projectFile}",
219-
"args": ["-gargs", "-vh"]
222+
"command": "gprbuild",
223+
"args": [
224+
"${command:ada.gprProjectArgs}",
225+
"-cargs:ada",
226+
"-gnatef",
227+
"-gargs",
228+
"-vh"
229+
],
230+
"problemMatcher": ["$ada"],
231+
"group": "build",
232+
"label": "ada: Build current project"
233+
}
234+
]
235+
}
236+
```
237+
238+
You can also customize the working directory of the task or the environment variables via the `options` property:
239+
240+
```json
241+
{
242+
"version": "2.0.0",
243+
"tasks": [
244+
{
245+
"type": "ada",
246+
"command": "gprbuild",
247+
"args": [
248+
"${command:ada.gprProjectArgs}",
249+
"-cargs:ada",
250+
"-gnatef"
251+
],
252+
"options": {
253+
"cwd": "${workspaceFolder}/my/subdir",
254+
"env": {
255+
"MY_ENV_VAR": "value"
256+
}
220257
},
221258
"problemMatcher": ["$ada"],
222259
"group": "build",
223-
"label": "ada: Build current project with custom options"
260+
"label": "ada: Build current project"
224261
}
225262
]
226263
}
227264
```
228265

266+
#### Tasks for Project Mains
267+
268+
If your GPR project defines main programs via the project attribute `Main`, additional tasks are automatically provided for each defined main.
269+
For example, if the project defines a `main1.adb` and `main2.adb` located under the `src/` source directory, the following tasks will be available:
270+
271+
* `ada: Build main - src/main1.adb`
272+
* `ada: Run main - src/main1.adb`
273+
* `ada: Build and run main - src/main1.adb`
274+
* `ada: Build main - src/main2.adb`
275+
* `ada: Run main - src/main2.adb`
276+
* `ada: Build and run main - src/main2.adb`
277+
278+
#### ALIRE Support
279+
280+
When the workspace is an ALIRE project (i.e. it contains an `alire.toml` file), tasks automatically use standard ALIRE commands.
281+
282+
For example, the `ada: Build current project` task uses the command `alr build` and the `ada: Clean current project` task uses the command `alr clean`.
283+
284+
All other tasks use `alr exec -- ...` to execute the command in the environment provided by ALIRE.
285+
229286
### Commands and Shortcuts
230287

231288
The extension contributes commands and a few default key bindings.
@@ -259,12 +316,13 @@ The VS Code extension has a few limitations and some differences compared to [GN
259316
* **Indentation/formatting**: it does not support automatic indentation when adding a newline and range/document
260317
formatting might no succeed on incomplete/illegal code.
261318

262-
* **Tooling support**: we currently provide minimal support for *SPARK* (see *Prove/Examine* tasks in the [Auto-detected tasks](#auto-detected-tasks) section), but there is no support for tools such as *CodePeer*, *GNATcheck*, *GNATtest* or *GNATcoverage*.
319+
* **Tooling support**: we currently provide support for some *SPARK*, *GNATtest* and *GNAT SAS* [Tasks](#tasks), but there is no support for tools such as *GNATcheck* or *GNATcoverage* yet.
263320

264321
* **Alire support**: if the root folder contains an `alire.toml` file and
265322
there is `alr` executable in the `PATH`, then the language server fetches
266323
the project's search path, environment variables and the project's file
267-
name from the crate description.
324+
name from the crate description. [Tasks](#tasks) are also automatically
325+
invoked with ALIRE in this case.
268326

269327
* **Project support**: there is no `Scenario` view: users should configure scenarios via the *ada.scenarioVariables* setting (see the settings list available [here](doc/settings.md)). Saving the settings file after changing the values will automatically reload the project and update the
270328
predefined tasks to take into account the new scenario values.

integration/vscode/ada/.eslintrc.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@
1515
},
1616
"project": "tsconfig.json"
1717
},
18-
"plugins": [
19-
"@typescript-eslint/eslint-plugin",
20-
"eslint-plugin-tsdoc"
21-
],
18+
"plugins": ["@typescript-eslint/eslint-plugin", "eslint-plugin-tsdoc"],
2219
"extends": [
2320
"eslint:recommended",
2421
"plugin:@typescript-eslint/recommended",
2522
"plugin:@typescript-eslint/recommended-requiring-type-checking",
2623
"plugin:prettier/recommended"
2724
],
28-
"ignorePatterns": [
29-
"out",
30-
"**/*.d.ts"
31-
],
25+
"ignorePatterns": ["out", "**/*.d.ts"],
3226
"rules": {
3327
"tsdoc/syntax": "warn",
3428
"max-len": [
@@ -37,6 +31,7 @@
3731
"code": 100,
3832
"ignoreUrls": true
3933
}
40-
]
34+
],
35+
"@typescript-eslint/switch-exhaustiveness-check": "error"
4136
}
42-
}
37+
}

integration/vscode/ada/package.json

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,28 @@
479479
"taskDefinitions": [
480480
{
481481
"type": "ada",
482-
"required": [
483-
"configuration"
484-
],
482+
"when": "shellExecutionSupported",
485483
"properties": {
484+
"command": {
485+
"description": "The name of the command to call.",
486+
"type": "string"
487+
},
488+
"args": {
489+
"description": "The arguments to pass to the command.",
490+
"type": "array",
491+
"items": {
492+
"type": "string"
493+
}
494+
},
495+
"compound": {
496+
"description": "List of task names to be executed sequentially.",
497+
"type": "array",
498+
"items": {
499+
"type": "string"
500+
}
501+
},
486502
"configuration": {
503+
"deprecationMessage": "The task property 'configuration' is deprecated. Instead, use the properties 'command' and 'args' to configure the task.",
487504
"type": "object",
488505
"required": [
489506
"kind"
@@ -613,7 +630,26 @@
613630
},
614631
{
615632
"type": "spark",
633+
"when": "shellExecutionSupported",
616634
"properties": {
635+
"command": {
636+
"description": "The name of the command to call.",
637+
"type": "string"
638+
},
639+
"args": {
640+
"description": "The arguments to pass to the command.",
641+
"type": "array",
642+
"items": {
643+
"type": "string"
644+
}
645+
},
646+
"compound": {
647+
"description": "List of task names to be executed sequentially.",
648+
"type": "array",
649+
"items": {
650+
"type": "string"
651+
}
652+
},
617653
"configuration": {
618654
"type": "object",
619655
"required": [

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ export class ExtensionState {
3737
public readonly testData: Map<vscode.TestItem, object> = new Map();
3838

3939
/**
40-
* The following fields are caches for ALS requests
40+
* The following fields are caches for ALS requests or costly properties.
4141
*/
4242
cachedProjectFile: string | undefined;
4343
cachedObjectDir: string | undefined;
4444
cachedMains: string[] | undefined;
4545
cachedExecutables: string[] | undefined;
46+
cachedAlireTomls: vscode.Uri[] | undefined;
4647

4748
public clearALSCache() {
4849
this.cachedProjectFile = undefined;
4950
this.cachedObjectDir = undefined;
5051
this.cachedMains = undefined;
5152
this.cachedExecutables = undefined;
53+
this.cachedAlireTomls = undefined;
5254
}
5355

5456
constructor(context: vscode.ExtensionContext) {
@@ -205,4 +207,12 @@ export class ExtensionState {
205207

206208
return this.cachedExecutables;
207209
}
210+
211+
public async getAlireTomls(): Promise<vscode.Uri[]> {
212+
if (!this.cachedAlireTomls) {
213+
this.cachedAlireTomls = await vscode.workspace.findFiles('alire.toml');
214+
}
215+
216+
return this.cachedAlireTomls;
217+
}
208218
}

0 commit comments

Comments
 (0)