Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug using console commands as variables labels #332

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
},
]);
});
});
Loading