Skip to content

Commit 82fb3cf

Browse files
committed
Add args options to VS code tasks
Closes eng/ide/ada_language_server#1113
1 parent fe16f74 commit 82fb3cf

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ You can bind keyboard shortcuts to them by adding to the `keybindings.json` file
174174

175175
[A demo for auto-detected tasks](https://github.com/AdaCore/ada_language_server/wiki/auto_detected_tasks.mp4)
176176

177+
#### Task customization
178+
You can [customize autodetected tasks](https://code.visualstudio.com/docs/editor/tasks#_customizing-autodetected-tasks)
179+
by providing extra tool command line options via `args` property in the `tasks.json`:
180+
181+
```json
182+
{
183+
"version": "2.0.0",
184+
"tasks": [
185+
{
186+
"type": "gnat",
187+
"taskKind": "buildProject",
188+
"problemMatcher": [
189+
"$ada"
190+
],
191+
"group": "build",
192+
"label": "ada: Build project",
193+
"args": ["-gargs", "-vh"]
194+
}
195+
]
196+
}
197+
```
198+
177199
### Commands and shortcuts
178200

179201
The extension contributes a few commands and corresponding key bindings.

integration/vscode/Code Samples/hello/.vscode/tasks.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "build",
8-
"type": "shell",
9-
"command": "gprbuild",
10-
"args": [
11-
"-p",
12-
"-P",
13-
"${config:ada.projectFile}",
14-
"-cargs",
15-
"-gnatef"
7+
"type": "gnat",
8+
"taskKind": "buildProject",
9+
"problemMatcher": [
10+
"$ada"
1611
],
17-
"problemMatcher": ["$ada"],
18-
"group": {
19-
"kind": "build",
20-
"isDefault": true
21-
}
12+
"group": "build",
13+
"label": "ada: Build project",
14+
"args": ["-gargs", "-q"]
2215
}
2316
]
2417
}

integration/vscode/ada/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@
379379
"taskKind": {
380380
"type": "string",
381381
"description": "Tool and action kind"
382+
},
383+
"args": {
384+
"type": "array",
385+
"description": "Extra command arguments"
382386
}
383387
}
384388
}

integration/vscode/ada/src/gnatTaskProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,14 @@ export default class GnatTaskProvider implements vscode.TaskProvider<vscode.Task
190190
// Check if the task in our known task
191191
if (definition.taskKind in knownTaskKinds) {
192192
const item: TaskProperties = knownTaskKinds[String(definition.taskKind)];
193+
const extraArgs: string[] = Array.isArray(definition.args)
194+
? definition.args.map((x) => String(x))
195+
: [];
193196
if (item.extra) {
194197
// We have a callback, evaluate it to get an extra argument and
195198
// wrap all args with getGnatArgs
196199
return item.extra().then((extra) => {
197-
const args = getGnatArgs(item.args.concat(extra ? [extra] : []));
200+
const args = getGnatArgs(item.args.concat(extraArgs, extra ? [extra] : []));
198201
const shell = new vscode.ShellExecution(item.tool, args);
199202
return new vscode.Task(
200203
definition,
@@ -206,7 +209,7 @@ export default class GnatTaskProvider implements vscode.TaskProvider<vscode.Task
206209
);
207210
});
208211
} else {
209-
const shell = new vscode.ShellExecution(item.tool, item.args);
212+
const shell = new vscode.ShellExecution(item.tool, item.args.concat(extraArgs));
210213
return new vscode.Task(
211214
definition,
212215
vscode.TaskScope.Workspace, // scope

0 commit comments

Comments
 (0)