Skip to content

Commit 872dd82

Browse files
Add onEnterRule to split long comments
When pressing ENTER in the middle of an Ada comment, a comment tag will now automatically be added to the next line. This is useful to split comments that exceeds the line characters' limit. For eng/ide/ada_language_server#1662
1 parent 1d8509a commit 872dd82

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ section below it for the last release. -->
55

66
## \<next>
77

8+
* Added `onEnterRules` for Ada/GPR files to split long comments by adding automatically a comment tag to the next line
9+
810
## 26.0.202504171
911

1012
* Various improvements and bug fixes related to the GNATcoverage integration

integration/vscode/ada/gpr-language-configuration.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"lineComment": "--"
55
},
66
// symbols used as brackets
7-
"brackets": [
8-
["(", ")"]
9-
],
7+
"brackets": [["(", ")"]],
108
// symbols that are auto closed when typing
119
"autoClosingPairs": [
1210
["(", ")"],
@@ -16,5 +14,22 @@
1614
"surroundingPairs": [
1715
["(", ")"],
1816
["\"", "\""]
17+
],
18+
// Used to split long comments easily: when a user presses ENTER
19+
// in the middle of a GPR comment, '-- ' will automatically be added
20+
// to the next line.
21+
"onEnterRules": [
22+
{
23+
"beforeText": {
24+
"pattern": "--\\s+"
25+
},
26+
"afterText": {
27+
"pattern": "\\S+"
28+
},
29+
"action": {
30+
"indent": "none",
31+
"appendText": "-- "
32+
}
33+
}
1934
]
20-
}
35+
}

integration/vscode/ada/language-configuration.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"lineComment": "-- "
55
},
66
// symbols used as brackets
7-
"brackets": [
8-
["(", ")"]
9-
],
7+
"brackets": [["(", ")"]],
108
// symbols that are auto closed when typing
119
"autoClosingPairs": [
1210
["<<", ">>"],
@@ -23,5 +21,22 @@
2321
["(", ")"],
2422
["\"", "\""],
2523
["'", "'"]
24+
],
25+
// Used to split long comments easily: when a user presses ENTER
26+
// in the middle of an Ada comment, '-- ' will automatically be added
27+
// to the next line.
28+
"onEnterRules": [
29+
{
30+
"beforeText": {
31+
"pattern": "--\\s+"
32+
},
33+
"afterText": {
34+
"pattern": "\\S+"
35+
},
36+
"action": {
37+
"indent": "none",
38+
"appendText": "-- "
39+
}
40+
}
2641
]
2742
}

integration/vscode/ada/test/general/extension.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from 'assert';
22
import { adaExtState } from '../../src/extension';
33
import { getObjectDir, TERMINAL_ENV_SETTING_NAME } from '../../src/helpers';
4-
import { activate, assertEqualToFileContent } from '../utils';
4+
import { activate, assertEqualToFileContent, showTextDocument } from '../utils';
55

66
import { readFileSync, writeFileSync } from 'fs';
77
import * as vscode from 'vscode';
@@ -212,4 +212,30 @@ suite('Extensions Test Suite', function () {
212212
throw new Error('No workspace folder found for the specified URI');
213213
}
214214
});
215+
216+
test('Split long comments on ENTER', async () => {
217+
if (vscode.workspace.workspaceFolders !== undefined) {
218+
// Get a file with a long comment (>80 chars)
219+
const srcRelPath = ['src', 'split_comment.ads'];
220+
const textEditor = await showTextDocument(...srcRelPath);
221+
222+
// Set the cursor in the middle of the long comment
223+
const insertPos = new vscode.Position(0, 69);
224+
textEditor.selection = new vscode.Selection(insertPos, insertPos);
225+
226+
// Simulate a keypress on the ENTER key
227+
const inputText = '\n';
228+
await vscode.commands.executeCommand('type', { text: inputText });
229+
230+
// Check that we now have two lines, and that the second line
231+
// starts with the '-- ' comment tag
232+
const text = textEditor.document.getText() ?? '';
233+
assert.strictEqual(
234+
text,
235+
"-- Used to test the VS Code extension 'onEnterRule' that splits long\n" +
236+
'-- comments when pressing ENTER\n',
237+
`Wrong text in the editor after pressing ENTER in the middle of a comment`,
238+
);
239+
}
240+
});
215241
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Used to test the VS Code extension 'onEnterRule' that splits long comments when pressing ENTER

0 commit comments

Comments
 (0)