Skip to content

Commit e59acdb

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 0075e89 + c21038b commit e59acdb

File tree

7 files changed

+104
-14
lines changed

7 files changed

+104
-14
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extension at
5858
- [Ada: Go to other file](#ada-go-to-other-file)
5959
- [Ada: Add subprogram box](#ada-add-subprogram-box)
6060
- [Ada: Reload project](#ada-reload-project)
61+
- [Tasks with keyboard shortcuts](#tasks-with-keyboard-shortcuts)
6162
- [Bug Reporting](#bug-reporting)
6263
- [Limitations and Differences with GNAT Studio](#limitations-and-differences-with-gnat-studio)
6364
- [Integration with other editors and IDEs](#integration-with-other-editors-and-ides)
@@ -331,6 +332,30 @@ The default shortcut is `Alt+Shift+B`.
331332
This command reloads the current project.
332333
The default shortcut is `None`.
333334

335+
#### Tasks with keyboard shortcuts
336+
337+
The following default shortcuts are provided for tasks:
338+
339+
| Task | Shortcut |
340+
|--------------------------------|-----------------|
341+
| `spark: Prove file` | `Meta+Y Meta+F` |
342+
| `spark: Prove subprogram` | `Meta+Y Meta+S` |
343+
| `spark: Prove selected region` | `Meta+Y Meta+R` |
344+
| `spark: Prove line` | `Meta+Y Meta+L` |
345+
346+
`Meta` = ⌘ on macOS, `Win` on Windows, `Meta` on Linux
347+
348+
These shortcuts can be customized and new shortcuts can be added for other tasks by using the command `Preferences: Open Keyboard Shortcuts (JSON)` and adding entries like the following example:
349+
350+
```json
351+
{
352+
"command": "workbench.action.tasks.runTask",
353+
"args": "ada: Check current file",
354+
"key": "meta+y meta+c",
355+
"when": "editorLangId == ada && editorTextFocus"
356+
}
357+
```
358+
334359
### Bug Reporting
335360

336361
You can use the VS Code `Issue Reporter` to report issues. Just click on the `Help -> Report Issue` menu, select `An extension` for the `File on` entry and `Language Support for Ada` for the extension name. Put as many information you can in the description, like steps to reproduce, stacktraces or system information (VS Code automatically includes it by default). This will create a GitHub issue in the [Ada Language Server](https://github.com/AdaCore/ada_language_server/) repository.

integration/vscode/ada/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,30 @@
787787
"command": "ada.subprogramBox",
788788
"key": "alt+shift+B",
789789
"when": "editorLangId == ada && editorTextFocus"
790+
},
791+
{
792+
"command": "workbench.action.tasks.runTask",
793+
"args": "spark: Prove file",
794+
"key": "meta+y meta+f",
795+
"when": "editorLangId == ada && editorTextFocus"
796+
},
797+
{
798+
"command": "workbench.action.tasks.runTask",
799+
"args": "spark: Prove subprogram",
800+
"key": "meta+y meta+s",
801+
"when": "editorLangId == ada && editorTextFocus"
802+
},
803+
{
804+
"command": "workbench.action.tasks.runTask",
805+
"args": "spark: Prove selected region",
806+
"key": "meta+y meta+r",
807+
"when": "editorLangId == ada && editorTextFocus"
808+
},
809+
{
810+
"command": "workbench.action.tasks.runTask",
811+
"args": "spark: Prove line",
812+
"key": "meta+y meta+l",
813+
"when": "editorLangId == ada && editorTextFocus"
790814
}
791815
],
792816
"menus": {

integration/vscode/ada/src/commands.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,9 @@ function getLimitSubpArg(filename: string, range: vscode.Range) {
684684
* to the current editor's selection.
685685
*/
686686
export const sparkLimitRegionArg = (): Promise<string[]> => {
687-
return new Promise((resolve) => {
688-
resolve([
689-
`--limit-region=\${fileBasename}:${getSelectedRegion(vscode.window.activeTextEditor)}`,
690-
]);
691-
});
687+
return Promise.resolve([
688+
`--limit-region=\${fileBasename}:${getSelectedRegion(vscode.window.activeTextEditor)}`,
689+
]);
692690
};
693691

694692
/**
@@ -711,6 +709,10 @@ export const getSelectedRegion = (editor: vscode.TextEditor | undefined): string
711709
/**
712710
* Return the closest DocumentSymbol of the given kinds enclosing the
713711
* the given editor's cursor position, if any.
712+
*
713+
* If the given editor is undefined or not on an Ada file, the function returns
714+
* `null` immediately.
715+
*
714716
* @param editor - The editor in which we want
715717
* to find the closest symbol enclosing the cursor's position.
716718
* @returns Return the closest enclosing symbol.
@@ -720,7 +722,7 @@ export async function getEnclosingSymbol(
720722
editor: vscode.TextEditor | undefined,
721723
kinds: vscode.SymbolKind[]
722724
): Promise<vscode.DocumentSymbol | null> {
723-
if (editor) {
725+
if (editor && editor.document.languageId == 'ada') {
724726
const line = editor.selection.active.line;
725727

726728
// First get all symbols for current file
@@ -758,6 +760,12 @@ export async function getEnclosingSymbol(
758760
*
759761
* It is implemented by fetching the 'Prove subbprogram' task and using it as a
760762
* template such that the User can customize the task to impact the CodeLens.
763+
*
764+
* Another option could have been to use the command
765+
* `workbench.action.tasks.runTask` with the name of the SPARK task as argument
766+
* however that would run the task using the current cursor location which may
767+
* not match the CodeLens that was triggered. So it is better to create a task
768+
* dedicated to the location of the CodeLens.
761769
*/
762770
async function sparkProveSubprogram(
763771
uri: vscode.Uri,

integration/vscode/ada/src/extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ import {
3131
getEvaluatedTerminalEnv,
3232
startedInDebugMode,
3333
} from './helpers';
34+
/**
35+
* This import gives access to the package.json content.
36+
*/
37+
import * as meta from '../package.json';
38+
39+
// eslint-disable-next-line max-len
40+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
41+
export const EXTENSION_NAME: string = meta.displayName;
3442

3543
const ADA_CONTEXT = 'ADA_PROJECT_CONTEXT';
3644

integration/vscode/ada/src/helpers.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import { CancellationError, CancellationToken, DocumentSymbol, SymbolKind } from
2222
import { LanguageClient } from 'vscode-languageclient/node';
2323
import winston from 'winston';
2424
// eslint-disable-next-line @typescript-eslint/no-unused-vars
25-
import { ExtensionState } from './ExtensionState';
26-
import { adaExtState, logger } from './extension';
2725
import { existsSync } from 'fs';
26+
import { ExtensionState } from './ExtensionState';
27+
import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension';
2828

2929
/**
3030
* Substitue any variable reference present in the given string. VS Code
@@ -480,3 +480,22 @@ export function which(execName: string) {
480480

481481
return exePath;
482482
}
483+
484+
/**
485+
* Show an error message with a button "Open Log" that opens the main extension
486+
* log (not the Ada LS or the GPR LS)
487+
*
488+
* @param msg - the message to display
489+
* @param options - message options to pass to {@link vscode.window.showErrorMessage}
490+
*/
491+
export async function showErrorMessageWithOpenLogButton(
492+
msg: string,
493+
options?: vscode.MessageOptions
494+
) {
495+
const answer = await vscode.window.showErrorMessage<vscode.MessageItem>(msg, options ?? {}, {
496+
title: `Open ${EXTENSION_NAME} Extension Log`,
497+
});
498+
if (answer) {
499+
mainOutputChannel.show();
500+
}
501+
}

integration/vscode/ada/src/taskProviders.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import assert from 'assert';
1919
import { basename } from 'path';
2020
import * as vscode from 'vscode';
2121
import { CMD_GPR_PROJECT_ARGS } from './commands';
22-
import { adaExtState } from './extension';
23-
import { AdaMain, getAdaMains } from './helpers';
22+
import { adaExtState, logger } from './extension';
23+
import { AdaMain, getAdaMains, showErrorMessageWithOpenLogButton } from './helpers';
2424

2525
export const TASK_TYPE_ADA = 'ada';
2626
export const TASK_TYPE_SPARK = 'spark';
@@ -462,9 +462,12 @@ export class SimpleTaskProvider implements vscode.TaskProvider {
462462
* resolved tasks, hence we must resolve pre-defined tasks here.
463463
*/
464464
const resolvedTask = await this.resolveTask(task, token);
465-
assert(resolvedTask);
466465

467-
result.push(resolvedTask);
466+
if (resolvedTask) {
467+
result.push(resolvedTask);
468+
} else {
469+
logger.error(`Failed to resolve task: ${JSON.stringify(task, undefined, 2)}`);
470+
}
468471
}
469472

470473
return result;
@@ -520,10 +523,12 @@ export class SimpleTaskProvider implements vscode.TaskProvider {
520523
execution = new vscode.ShellExecution(taskDef.command, evaluatedArgs);
521524
} catch (err) {
522525
let msg = 'Error while evaluating task arguments.';
526+
logger.error(msg);
527+
logger.error(err);
523528
if (err instanceof Error) {
524529
msg += ' ' + err.message;
525530
}
526-
void vscode.window.showErrorMessage(msg);
531+
void showErrorMessageWithOpenLogButton(msg);
527532
return undefined;
528533
}
529534
}

integration/vscode/ada/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"forceConsistentCasingInFileNames": true,
1616
"noImplicitReturns": true,
1717
"noFallthroughCasesInSwitch": true,
18-
"noUnusedParameters": true
18+
"noUnusedParameters": true,
19+
"resolveJsonModule": true
1920
},
2021
"exclude": ["node_modules", "out"],
2122
"include": ["test", "src"]

0 commit comments

Comments
 (0)