Skip to content

Commit f9b6265

Browse files
Add file template for GPR files
For eng/ide/ada_language_server#1515
1 parent 127466d commit f9b6265

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ section below it for the last release. -->
1212
* [GNATformat](https://github.com/AdaCore/gnatformat) is now the default back-end for LSP formatting requests
1313
* Add tasks and a CodeLens to run and debug a given main with GNATemulator on non-native projects
1414
* Diagnostics are now emitted for issues encountered when trying to load an Alire crate
15-
* Commands to create a new main units and packages have been added, both available under the `File->New File...` menu
15+
* Commands to create a new main units, packages and GPR project files have
16+
been added, both available under the `File->New File...` menu
1617
* Add VS Code command `ada: GNATcoverage - Load an existing XML coverage report` for importing coverage reports
1718
* Support running GNATtest tests in coverage mode
1819

integration/vscode/ada/gpr-snippets.json

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
{
22
"Case Statement": {
3-
"prefix": "case",
4-
"scope": "gpr",
5-
"body": [
6-
"case ${1:Variable} is",
7-
"\twhen \"${3:Condition}\" =>",
8-
"\t\t$0",
9-
"\twhen others =>",
10-
"\t\t$2",
11-
"end case;"
12-
],
13-
"description": "Case Statement"
3+
"prefix": "case",
4+
"scope": "gpr",
5+
"body": [
6+
"case ${1:Variable} is",
7+
"\twhen \"${3:Condition}\" =>",
8+
"\t\t$0",
9+
"\twhen others =>",
10+
"\t\t$2",
11+
"end case;"
12+
],
13+
"description": "Case Statement"
1414
},
1515
"Package Declaration": {
16-
"prefix": "package",
17-
"scope": "gpr",
18-
"body": [
19-
"package ${1|Binder,Builder,Check,Clean,Compiler,Cross_Reference,Documentation,Eliminate,Finder,Gnatls,Gnatstub,IDE,Install,Linker,Metrics,Naming,Pretty_Printer,Remote,Stack,Synchronize|} is",
20-
"\t$0",
21-
"end $1;"
22-
],
23-
"description": "Package Declaration"
24-
},
16+
"prefix": "package",
17+
"scope": "gpr",
18+
"body": [
19+
"package ${1|Binder,Builder,Check,Clean,Compiler,Cross_Reference,Documentation,Eliminate,Finder,Gnatls,Gnatstub,IDE,Install,Linker,Metrics,Naming,Pretty_Printer,Remote,Stack,Synchronize|} is",
20+
"\t$0",
21+
"end $1;"
22+
],
23+
"description": "Package Declaration"
24+
},
2525
"Package Extension": {
26-
"prefix": "package",
27-
"scope": "gpr",
28-
"body": [
29-
"package ${1:Name} extends ${2} is",
30-
"\t$0",
31-
"end $1;"
32-
],
33-
"description": "Package Extension"
34-
},
26+
"prefix": "package",
27+
"scope": "gpr",
28+
"body": ["package ${1:Name} extends ${2} is", "\t$0", "end $1;"],
29+
"description": "Package Extension"
30+
},
3531
"Project Declaration": {
3632
"prefix": "project",
3733
"scope": "gpr",

integration/vscode/ada/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,11 @@
784784
"title": "Ada: Create Package",
785785
"shortTitle": "Ada Package"
786786
},
787+
{
788+
"command": "ada.createNewGPRProjectFile",
789+
"title": "Ada: Create GPR Project File",
790+
"shortTitle": "GPR Project File"
791+
},
787792
{
788793
"command": "ada.otherFile",
789794
"title": "Ada: Go to other file"
@@ -937,6 +942,10 @@
937942
{
938943
"command": "ada.createNewAdaPackage",
939944
"group": "ada"
945+
},
946+
{
947+
"command": "ada.createNewGPRProjectFile",
948+
"group": "ada"
940949
}
941950
]
942951
},

integration/vscode/ada/src/commands.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ export function registerCommands(context: vscode.ExtensionContext, clients: Exte
9696
context.subscriptions.push(vscode.commands.registerCommand('ada.otherFile', otherFileHandler));
9797
context.subscriptions.push(
9898
vscode.commands.registerCommand('ada.createNewAdaMainUnit', () =>
99-
createNewAdaFile('Main Procedure'),
99+
createNewFile('ada', 'Main Procedure'),
100100
),
101101
);
102102
context.subscriptions.push(
103103
vscode.commands.registerCommand('ada.createNewAdaPackage', () =>
104-
createNewAdaFile('Package Declaration or Body'),
104+
createNewFile('ada', 'Package Declaration or Body'),
105+
),
106+
);
107+
context.subscriptions.push(
108+
vscode.commands.registerCommand('ada.createNewGPRProjectFile', () =>
109+
createNewFile('gpr', 'Project Declaration'),
105110
),
106111
);
107112
context.subscriptions.push(
@@ -463,17 +468,19 @@ async function buildAndRunMainAsk() {
463468
}
464469

465470
/**
466-
* Handler for commands that create new Ada files.
467-
* This function creates a new Ada editor, focus it, and insert the specified snippet.
468-
* Used to proivide Ada file templates.
471+
* Handler for commands that create new files.
472+
* This function creates a new editor for the given language, focus it,
473+
* and insert the specified snippet.
474+
* Used to proivide Ada/GPR file templates.
469475
*
476+
* @param langId - the new file's language ID (e.g: 'ada' or 'gpr')
470477
* @param snippetName - the name of the snippet to insert in the newly created editor.
471478
*/
472-
async function createNewAdaFile(snippetName: string) {
479+
async function createNewFile(langId: string, snippetName: string) {
473480
const doc = await vscode.workspace.openTextDocument({ language: 'ada' });
474481
await vscode.window.showTextDocument(doc);
475482
await vscode.commands.executeCommand('editor.action.insertSnippet', {
476-
langId: 'ada',
483+
langId: langId,
477484
name: snippetName,
478485
});
479486
}

0 commit comments

Comments
 (0)