Skip to content

Commit b1e686e

Browse files
authored
adding support for the help command (#592)
1 parent b90f48a commit b1e686e

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

.changeset/fuzzy-mangos-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@neo4j-cypher/language-support': patch
3+
---
4+
5+
adding support for the help command

packages/language-support/src/antlr-grammar/CypherCmdLexer.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ RESET: R E S E T;
2222

2323
PLAY: P L A Y;
2424

25-
ACCESSMODE: A C C E S S '-' M O D E;
25+
ACCESSMODE: A C C E S S '-' M O D E;
26+
27+
HELP: H E L P;

packages/language-support/src/antlr-grammar/CypherCmdParser.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ consoleCommand: COLON (
2121
| styleCmd
2222
| playCmd
2323
| accessModeCmd
24+
| helpCmd
2425
);
2526

2627
paramsCmd: PARAM paramsArgs?;
@@ -55,6 +56,8 @@ accessModeArgs: (readCompletionRule | writeCompletionRule);
5556

5657
accessModeCmd: ACCESSMODE accessModeArgs?;
5758

59+
helpCmd: HELP;
60+
5861
// These rules are needed to distinguish cypher <-> commands, for exapmle `USE` and `:use` in autocompletion
5962
listCompletionRule: LIST;
6063

packages/language-support/src/lexerSymbols.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ export const lexerConsoleCmds = [
407407
CypherLexer.RESET,
408408
CypherLexer.PLAY,
409409
CypherLexer.ACCESSMODE,
410+
CypherLexer.HELP,
410411
];
411412

412413
function toTokentypeObject(arr: number[], tokenType: CypherTokenType) {

packages/language-support/src/parserWrapper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ export type ParsedCommandNoPosition =
566566
| { type: 'sysinfo' }
567567
| { type: 'style'; operation?: 'reset' }
568568
| { type: 'play' }
569-
| { type: 'access-mode'; operation?: string };
569+
| { type: 'access-mode'; operation?: string }
570+
| { type: 'help' };
570571

571572
export type ParsedCommand = ParsedCommandNoPosition & RuleTokens;
572573

@@ -759,6 +760,11 @@ function parseToCommand(
759760
}
760761
}
761762

763+
const helpCmd = consoleCmd.helpCmd();
764+
if (helpCmd) {
765+
return { type: 'help', start, stop };
766+
}
767+
762768
return { type: 'parse-error', start, stop };
763769
}
764770
const stopToken = stop ?? tokens.at(-1);

packages/language-support/src/tests/consoleCommands.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('sanity checks', () => {
5555
expectParsedCommands(':sysinfo', [{ type: 'sysinfo' }]);
5656
expectParsedCommands(':style', [{ type: 'style' }]);
5757
expectParsedCommands(':play', [{ type: 'play' }]);
58+
expectParsedCommands(':help', [{ type: 'help' }]);
5859
});
5960

6061
test('properly highlights simple commands', () => {
@@ -218,12 +219,28 @@ describe('sanity checks', () => {
218219
tokenType: 'consoleCommand',
219220
},
220221
]);
222+
223+
expect(applySyntaxColouring(':help')).toEqual([
224+
{
225+
length: 1,
226+
position: { line: 0, startCharacter: 0, startOffset: 0 },
227+
token: ':',
228+
tokenType: 'consoleCommand',
229+
},
230+
{
231+
length: 4,
232+
position: { line: 0, startCharacter: 1, startOffset: 1 },
233+
token: 'help',
234+
tokenType: 'consoleCommand',
235+
},
236+
]);
221237
});
222238

223239
test('completes basic console cmds on :', () => {
224240
expect(autocomplete(':', {})).toEqual([
225241
{ kind: 23, label: 'server' },
226242
{ kind: 23, label: 'use' },
243+
{ kind: 23, label: 'help' },
227244
{ kind: 23, label: 'access-mode' },
228245
{ kind: 23, label: 'play' },
229246
{ kind: 23, label: 'style' },
@@ -270,7 +287,7 @@ describe('sanity checks', () => {
270287
test('handles misspelled or non-existing command', () => {
271288
expectErrorMessage(
272289
':foo',
273-
'Expected any of access-mode, play, style, sysinfo, welcome, disconnect, connect, param, history, clear, server or use',
290+
'Expected any of help, access-mode, play, style, sysinfo, welcome, disconnect, connect, param, history, clear, server or use',
274291
);
275292

276293
expectErrorMessage(':clea', 'Unexpected token. Did you mean clear?');

0 commit comments

Comments
 (0)