Skip to content

Commit

Permalink
Fix bug using console commands as variables labels (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon authored Jan 27, 2025
1 parent bad96d7 commit c587b81
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/serious-ducks-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@neo4j-cypher/language-support': patch
---

Fixes bug using console commands as variables or labels
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ useCompletionRule: USE;
serverCompletionRule: SERVER;

// This rule overrides the identifiers adding EXPLAIN, PROFILE, etc
unescapedLabelSymbolicNameString:
unescapedSymbolicNameString:
preparserKeyword
| HISTORY
| CLEAR
Expand Down
240 changes: 240 additions & 0 deletions packages/language-support/src/tests/syntaxColouring/preparser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]);
});
});

0 comments on commit c587b81

Please sign in to comment.