@neo4j-cypher/react-codemirror 2.0.0-next.3 → 2.0.0-next.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +265 -0
  2. package/README.md +3 -2
  3. package/dist/{types → src}/CypherEditor.d.ts +81 -3
  4. package/dist/src/CypherEditor.js +336 -0
  5. package/dist/src/CypherEditor.js.map +1 -0
  6. package/dist/src/CypherEditor.test.js +154 -0
  7. package/dist/src/CypherEditor.test.js.map +1 -0
  8. package/dist/src/constants.d.ts +1 -0
  9. package/dist/src/constants.js +2 -0
  10. package/dist/src/constants.js.map +1 -0
  11. package/dist/src/e2e_tests/autoCompletion.spec.js +332 -0
  12. package/dist/src/e2e_tests/autoCompletion.spec.js.map +1 -0
  13. package/dist/src/e2e_tests/configuration.spec.js +83 -0
  14. package/dist/src/e2e_tests/configuration.spec.js.map +1 -0
  15. package/dist/src/e2e_tests/debounce.spec.js +66 -0
  16. package/dist/src/e2e_tests/debounce.spec.js.map +1 -0
  17. package/dist/{types/e2e_tests/e2e-utils.d.ts → src/e2e_tests/e2eUtils.d.ts} +2 -0
  18. package/dist/src/e2e_tests/e2eUtils.js +79 -0
  19. package/dist/src/e2e_tests/e2eUtils.js.map +1 -0
  20. package/dist/src/e2e_tests/extraKeybindings.spec.js +43 -0
  21. package/dist/src/e2e_tests/extraKeybindings.spec.js.map +1 -0
  22. package/dist/src/e2e_tests/historyNavigation.spec.js +227 -0
  23. package/dist/src/e2e_tests/historyNavigation.spec.js.map +1 -0
  24. package/dist/src/e2e_tests/performanceTest.spec.d.ts +6 -0
  25. package/dist/src/e2e_tests/performanceTest.spec.js +97 -0
  26. package/dist/src/e2e_tests/performanceTest.spec.js.map +1 -0
  27. package/dist/src/e2e_tests/sanityChecks.spec.js +53 -0
  28. package/dist/src/e2e_tests/sanityChecks.spec.js.map +1 -0
  29. package/dist/src/e2e_tests/signatureHelp.spec.js +228 -0
  30. package/dist/src/e2e_tests/signatureHelp.spec.js.map +1 -0
  31. package/dist/src/e2e_tests/snippets.spec.js +62 -0
  32. package/dist/src/e2e_tests/snippets.spec.js.map +1 -0
  33. package/dist/src/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  34. package/dist/src/e2e_tests/syntaxHighlighting.spec.js +90 -0
  35. package/dist/src/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  36. package/dist/src/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  37. package/dist/src/e2e_tests/syntaxValidation.spec.js +126 -0
  38. package/dist/src/e2e_tests/syntaxValidation.spec.js.map +1 -0
  39. package/dist/src/historyNavigation.js +163 -0
  40. package/dist/src/historyNavigation.js.map +1 -0
  41. package/dist/{types → src}/icons.d.ts +1 -1
  42. package/dist/src/icons.js +62 -0
  43. package/dist/src/icons.js.map +1 -0
  44. package/dist/src/index.d.ts +4 -0
  45. package/dist/src/index.js +5 -0
  46. package/dist/src/index.js.map +1 -0
  47. package/dist/src/lang-cypher/autocomplete.d.ts +6 -0
  48. package/dist/src/lang-cypher/autocomplete.js +113 -0
  49. package/dist/src/lang-cypher/autocomplete.js.map +1 -0
  50. package/dist/{types → src}/lang-cypher/constants.d.ts +11 -0
  51. package/dist/src/lang-cypher/constants.js +69 -0
  52. package/dist/src/lang-cypher/constants.js.map +1 -0
  53. package/dist/src/lang-cypher/contants.test.d.ts +1 -0
  54. package/dist/src/lang-cypher/contants.test.js +103 -0
  55. package/dist/src/lang-cypher/contants.test.js.map +1 -0
  56. package/dist/src/lang-cypher/createCypherTheme.js +183 -0
  57. package/dist/src/lang-cypher/createCypherTheme.js.map +1 -0
  58. package/dist/src/lang-cypher/langCypher.d.ts +13 -0
  59. package/dist/src/lang-cypher/langCypher.js +23 -0
  60. package/dist/src/lang-cypher/langCypher.js.map +1 -0
  61. package/dist/src/lang-cypher/lintWorker.mjs +2022 -0
  62. package/dist/src/lang-cypher/parser-adapter.d.ts +19 -0
  63. package/dist/src/lang-cypher/parser-adapter.js +113 -0
  64. package/dist/src/lang-cypher/parser-adapter.js.map +1 -0
  65. package/dist/src/lang-cypher/signatureHelp.d.ts +4 -0
  66. package/dist/src/lang-cypher/signatureHelp.js +109 -0
  67. package/dist/src/lang-cypher/signatureHelp.js.map +1 -0
  68. package/dist/{types/lang-cypher/syntax-validation.d.ts → src/lang-cypher/syntaxValidation.d.ts} +2 -1
  69. package/dist/src/lang-cypher/syntaxValidation.js +57 -0
  70. package/dist/src/lang-cypher/syntaxValidation.js.map +1 -0
  71. package/dist/src/lang-cypher/themeIcons.js +22 -0
  72. package/dist/src/lang-cypher/themeIcons.js.map +1 -0
  73. package/dist/src/lang-cypher/utils.d.ts +2 -0
  74. package/dist/src/lang-cypher/utils.js +10 -0
  75. package/dist/src/lang-cypher/utils.js.map +1 -0
  76. package/dist/src/ndlTokensCopy.d.ts +570 -0
  77. package/dist/src/ndlTokensCopy.js +571 -0
  78. package/dist/src/ndlTokensCopy.js.map +1 -0
  79. package/dist/src/ndlTokensCopy.test.d.ts +1 -0
  80. package/dist/src/ndlTokensCopy.test.js +12 -0
  81. package/dist/src/ndlTokensCopy.test.js.map +1 -0
  82. package/dist/src/neo4jSetup.d.ts +6 -0
  83. package/dist/src/neo4jSetup.js +120 -0
  84. package/dist/src/neo4jSetup.js.map +1 -0
  85. package/dist/src/richClipboardCopier.d.ts +4 -0
  86. package/dist/src/richClipboardCopier.js +78 -0
  87. package/dist/src/richClipboardCopier.js.map +1 -0
  88. package/dist/src/richClipboardCopier.test.d.ts +1 -0
  89. package/dist/src/richClipboardCopier.test.js +53 -0
  90. package/dist/src/richClipboardCopier.test.js.map +1 -0
  91. package/dist/{types → src}/themes.d.ts +1 -1
  92. package/dist/src/themes.js +93 -0
  93. package/dist/src/themes.js.map +1 -0
  94. package/dist/tsconfig.tsbuildinfo +1 -0
  95. package/package.json +43 -41
  96. package/src/CypherEditor.test.tsx +204 -0
  97. package/src/CypherEditor.tsx +316 -42
  98. package/src/constants.ts +1 -0
  99. package/src/e2e_tests/autoCompletion.spec.tsx +571 -0
  100. package/src/e2e_tests/configuration.spec.tsx +111 -0
  101. package/src/e2e_tests/debounce.spec.tsx +106 -0
  102. package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +41 -3
  103. package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
  104. package/src/e2e_tests/{history-navigation.spec.tsx → historyNavigation.spec.tsx} +137 -18
  105. package/src/e2e_tests/performanceTest.spec.tsx +163 -0
  106. package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
  107. package/src/e2e_tests/signatureHelp.spec.tsx +444 -0
  108. package/src/e2e_tests/snippets.spec.tsx +92 -0
  109. package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +26 -24
  110. package/src/e2e_tests/syntaxValidation.spec.tsx +259 -0
  111. package/src/{history-navigation.ts → historyNavigation.ts} +1 -1
  112. package/src/icons.ts +3 -0
  113. package/src/index.ts +2 -2
  114. package/src/lang-cypher/autocomplete.ts +99 -18
  115. package/src/lang-cypher/constants.ts +27 -0
  116. package/src/lang-cypher/contants.test.ts +6 -2
  117. package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +45 -2
  118. package/src/lang-cypher/langCypher.ts +42 -0
  119. package/src/lang-cypher/lintWorker.mjs +2022 -0
  120. package/src/lang-cypher/parser-adapter.ts +145 -0
  121. package/src/lang-cypher/signatureHelp.ts +151 -0
  122. package/src/lang-cypher/syntaxValidation.ts +72 -0
  123. package/src/lang-cypher/utils.ts +9 -0
  124. package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
  125. package/src/ndlTokensCopy.ts +570 -0
  126. package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +78 -17
  127. package/src/richClipboardCopier.test.ts +65 -0
  128. package/src/richClipboardCopier.ts +99 -0
  129. package/src/themes.ts +45 -70
  130. package/src/viteEnv.d.ts +1 -0
  131. package/dist/cjs/index.cjs +0 -1440
  132. package/dist/cjs/index.cjs.map +0 -7
  133. package/dist/esm/index.mjs +0 -1463
  134. package/dist/esm/index.mjs.map +0 -7
  135. package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
  136. package/dist/types/index.d.ts +0 -4
  137. package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
  138. package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
  139. package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
  140. package/dist/types/ndl-tokens-copy.d.ts +0 -379
  141. package/dist/types/neo4j-setup.d.ts +0 -2
  142. package/dist/types/tsconfig.tsbuildinfo +0 -1
  143. package/src/e2e_tests/auto-completion.spec.tsx +0 -232
  144. package/src/e2e_tests/mock-data.ts +0 -4310
  145. package/src/e2e_tests/performance-test.spec.tsx +0 -71
  146. package/src/e2e_tests/syntax-validation.spec.tsx +0 -156
  147. package/src/lang-cypher/ParserAdapter.ts +0 -92
  148. package/src/lang-cypher/lang-cypher.ts +0 -32
  149. package/src/lang-cypher/syntax-validation.ts +0 -24
  150. package/src/ndl-tokens-copy.ts +0 -379
  151. /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → src/CypherEditor.test.d.ts} +0 -0
  152. /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → src/e2e_tests/autoCompletion.spec.d.ts} +0 -0
  153. /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → src/e2e_tests/configuration.spec.d.ts} +0 -0
  154. /package/dist/{types/e2e_tests/performance-test.spec.d.ts → src/e2e_tests/debounce.spec.d.ts} +0 -0
  155. /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → src/e2e_tests/extraKeybindings.spec.d.ts} +0 -0
  156. /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → src/e2e_tests/historyNavigation.spec.d.ts} +0 -0
  157. /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → src/e2e_tests/sanityChecks.spec.d.ts} +0 -0
  158. /package/dist/{types/lang-cypher/contants.test.d.ts → src/e2e_tests/signatureHelp.spec.d.ts} +0 -0
  159. /package/dist/{types/ndl-tokens-copy.test.d.ts → src/e2e_tests/snippets.spec.d.ts} +0 -0
  160. /package/dist/{types/history-navigation.d.ts → src/historyNavigation.d.ts} +0 -0
  161. /package/dist/{types/lang-cypher/create-cypher-theme.d.ts → src/lang-cypher/createCypherTheme.d.ts} +0 -0
  162. /package/dist/{types/lang-cypher/theme-icons.d.ts → src/lang-cypher/themeIcons.d.ts} +0 -0
  163. /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
@@ -0,0 +1,259 @@
1
+ import { testData } from '@neo4j-cypher/language-support';
2
+ import { expect, test } from '@playwright/experimental-ct-react';
3
+ import { CypherEditor } from '../CypherEditor';
4
+ import { CypherEditorPage } from './e2eUtils';
5
+
6
+ test.use({ viewport: { width: 1000, height: 500 } });
7
+ test('Prop lint set to false disables syntax validation', async ({
8
+ page,
9
+ mount,
10
+ }) => {
11
+ const query = 'METCH (n) RETURN n';
12
+
13
+ await mount(<CypherEditor value={query} lint={false} />);
14
+
15
+ await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
16
+ timeout: 10000,
17
+ });
18
+ });
19
+
20
+ test('Can turn linting back on', async ({ page, mount }) => {
21
+ const editorPage = new CypherEditorPage(page);
22
+ const query = 'METCH (n) RETURN n';
23
+
24
+ const component = await mount(<CypherEditor value={query} lint={false} />);
25
+
26
+ await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
27
+ timeout: 10000,
28
+ });
29
+
30
+ await component.update(<CypherEditor value={query} lint={true} />);
31
+
32
+ await editorPage.getEditor().fill('METCH (n) RETURN n');
33
+
34
+ await editorPage.checkErrorMessage(
35
+ 'METCH',
36
+ `Invalid input 'METCH': expected 'ALTER', 'ORDER BY', 'CALL', 'USING PERIODIC COMMIT', 'CREATE', 'LOAD CSV', 'START DATABASE', 'STOP DATABASE', 'DEALLOCATE', 'DELETE', 'DENY', 'DETACH', 'DROP', 'DRYRUN', 'FINISH', 'FOREACH', 'GRANT', 'INSERT', 'LIMIT', 'MATCH', 'MERGE', 'NODETACH', 'OFFSET', 'OPTIONAL', 'REALLOCATE', 'REMOVE', 'RENAME', 'RETURN', 'REVOKE', 'ENABLE SERVER', 'SET', 'SHOW', 'SKIP', 'TERMINATE', 'UNWIND', 'USE' or 'WITH'`,
37
+ );
38
+ });
39
+
40
+ test('Syntactic errors are surfaced', async ({ page, mount }) => {
41
+ const editorPage = new CypherEditorPage(page);
42
+ const query = 'METCH (n) RETURN n';
43
+
44
+ await mount(<CypherEditor value={query} />);
45
+
46
+ await editorPage.checkErrorMessage(
47
+ 'METCH',
48
+ `Invalid input 'METCH': expected 'ALTER', 'ORDER BY', 'CALL', 'USING PERIODIC COMMIT', 'CREATE', 'LOAD CSV', 'START DATABASE', 'STOP DATABASE', 'DEALLOCATE', 'DELETE', 'DENY', 'DETACH', 'DROP', 'DRYRUN', 'FINISH', 'FOREACH', 'GRANT', 'INSERT', 'LIMIT', 'MATCH', 'MERGE', 'NODETACH', 'OFFSET', 'OPTIONAL', 'REALLOCATE', 'REMOVE', 'RENAME', 'RETURN', 'REVOKE', 'ENABLE SERVER', 'SET', 'SHOW', 'SKIP', 'TERMINATE', 'UNWIND', 'USE' or 'WITH'`,
49
+ );
50
+ });
51
+
52
+ test('Does not trigger syntax errors for backticked parameters in parameter creation', async ({
53
+ page,
54
+ mount,
55
+ }) => {
56
+ const editorPage = new CypherEditorPage(page);
57
+
58
+ const query = ':param x => "abc"';
59
+ await mount(<CypherEditor value={query} />);
60
+
61
+ await editorPage.checkNoNotificationMessage('error');
62
+ });
63
+
64
+ test('Errors for undefined labels are surfaced', async ({ page, mount }) => {
65
+ const editorPage = new CypherEditorPage(page);
66
+ const query = 'MATCH (n: Person) RETURN n';
67
+
68
+ await mount(
69
+ <CypherEditor
70
+ value={query}
71
+ schema={{ labels: ['Movie'], relationshipTypes: [] }}
72
+ />,
73
+ );
74
+
75
+ await editorPage.checkWarningMessage(
76
+ 'Person',
77
+ "Label Person is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application",
78
+ );
79
+ });
80
+
81
+ test('Errors for multiline undefined labels are highlighted correctly', async ({
82
+ page,
83
+ mount,
84
+ }) => {
85
+ const editorPage = new CypherEditorPage(page);
86
+ const query = `MATCH (n:\`Foo
87
+ Bar\`) RETURN n`;
88
+ const expectedMsg = `Label \`Foo
89
+ Bar\` is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application`;
90
+
91
+ await mount(
92
+ <CypherEditor
93
+ value={query}
94
+ schema={{ labels: ['Movie'], relationshipTypes: [] }}
95
+ />,
96
+ );
97
+
98
+ await editorPage.checkWarningMessage('`Foo', expectedMsg);
99
+ await editorPage.checkWarningMessage('Bar`', expectedMsg);
100
+ });
101
+
102
+ test('Semantic errors work in firefox', async ({
103
+ browserName,
104
+ page,
105
+ mount,
106
+ }) => {
107
+ test.skip(browserName !== 'firefox');
108
+ const editorPage = new CypherEditorPage(page);
109
+ const query = 'MATCH (n:OperationalPoint)--(m:OperationalPoint) RETURN s,m,n';
110
+
111
+ await mount(<CypherEditor value={query} schema={testData.mockSchema} />);
112
+
113
+ await editorPage.checkErrorMessage('s,m,n', 'Variable `s` not defined');
114
+ });
115
+
116
+ test('Semantic errors are surfaced when there are no syntactic errors', async ({
117
+ page,
118
+ mount,
119
+ }) => {
120
+ const editorPage = new CypherEditorPage(page);
121
+ const query = 'MATCH (n) RETURN m';
122
+
123
+ await mount(<CypherEditor value={query} />);
124
+
125
+ await editorPage.checkErrorMessage('m', 'Variable `m` not defined');
126
+ });
127
+
128
+ test('Semantic errors are correctly accumulated', async ({ page, mount }) => {
129
+ const editorPage = new CypherEditorPage(page);
130
+ const query = 'CALL { MATCH (n) } IN TRANSACTIONS OF -1 ROWS';
131
+
132
+ await mount(<CypherEditor value={query} />);
133
+
134
+ await editorPage.checkErrorMessage(
135
+ 'MATCH (n)',
136
+ 'Query cannot conclude with MATCH (must be a RETURN clause, a FINISH clause, an update clause, a unit subquery call, or a procedure call with no YIELD).',
137
+ );
138
+
139
+ await editorPage.checkErrorMessage(
140
+ '-1',
141
+ "Invalid input. '-1' is not a valid value. Must be a positive integer.",
142
+ );
143
+ });
144
+
145
+ test('Multiline errors are correctly placed', async ({ page, mount }) => {
146
+ const editorPage = new CypherEditorPage(page);
147
+ const query = `CALL {
148
+ MATCH (n)
149
+ } IN TRANSACTIONS
150
+ OF -1 ROWS`;
151
+
152
+ await mount(<CypherEditor value={query} />);
153
+
154
+ await editorPage.checkErrorMessage(
155
+ 'MATCH (n)',
156
+ 'Query cannot conclude with MATCH (must be a RETURN clause, a FINISH clause, an update clause, a unit subquery call, or a procedure call with no YIELD).',
157
+ );
158
+
159
+ await editorPage.checkErrorMessage(
160
+ '-1',
161
+ "Invalid input. '-1' is not a valid value. Must be a positive integer.",
162
+ );
163
+ });
164
+
165
+ test('Validation errors are correctly overlapped', async ({ page, mount }) => {
166
+ const editorPage = new CypherEditorPage(page);
167
+ const query = `CALL { MATCH (n)
168
+ RETURN n
169
+ } IN TRANSACTIONS
170
+ OF -1 ROWS`;
171
+
172
+ await mount(<CypherEditor value={query} />);
173
+
174
+ await editorPage.checkErrorMessage(
175
+ '-1',
176
+ 'Query cannot conclude with CALL (must be a RETURN clause, a FINISH clause, an update clause, a unit subquery call, or a procedure call with no YIELD).',
177
+ );
178
+
179
+ await editorPage.checkErrorMessage(
180
+ '-1',
181
+ "Invalid input. '-1' is not a valid value. Must be a positive integer.",
182
+ );
183
+ });
184
+
185
+ test('Syntax highlighting works as expected with multiple separate linting messages', async ( {
186
+ page,
187
+ mount
188
+ }) => {
189
+ const editorPage = new CypherEditorPage(page);
190
+ const query = `MATCH (n)--(m) CALL (n) {RETURN id(n) AS b} RETURN apoc.create.uuid(), a`;
191
+
192
+ await mount(<CypherEditor value={query} schema={testData.mockSchema} />);
193
+ await expect(
194
+ editorPage.page.locator('.cm-deprecated-element').last(),
195
+ ).toBeVisible({ timeout: 10000 });
196
+ await editorPage.checkWarningMessage('id', 'Function id is deprecated.');
197
+ await editorPage.checkWarningMessage('id', `The query used a deprecated function. ('id' has been replaced by 'elementId or consider using an application-generated id')`);
198
+ await editorPage.checkWarningMessage('apoc.create.uuid', 'Function apoc.create.uuid is deprecated. Alternative: Neo4j randomUUID() function');
199
+ await editorPage.checkErrorMessage('a', 'Variable `a` not defined');
200
+ })
201
+
202
+ test('Strikethroughs are shown for deprecated functions', async ({
203
+ page,
204
+ mount,
205
+ }) => {
206
+ const editorPage = new CypherEditorPage(page);
207
+ const query = `RETURN id(1)`;
208
+
209
+ await mount(<CypherEditor value={query} schema={testData.mockSchema} />);
210
+ await expect(
211
+ editorPage.page.locator('.cm-deprecated-element').last(),
212
+ ).toBeVisible({ timeout: 10000 });
213
+ await editorPage.checkWarningMessage('id', 'Function id is deprecated.');
214
+ });
215
+
216
+ test('Strikethroughs are shown for deprecated procedures', async ({
217
+ page,
218
+ mount,
219
+ }) => {
220
+ const editorPage = new CypherEditorPage(page);
221
+ const query = `CALL apoc.create.uuids(5)`;
222
+
223
+ await mount(<CypherEditor value={query} schema={testData.mockSchema} />);
224
+ await expect(
225
+ editorPage.page.locator('.cm-deprecated-element').last(),
226
+ ).toBeVisible({ timeout: 10000 });
227
+
228
+ await editorPage.checkWarningMessage(
229
+ 'apoc.create.uuids',
230
+ "Procedure apoc.create.uuids is deprecated. Alternative: Neo4j's randomUUID() function can be used as a replacement, for example: `UNWIND range(0,$count) AS row RETURN row, randomUUID() AS uuid`",
231
+ );
232
+ });
233
+
234
+ test('Syntax validation depends on the Cypher version', async ({
235
+ page,
236
+ mount,
237
+ }) => {
238
+ await mount(
239
+ <CypherEditor
240
+ schema={testData.mockSchema}
241
+ />,
242
+ );
243
+
244
+ const editorPage = new CypherEditorPage(page);
245
+ const textField = page.getByRole('textbox');
246
+ await textField.fill('CYPHER 5 CALL apoc.create.uuids(5)');
247
+
248
+ await editorPage.checkWarningMessage(
249
+ 'apoc.create.uuids',
250
+ "Procedure apoc.create.uuids is deprecated. Alternative: Neo4j's randomUUID() function can be used as a replacement, for example: `UNWIND range(0,$count) AS row RETURN row, randomUUID() AS uuid`",
251
+ );
252
+
253
+ await textField.fill('CYPHER 25 CALL apoc.create.uuids(5)');
254
+
255
+ await editorPage.checkErrorMessage(
256
+ 'apoc.create.uuids',
257
+ `Procedure apoc.create.uuids is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application`,
258
+ );
259
+ });
@@ -97,7 +97,7 @@ function navigateHistory(view: EditorView, direction: HistoryNavigation) {
97
97
  view.dispatch(
98
98
  view.state.update({
99
99
  effects: moveInHistory.of(direction),
100
- selection: { anchor: view.state.doc.length },
100
+ selection: { anchor: direction === 'BACK' ? 0 : view.state.doc.length },
101
101
  }),
102
102
  );
103
103
 
package/src/icons.ts CHANGED
@@ -23,6 +23,7 @@ export type CompletionItemIcons =
23
23
  | 'Struct'
24
24
  | 'Event'
25
25
  | 'Operator'
26
+ | 'Console'
26
27
  | 'TypeParameter';
27
28
 
28
29
  export function getIconForType(iconTypeString = 'Text', isDarkTheme = false) {
@@ -51,6 +52,7 @@ export function getIconForType(iconTypeString = 'Text', isDarkTheme = false) {
51
52
  Struct: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M2.00024 2L1.00024 3V6L2.00024 7H14.0002L15.0002 6V3L14.0002 2H2.00024ZM2.00024 3H3.00024H13.0002H14.0002V4V5V6H13.0002H3.00024H2.00024V5V4V3ZM1.00024 10L2.00024 9H5.00024L6.00024 10V13L5.00024 14H2.00024L1.00024 13V10ZM3.00024 10H2.00024V11V12V13H3.00024H4.00024H5.00024V12V11V10H4.00024H3.00024ZM10.0002 10L11.0002 9H14.0002L15.0002 10V13L14.0002 14H11.0002L10.0002 13V10ZM12.0002 10H11.0002V11V12V13H12.0002H13.0002H14.0002V12V11V10H13.0002H12.0002Z" fill="#424242"/> </svg>`,
52
53
  Event: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M7.41379 1.55996L8.31177 1H11.6059L12.4243 2.57465L10.2358 6H12.0176L12.7365 7.69512L5.61967 15L4.01699 13.837L6.11967 10H4.89822L4.00024 8.55996L7.41379 1.55996ZM7.78058 9L4.90078 14.3049L12.0176 7H8.31177L11.6059 2H8.31177L4.89822 9H7.78058Z" fill="#D67E00"/> </svg>`,
53
54
  Operator: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M2.87313 1.10023C3.20793 1.23579 3.4757 1.498 3.61826 1.82988C3.69056 1.99959 3.72699 2.18242 3.72526 2.36688C3.72642 2.54999 3.69 2.7314 3.61826 2.89988C3.51324 3.14567 3.33807 3.35503 3.11466 3.50177C2.89126 3.64851 2.62955 3.72612 2.36226 3.72488C2.17948 3.72592 1.99842 3.68951 1.83026 3.61788C1.58322 3.51406 1.37252 3.33932 1.22478 3.11575C1.07704 2.89219 0.99891 2.62984 1.00026 2.36188C0.999374 2.17921 1.03543 1.99825 1.10626 1.82988C1.24362 1.50314 1.50353 1.24323 1.83026 1.10588C2.16357 0.966692 2.53834 0.964661 2.87313 1.10023ZM2.57526 2.86488C2.70564 2.80913 2.80951 2.70526 2.86526 2.57488C2.89314 2.50838 2.90742 2.43698 2.90726 2.36488C2.90838 2.2654 2.88239 2.1675 2.8321 2.08167C2.7818 1.99584 2.70909 1.92531 2.62176 1.87767C2.53443 1.83002 2.43577 1.80705 2.33638 1.81121C2.23698 1.81537 2.1406 1.8465 2.05755 1.90128C1.97451 1.95606 1.90794 2.03241 1.865 2.12215C1.82205 2.21188 1.80434 2.31161 1.81376 2.41065C1.82319 2.50968 1.85939 2.60428 1.9185 2.6843C1.9776 2.76433 2.05738 2.82675 2.14926 2.86488C2.28574 2.92089 2.43878 2.92089 2.57526 2.86488ZM6.43019 1.1095L1.10992 6.42977L1.79581 7.11567L7.11608 1.7954L6.43019 1.1095ZM11.5002 8.99999H12.5002V11.5H15.0002V12.5H12.5002V15H11.5002V12.5H9.00024V11.5H11.5002V8.99999ZM5.76801 9.52509L6.47512 10.2322L4.70735 12L6.47512 13.7677L5.76801 14.4748L4.00024 12.7071L2.23248 14.4748L1.52537 13.7677L3.29314 12L1.52537 10.2322L2.23248 9.52509L4.00024 11.2929L5.76801 9.52509ZM7.11826 5.32988C7.01466 5.08268 6.83997 4.87183 6.61636 4.72406C6.39275 4.57629 6.13028 4.49826 5.86226 4.49988C5.6796 4.49899 5.49864 4.53505 5.33026 4.60588C5.00353 4.74323 4.74362 5.00314 4.60626 5.32988C4.53612 5.49478 4.49922 5.67191 4.49766 5.8511C4.4961 6.0303 4.52992 6.20804 4.59718 6.37414C4.66443 6.54024 4.76381 6.69143 4.88961 6.81906C5.0154 6.94669 5.16515 7.04823 5.33026 7.11788C5.49892 7.18848 5.67993 7.22484 5.86276 7.22484C6.0456 7.22484 6.22661 7.18848 6.39526 7.11788C6.64225 7.01388 6.85295 6.83913 7.00082 6.61563C7.1487 6.39213 7.22713 6.12987 7.22626 5.86188C7.22679 5.67905 7.19005 5.49803 7.11826 5.32988ZM6.36526 6.07488C6.3379 6.13937 6.29854 6.19808 6.24926 6.24788C6.19932 6.29724 6.14066 6.33691 6.07626 6.36488C6.00878 6.39297 5.93635 6.40725 5.86326 6.40688C5.79015 6.40744 5.71769 6.39315 5.65026 6.36488C5.58565 6.33729 5.52693 6.29757 5.47726 6.24788C5.42715 6.19856 5.38738 6.13975 5.36026 6.07488C5.30425 5.9384 5.30425 5.78536 5.36026 5.64888C5.41561 5.51846 5.51965 5.41477 5.65026 5.35988C5.71761 5.33126 5.79008 5.31663 5.86326 5.31688C5.93642 5.31685 6.00884 5.33147 6.07626 5.35988C6.14062 5.38749 6.19928 5.42682 6.24926 5.47588C6.2981 5.52603 6.33741 5.58465 6.36526 5.64888C6.39364 5.7163 6.40827 5.78872 6.40827 5.86188C6.40827 5.93503 6.39364 6.00745 6.36526 6.07488ZM14.0002 3H10.0002V4H14.0002V3Z" fill="#424242"/> </svg>`,
55
+ Console: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M1.00024 1H15.0002V15H1.00024V1ZM2.00024 14H14.0002V2H2.00024V14ZM4.00032 5.70709L4.70743 4.99999L8.24296 8.53552L7.53585 9.24263L7.53583 9.2426L4.70735 12.0711L4.00024 11.364L6.82872 8.53549L4.00032 5.70709Z" fill="#424242"/> </svg>`,
54
56
  TypeParameter: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M11.0003 6H10.0003V5.5C10.0003 5.22386 9.7764 5 9.50026 5H8.47926V10.5C8.47926 10.7761 8.70312 11 8.97926 11H9.47926V12H6.47926V11H6.97926C7.2554 11 7.47926 10.7761 7.47926 10.5V5H6.50026C6.22412 5 6.00026 5.22386 6.00026 5.5V6H5.00026V4H11.0003V6ZM13.9145 8.0481L12.4522 6.58581L13.1593 5.87871L14.9751 7.69454V8.40165L13.2074 10.1694L12.5003 9.46231L13.9145 8.0481ZM3.54835 9.4623L2.08605 8.00002L3.50026 6.58581L2.79316 5.8787L1.02539 7.64647V8.35357L2.84124 10.1694L3.54835 9.4623Z" fill="#424242"/> </svg>`,
55
57
  };
56
58
 
@@ -79,6 +81,7 @@ export function getIconForType(iconTypeString = 'Text', isDarkTheme = false) {
79
81
  Struct: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M2 2L1 3V6L2 7H14L15 6V3L14 2H2ZM2 3H3H13H14V4V5V6H13H3H2V5V4V3ZM1 10L2 9H5L6 10V13L5 14H2L1 13V10ZM3 10H2V11V12V13H3H4H5V12V11V10H4H3ZM10 10L11 9H14L15 10V13L14 14H11L10 13V10ZM12 10H11V11V12V13H12H13H14V12V11V10H13H12Z" fill="#C5C5C5"/> </svg>`,
80
82
  Event: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M7.41354 1.55996L8.31152 1H11.6056L12.424 2.57465L10.2356 6H12.0174L12.7363 7.69512L5.61943 15L4.01675 13.837L6.11943 10H4.89798L4 8.55996L7.41354 1.55996ZM7.78033 9L4.90054 14.3049L12.0174 7H8.31152L11.6056 2H8.31152L4.89798 9H7.78033Z" fill="#EE9D28"/> </svg>`,
81
83
  Operator: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M2.87289 1.10023C3.20768 1.23579 3.47545 1.498 3.61802 1.82988C3.69032 1.99959 3.72675 2.18242 3.72502 2.36688C3.72617 2.54999 3.68975 2.7314 3.61802 2.89988C3.51299 3.14567 3.33782 3.35503 3.11442 3.50177C2.89102 3.64851 2.6293 3.72612 2.36202 3.72488C2.17924 3.72592 1.99818 3.68951 1.83002 3.61788C1.58298 3.51406 1.37227 3.33932 1.22453 3.11575C1.0768 2.89219 0.998666 2.62984 1.00002 2.36188C0.99913 2.17921 1.03519 1.99825 1.10602 1.82988C1.24337 1.50314 1.50328 1.24323 1.83002 1.10588C2.16332 0.966692 2.53809 0.964661 2.87289 1.10023ZM2.57502 2.86488C2.7054 2.80913 2.80927 2.70526 2.86502 2.57488C2.8929 2.50838 2.90718 2.43698 2.90702 2.36488C2.90813 2.2654 2.88215 2.1675 2.83185 2.08167C2.78156 1.99584 2.70884 1.92531 2.62151 1.87767C2.53418 1.83002 2.43553 1.80705 2.33614 1.81121C2.23674 1.81537 2.14035 1.8465 2.05731 1.90128C1.97426 1.95606 1.9077 2.03241 1.86475 2.12215C1.8218 2.21188 1.80409 2.31161 1.81352 2.41065C1.82294 2.50968 1.85915 2.60428 1.91825 2.6843C1.97736 2.76433 2.05713 2.82675 2.14902 2.86488C2.28549 2.92089 2.43854 2.92089 2.57502 2.86488ZM6.42995 1.1095L1.10967 6.42977L1.79557 7.11567L7.11584 1.7954L6.42995 1.1095ZM11.5 8.99999H12.5V11.5H15V12.5H12.5V15H11.5V12.5H9V11.5H11.5V8.99999ZM5.76777 9.52509L6.47487 10.2322L4.70711 12L6.47487 13.7677L5.76777 14.4748L4 12.7071L2.23223 14.4748L1.52513 13.7677L3.29289 12L1.52513 10.2322L2.23223 9.52509L4 11.2929L5.76777 9.52509ZM7.11802 5.32988C7.01442 5.08268 6.83973 4.87183 6.61612 4.72406C6.3925 4.57629 6.13004 4.49826 5.86202 4.49988C5.67935 4.49899 5.49839 4.53505 5.33002 4.60588C5.00328 4.74323 4.74337 5.00314 4.60602 5.32988C4.53588 5.49478 4.49897 5.67191 4.49741 5.8511C4.49586 6.0303 4.52967 6.20804 4.59693 6.37414C4.66419 6.54024 4.76356 6.69143 4.88936 6.81906C5.01516 6.94669 5.1649 7.04823 5.33002 7.11788C5.49867 7.18848 5.67968 7.22484 5.86252 7.22484C6.04535 7.22484 6.22636 7.18848 6.39502 7.11788C6.64201 7.01388 6.8527 6.83913 7.00058 6.61563C7.14845 6.39213 7.22689 6.12987 7.22602 5.86188C7.22655 5.67905 7.1898 5.49803 7.11802 5.32988ZM6.36502 6.07488C6.33766 6.13937 6.29829 6.19808 6.24902 6.24788C6.19908 6.29724 6.14042 6.33691 6.07602 6.36488C6.00854 6.39297 5.93611 6.40725 5.86302 6.40688C5.78991 6.40744 5.71744 6.39315 5.65002 6.36488C5.58541 6.33729 5.52668 6.29757 5.47702 6.24788C5.42691 6.19856 5.38713 6.13975 5.36002 6.07488C5.30401 5.9384 5.30401 5.78536 5.36002 5.64888C5.41536 5.51846 5.51941 5.41477 5.65002 5.35988C5.71737 5.33126 5.78984 5.31663 5.86302 5.31688C5.93618 5.31685 6.0086 5.33147 6.07602 5.35988C6.14037 5.38749 6.19904 5.42682 6.24902 5.47588C6.29786 5.52603 6.33717 5.58465 6.36502 5.64888C6.3934 5.7163 6.40802 5.78872 6.40802 5.86188C6.40802 5.93503 6.3934 6.00745 6.36502 6.07488ZM14 3H10V4H14V3Z" fill="#C5C5C5"/> </svg>`,
84
+ Console: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M1 1H15V15H1V1ZM2 14H14V2H2V14ZM4.00008 5.70709L4.70718 4.99999L8.24272 8.53552L7.53561 9.24263L7.53558 9.2426L4.70711 12.0711L4 11.364L6.82848 8.53549L4.00008 5.70709Z" fill="#C5C5C5"/> </svg>`,
82
85
  TypeParameter: `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M11 6H10V5.5C10 5.22386 9.77616 5 9.50001 5H8.47902V10.5C8.47902 10.7761 8.70288 11 8.97902 11H9.47902V12H6.47902V11H6.97902C7.25516 11 7.47902 10.7761 7.47902 10.5V5H6.50001C6.22387 5 6.00001 5.22386 6.00001 5.5V6H5.00001V4H11V6ZM13.9142 8.0481L12.4519 6.58581L13.159 5.87871L14.9749 7.69454V8.40165L13.2071 10.1694L12.5 9.46231L13.9142 8.0481ZM3.5481 9.4623L2.08581 8.00002L3.50002 6.58581L2.79291 5.8787L1.02515 7.64647V8.35357L2.841 10.1694L3.5481 9.4623Z" fill="#C5C5C5"/> </svg>`,
83
86
  };
84
87
  const iconType = iconTypeString as CompletionItemIcons;
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CypherParser, parse } from '@neo4j-cypher/language-support';
1
+ export * as LanguageSupport from '@neo4j-cypher/language-support';
2
2
  export { CypherEditor } from './CypherEditor';
3
- export { cypher } from './lang-cypher/lang-cypher';
3
+ export { cypher } from './lang-cypher/langCypher';
4
4
  export { darkThemeConstants, lightThemeConstants } from './themes';
@@ -1,8 +1,19 @@
1
- import { CompletionSource } from '@codemirror/autocomplete';
2
- import { autocomplete } from '@neo4j-cypher/language-support';
3
- import { CompletionItemKind } from 'vscode-languageserver-types';
1
+ import {
2
+ Completion,
3
+ CompletionSource,
4
+ snippet,
5
+ } from '@codemirror/autocomplete';
6
+ import {
7
+ autocomplete,
8
+ shouldAutoCompleteYield,
9
+ } from '@neo4j-cypher/language-support';
10
+ import {
11
+ CompletionItemKind,
12
+ CompletionItemTag,
13
+ } from 'vscode-languageserver-types';
4
14
  import { CompletionItemIcons } from '../icons';
5
- import type { CypherConfig } from './lang-cypher';
15
+ import type { CypherConfig } from './langCypher';
16
+ import { getDocString } from './utils';
6
17
 
7
18
  const completionKindToCodemirrorIcon = (c: CompletionItemKind) => {
8
19
  const map: Record<CompletionItemKind, CompletionItemIcons> = {
@@ -28,7 +39,8 @@ const completionKindToCodemirrorIcon = (c: CompletionItemKind) => {
28
39
  [CompletionItemKind.EnumMember]: 'EnumMember',
29
40
  [CompletionItemKind.Constant]: 'Constant',
30
41
  [CompletionItemKind.Struct]: 'Struct',
31
- [CompletionItemKind.Event]: 'Event',
42
+ // we're miss-using the enum here as there is no `Console` kind in the predefined list
43
+ [CompletionItemKind.Event]: 'Console',
32
44
  [CompletionItemKind.Operator]: 'Operator',
33
45
  [CompletionItemKind.TypeParameter]: 'TypeParameter',
34
46
  };
@@ -36,30 +48,99 @@ const completionKindToCodemirrorIcon = (c: CompletionItemKind) => {
36
48
  return map[c];
37
49
  };
38
50
 
51
+ export const completionStyles: (
52
+ completion: Completion & { deprecated?: boolean },
53
+ ) => string = (completion) => {
54
+ if (completion.deprecated) {
55
+ return 'cm-deprecated-element';
56
+ } else {
57
+ return null;
58
+ }
59
+ };
60
+
39
61
  export const cypherAutocomplete: (config: CypherConfig) => CompletionSource =
40
62
  (config) => (context) => {
41
- const textUntilCursor = context.state.doc.toString().slice(0, context.pos);
42
-
43
- const triggerCharacters = ['.', ':', '{', '$'];
44
- const lastCharacter = textUntilCursor.slice(-1);
45
-
63
+ const documentText = context.state.doc.toString();
64
+ const offset = context.pos;
65
+ const triggerCharacters = ['.', ':', '{', '$', ')'];
66
+ const lastCharacter = documentText.at(offset - 1);
67
+ const yieldTriggered = shouldAutoCompleteYield(documentText, offset);
46
68
  const lastWord = context.matchBefore(/\w*/);
47
69
  const inWord = lastWord.from !== lastWord.to;
48
-
49
70
  const shouldTriggerCompletion =
50
- inWord || context.explicit || triggerCharacters.includes(lastCharacter);
71
+ inWord ||
72
+ context.explicit ||
73
+ triggerCharacters.includes(lastCharacter) ||
74
+ yieldTriggered;
75
+
76
+ if (config.useLightVersion && !context.explicit) {
77
+ return null;
78
+ }
51
79
 
52
80
  if (!shouldTriggerCompletion) {
53
81
  return null;
54
82
  }
55
83
 
56
- const options = autocomplete(textUntilCursor, config.schema ?? {});
84
+ const options = autocomplete(
85
+ documentText,
86
+ config.schema ?? {},
87
+ offset,
88
+ context.explicit,
89
+ );
57
90
 
58
91
  return {
59
- from: context.matchBefore(/(\w|\$)*$/).from,
60
- options: options.map((o) => ({
61
- label: o.label,
62
- type: completionKindToCodemirrorIcon(o.kind),
63
- })),
92
+ from: context.matchBefore(/(\w)*$/).from,
93
+ options: options.map((o) => {
94
+ let maybeInfo = {};
95
+ let emptyInfo = true;
96
+ const newDiv = document.createElement('div');
97
+
98
+ if (o.signature) {
99
+ const header = document.createElement('p');
100
+ header.setAttribute('class', 'cm-completionInfo-signature');
101
+ header.textContent = o.signature;
102
+ if (header.textContent.length > 0) {
103
+ emptyInfo = false;
104
+ newDiv.appendChild(header);
105
+ }
106
+ }
107
+
108
+ if (o.documentation) {
109
+ const paragraph = document.createElement('p');
110
+ paragraph.textContent = getDocString(o.documentation);
111
+ if (paragraph.textContent.length > 0) {
112
+ emptyInfo = false;
113
+ newDiv.appendChild(paragraph);
114
+ }
115
+ }
116
+
117
+ if (!emptyInfo) {
118
+ maybeInfo = {
119
+ info: () => Promise.resolve(newDiv),
120
+ };
121
+ }
122
+ const deprecated =
123
+ o.tags?.find((tag) => tag === CompletionItemTag.Deprecated) ?? false;
124
+ // The negative boost moves the deprecation down the list
125
+ // so we offer the user the completions that are
126
+ // deprecated the last
127
+ const maybeDeprecated = deprecated
128
+ ? { boost: -99, deprecated: true }
129
+ : {};
130
+
131
+ return {
132
+ label: o.insertText ? o.insertText : o.label,
133
+ displayLabel: o.label,
134
+ type: completionKindToCodemirrorIcon(o.kind),
135
+ apply:
136
+ o.kind === CompletionItemKind.Snippet
137
+ ? // codemirror requires an empty snippet space to be able to tab out of the completion
138
+ snippet((o.insertText ?? o.label) + '${}')
139
+ : undefined,
140
+ detail: o.detail,
141
+ ...maybeDeprecated,
142
+ ...maybeInfo,
143
+ };
144
+ }),
64
145
  };
65
146
  };
@@ -31,8 +31,32 @@ export const cypherTokenTypeToNode = (facet: Facet<unknown>) => ({
31
31
  none: NodeType.define({ id: 19, name: 'none' }),
32
32
  separator: NodeType.define({ id: 20, name: 'separator' }),
33
33
  punctuation: NodeType.define({ id: 21, name: 'punctuation' }),
34
+ consoleCommand: NodeType.define({ id: 22, name: 'consoleCommand' }),
35
+ // also include prism token types
36
+ 'class-name': NodeType.define({ id: 23, name: 'label' }),
37
+ // this is escaped variables
38
+ identifier: NodeType.define({ id: 24, name: 'variable' }),
39
+ string: NodeType.define({ id: 25, name: 'stringLiteral' }),
40
+ relationship: NodeType.define({ id: 26, name: 'label' }),
41
+ boolean: NodeType.define({ id: 27, name: 'booleanLiteral' }),
42
+ number: NodeType.define({ id: 28, name: 'numberLiteral' }),
43
+ setting: NodeType.define({ id: 29, name: 'setting' }),
44
+ settingValue: NodeType.define({ id: 30, name: 'settingValue' }),
34
45
  });
35
46
 
47
+ export type PrismSpecificTokenType =
48
+ | 'class-name'
49
+ | 'identifier'
50
+ | 'string'
51
+ | 'relationship'
52
+ | 'boolean'
53
+ | 'number';
54
+
55
+ export type CodemirrorParseTokenType =
56
+ | CypherTokenType
57
+ | PrismSpecificTokenType
58
+ | 'topNode';
59
+
36
60
  export type HighlightedCypherTokenTypes = Exclude<CypherTokenType, 'none'>;
37
61
  export const tokenTypeToStyleTag: Record<HighlightedCypherTokenTypes, Tag> = {
38
62
  comment: tags.comment,
@@ -55,6 +79,9 @@ export const tokenTypeToStyleTag: Record<HighlightedCypherTokenTypes, Tag> = {
55
79
  bracket: tags.bracket,
56
80
  punctuation: tags.punctuation,
57
81
  separator: tags.separator,
82
+ consoleCommand: tags.macroName,
83
+ setting: tags.attributeName,
84
+ settingValue: tags.attributeValue,
58
85
  };
59
86
 
60
87
  export const parserAdapterNodeSet = (nodes: Record<string, NodeType>) =>
@@ -1,5 +1,9 @@
1
1
  import { tags } from '@lezer/highlight';
2
- import { applySyntaxColouring } from '@neo4j-cypher/language-support';
2
+ import {
3
+ applySyntaxColouring,
4
+ CypherTokenType,
5
+ } from '@neo4j-cypher/language-support';
6
+ import { expect, test } from 'vitest';
3
7
  import { tokenTypeToStyleTag } from './constants';
4
8
 
5
9
  const cypherQueryWithAllTokenTypes = `MATCH (variable :Label)-[:REL_TYPE]->()
@@ -54,7 +58,7 @@ test('correctly parses all cypher token types to style tags', () => {
54
58
  ]);
55
59
 
56
60
  const styleTags = tokenTypes.map((tokenType) => {
57
- if (tokenType === 'none') return undefined;
61
+ if (tokenType === CypherTokenType.none) return undefined;
58
62
  return tokenTypeToStyleTag[tokenType];
59
63
  });
60
64
  const correctTags = [
@@ -5,6 +5,7 @@ import {
5
5
  } from '@codemirror/language';
6
6
  import { Extension } from '@codemirror/state';
7
7
  import { EditorView } from '@codemirror/view';
8
+ import { CypherTokenType } from '@neo4j-cypher/language-support';
8
9
  import { StyleSpec } from 'style-mod';
9
10
  import { HighlightedCypherTokenTypes, tokenTypeToStyleTag } from './constants';
10
11
  import {
@@ -15,7 +16,7 @@ import {
15
16
  replaceAllSvg,
16
17
  replaceSvg,
17
18
  upArrowSvg,
18
- } from './theme-icons';
19
+ } from './themeIcons';
19
20
 
20
21
  export interface ThemeOptions {
21
22
  dark: boolean;
@@ -53,6 +54,9 @@ export const createCypherTheme = ({
53
54
  color: settings.foreground,
54
55
  fontVariantLigatures: 'none',
55
56
  },
57
+ '& .cm-snippetField': {
58
+ backgroundColor: settings.autoCompletionPanel.selectedColor,
59
+ },
56
60
  '&.cm-focused': {
57
61
  outline: 'none',
58
62
  },
@@ -61,8 +65,9 @@ export const createCypherTheme = ({
61
65
  color: settings.gutterForeground,
62
66
  border: 'none',
63
67
  },
64
- '&.cm-editor .cm-scroller': {
68
+ '&.cm-editor': {
65
69
  fontFamily: 'Fira Code, Menlo, Monaco, Lucida Console, monospace',
70
+ height: '100%',
66
71
  },
67
72
  '.cm-content': {
68
73
  caretColor: settings.cursor,
@@ -80,9 +85,13 @@ export const createCypherTheme = ({
80
85
  '& .cm-selectionMatch': {
81
86
  backgroundColor: settings.textMatchingSelection,
82
87
  },
88
+ '& .cm-bold': {
89
+ fontWeight: 'bold',
90
+ },
83
91
  '& .cm-panels': {
84
92
  backgroundColor: settings.searchPanel.background,
85
93
  fontFamily: 'Fira Code, Menlo, Monaco, Lucida Console, monospace',
94
+ zIndex: 0,
86
95
  },
87
96
  '& .cm-completionLabel': {
88
97
  fontFamily: 'Fira Code, Menlo, Monaco, Lucida Console, monospace',
@@ -93,7 +102,40 @@ export const createCypherTheme = ({
93
102
  color: settings.autoCompletionPanel.matchingTextColor,
94
103
  textDecoration: 'none',
95
104
  },
105
+ '& .cm-signature-help-panel': {
106
+ backgroundColor: settings.autoCompletionPanel.backgroundColor,
107
+ maxWidth: '700px',
108
+ maxHeight: '250px',
109
+ fontFamily: 'Fira Code, Menlo, Monaco, Lucida Console, monospace',
110
+ },
111
+ '& .cm-signature-help-panel-contents': {
112
+ overflow: 'auto',
113
+ maxHeight: '250px',
114
+ },
115
+ '& .cm-signature-help-panel-current-argument': {
116
+ color: settings.autoCompletionPanel.matchingTextColor,
117
+ fontWeight: 'bold',
118
+ },
119
+ '& .cm-signature-help-panel-separator': {
120
+ borderBottom: '1px solid #ccc',
121
+ },
122
+ '& .cm-signature-help-panel-name': {
123
+ padding: '5px',
124
+ },
125
+ '& .cm-signature-help-panel-arg-description': {
126
+ padding: '5px',
127
+ },
128
+ '& .cm-signature-help-panel-description': {
129
+ padding: '5px',
130
+ },
131
+ '.cm-completionInfo-signature': {
132
+ color: 'darkgrey',
133
+ },
134
+ '.cm-deprecated-element': {
135
+ 'text-decoration': 'line-through',
136
+ },
96
137
  '.cm-tooltip-autocomplete': {
138
+ maxWidth: '430px',
97
139
  '& > ul > li[aria-selected]': {
98
140
  backgroundColor: settings.autoCompletionPanel.selectedColor,
99
141
  color: settings.foreground,
@@ -198,6 +240,7 @@ export const createCypherTheme = ({
198
240
  ([token, color]: [HighlightedCypherTokenTypes, string]): TagStyle => ({
199
241
  tag: tokenTypeToStyleTag[token],
200
242
  color,
243
+ class: token === CypherTokenType.consoleCommand ? 'cm-bold' : undefined,
201
244
  }),
202
245
  );
203
246
  const highlightStyle = HighlightStyle.define(styles);
@@ -0,0 +1,42 @@
1
+ import { autocompletion } from '@codemirror/autocomplete';
2
+ import {
3
+ defineLanguageFacet,
4
+ Language,
5
+ LanguageSupport,
6
+ } from '@codemirror/language';
7
+ import { type DbSchema } from '@neo4j-cypher/language-support';
8
+ import { completionStyles, cypherAutocomplete } from './autocomplete';
9
+ import { ParserAdapter } from './parser-adapter';
10
+ import { signatureHelpTooltip } from './signatureHelp';
11
+ import { cypherLinter } from './syntaxValidation';
12
+
13
+ const facet = defineLanguageFacet({
14
+ commentTokens: { block: { open: '/*', close: '*/' }, line: '//' },
15
+ closeBrackets: { brackets: ['(', '[', '{', "'", '"', '`'] },
16
+ });
17
+
18
+ export type CypherConfig = {
19
+ lint?: boolean;
20
+ showSignatureTooltipBelow?: boolean;
21
+ featureFlags?: {
22
+ consoleCommands?: boolean;
23
+ };
24
+ schema?: DbSchema;
25
+ useLightVersion: boolean;
26
+ setUseLightVersion?: (useLightVersion: boolean) => void;
27
+ };
28
+
29
+ export function cypher(config: CypherConfig) {
30
+ const parserAdapter = new ParserAdapter(facet, config);
31
+
32
+ const cypherLanguage = new Language(facet, parserAdapter, [], 'cypher');
33
+
34
+ return new LanguageSupport(cypherLanguage, [
35
+ autocompletion({
36
+ override: [cypherAutocomplete(config)],
37
+ optionClass: completionStyles,
38
+ }),
39
+ cypherLinter(config),
40
+ signatureHelpTooltip(config),
41
+ ]);
42
+ }