From c587b81ef1defd33fed52e6cbec1fb623e681727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Cord=C3=B3n?= Date: Mon, 27 Jan 2025 15:27:25 +0100 Subject: [PATCH] Fix bug using console commands as variables labels (#332) --- .changeset/serious-ducks-sleep.md | 5 + .../src/antlr-grammar/CypherCmdParser.g4 | 2 +- .../tests/syntaxColouring/preparser.test.ts | 240 ++++++++++++++++++ 3 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 .changeset/serious-ducks-sleep.md diff --git a/.changeset/serious-ducks-sleep.md b/.changeset/serious-ducks-sleep.md new file mode 100644 index 000000000..bb7137983 --- /dev/null +++ b/.changeset/serious-ducks-sleep.md @@ -0,0 +1,5 @@ +--- +'@neo4j-cypher/language-support': patch +--- + +Fixes bug using console commands as variables or labels diff --git a/packages/language-support/src/antlr-grammar/CypherCmdParser.g4 b/packages/language-support/src/antlr-grammar/CypherCmdParser.g4 index 014c2d4c0..f5068d21a 100644 --- a/packages/language-support/src/antlr-grammar/CypherCmdParser.g4 +++ b/packages/language-support/src/antlr-grammar/CypherCmdParser.g4 @@ -52,7 +52,7 @@ useCompletionRule: USE; serverCompletionRule: SERVER; // This rule overrides the identifiers adding EXPLAIN, PROFILE, etc -unescapedLabelSymbolicNameString: +unescapedSymbolicNameString: preparserKeyword | HISTORY | CLEAR diff --git a/packages/language-support/src/tests/syntaxColouring/preparser.test.ts b/packages/language-support/src/tests/syntaxColouring/preparser.test.ts index 16e5170e4..4123103d1 100644 --- a/packages/language-support/src/tests/syntaxColouring/preparser.test.ts +++ b/packages/language-support/src/tests/syntaxColouring/preparser.test.ts @@ -535,4 +535,244 @@ describe('Preparser syntax colouring', () => { }, ]); }); + + test('Correctly colours console commands used as variables or labels', () => { + const query = `CREATE (n:clear {use: 0}) +WITH $param AS map +RETURN map.propertyKey`; + expect(applySyntaxColouring(query)).toEqual([ + { + bracketInfo: undefined, + length: 6, + position: { + line: 0, + startCharacter: 0, + startOffset: 0, + }, + token: 'CREATE', + tokenType: 'keyword', + }, + { + bracketInfo: { + bracketLevel: 0, + bracketType: 'parenthesis', + }, + length: 1, + position: { + line: 0, + startCharacter: 7, + startOffset: 7, + }, + token: '(', + tokenType: 'bracket', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 0, + startCharacter: 8, + startOffset: 8, + }, + token: 'n', + tokenType: 'variable', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 0, + startCharacter: 9, + startOffset: 9, + }, + token: ':', + tokenType: 'operator', + }, + { + bracketInfo: undefined, + length: 5, + position: { + line: 0, + startCharacter: 10, + startOffset: 10, + }, + token: 'clear', + tokenType: 'label', + }, + { + bracketInfo: { + bracketLevel: 0, + bracketType: 'curly', + }, + length: 1, + position: { + line: 0, + startCharacter: 16, + startOffset: 16, + }, + token: '{', + tokenType: 'bracket', + }, + { + bracketInfo: undefined, + length: 3, + position: { + line: 0, + startCharacter: 17, + startOffset: 17, + }, + token: 'use', + tokenType: 'property', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 0, + startCharacter: 20, + startOffset: 20, + }, + token: ':', + tokenType: 'operator', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 0, + startCharacter: 22, + startOffset: 22, + }, + token: '0', + tokenType: 'numberLiteral', + }, + { + bracketInfo: { + bracketLevel: 0, + bracketType: 'curly', + }, + length: 1, + position: { + line: 0, + startCharacter: 23, + startOffset: 23, + }, + token: '}', + tokenType: 'bracket', + }, + { + bracketInfo: { + bracketLevel: 0, + bracketType: 'parenthesis', + }, + length: 1, + position: { + line: 0, + startCharacter: 24, + startOffset: 24, + }, + token: ')', + tokenType: 'bracket', + }, + { + bracketInfo: undefined, + length: 4, + position: { + line: 1, + startCharacter: 0, + startOffset: 26, + }, + token: 'WITH', + tokenType: 'keyword', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 1, + startCharacter: 5, + startOffset: 31, + }, + token: '$', + tokenType: 'paramDollar', + }, + { + bracketInfo: undefined, + length: 5, + position: { + line: 1, + startCharacter: 6, + startOffset: 32, + }, + token: 'param', + tokenType: 'paramValue', + }, + { + bracketInfo: undefined, + length: 2, + position: { + line: 1, + startCharacter: 12, + startOffset: 38, + }, + token: 'AS', + tokenType: 'keyword', + }, + { + bracketInfo: undefined, + length: 3, + position: { + line: 1, + startCharacter: 15, + startOffset: 41, + }, + token: 'map', + tokenType: 'variable', + }, + { + bracketInfo: undefined, + length: 6, + position: { + line: 2, + startCharacter: 0, + startOffset: 45, + }, + token: 'RETURN', + tokenType: 'keyword', + }, + { + bracketInfo: undefined, + length: 3, + position: { + line: 2, + startCharacter: 7, + startOffset: 52, + }, + token: 'map', + tokenType: 'variable', + }, + { + bracketInfo: undefined, + length: 1, + position: { + line: 2, + startCharacter: 10, + startOffset: 55, + }, + token: '.', + tokenType: 'operator', + }, + { + bracketInfo: undefined, + length: 11, + position: { + line: 2, + startCharacter: 11, + startOffset: 56, + }, + token: 'propertyKey', + tokenType: 'property', + }, + ]); + }); });