@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
@@ -1,71 +0,0 @@
1
- import { expect, test } from '@playwright/experimental-ct-react';
2
- import { CypherEditor } from '../CypherEditor';
3
- import { CypherEditorPage } from './e2e-utils';
4
- import { largeQuery, mockSchema } from './mock-data';
5
-
6
- test.use({ viewport: { width: 1000, height: 500 } });
7
-
8
- test('performance test session ', async ({ mount, page }) => {
9
- test.setTimeout(30 * 1000);
10
- const editorPage = new CypherEditorPage(page);
11
- const component = await mount(
12
- <CypherEditor prompt="neo4j>" theme="dark" lint schema={mockSchema} />,
13
- );
14
-
15
- // pressSequentially is less efficient -> we want to test the performance of the editor
16
- await editorPage.getEditor().pressSequentially(`
17
- MATCH (n:Person) RETURN m;`);
18
-
19
- await editorPage.checkErrorMessage('m', 'Variable `m` not defined');
20
-
21
- // set and unset large query a few times
22
- await component.update(
23
- <CypherEditor value={largeQuery} schema={mockSchema} />,
24
- );
25
- await component.update(<CypherEditor value="" schema={mockSchema} />);
26
-
27
- await component.update(
28
- <CypherEditor value={largeQuery} schema={mockSchema} />,
29
- );
30
- await component.update(<CypherEditor value="" />);
31
-
32
- await component.update(
33
- <CypherEditor value={largeQuery} schema={mockSchema} />,
34
- );
35
- await component.update(<CypherEditor value="" schema={mockSchema} />);
36
-
37
- await component.update(
38
- <CypherEditor value={largeQuery} schema={mockSchema} />,
39
- );
40
- await component.update(<CypherEditor value="" schema={mockSchema} />);
41
-
42
- await component.update(
43
- <CypherEditor value={largeQuery} schema={mockSchema} />,
44
- );
45
-
46
- await editorPage.getEditor().pressSequentially(`
47
- MATCH (n:P`);
48
-
49
- await expect(
50
- page.locator('.cm-tooltip-autocomplete').getByText('Person'),
51
- ).toBeVisible();
52
-
53
- await page.locator('.cm-tooltip-autocomplete').getByText('Person').click();
54
-
55
- await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
56
-
57
- await expect(component).toContainText('MATCH (n:Person');
58
-
59
- await editorPage.getEditor().pressSequentially(') RETRN my');
60
-
61
- await expect(component).toContainText('MATCH (n:Person) RETRN m');
62
-
63
- await editorPage.checkErrorMessage(
64
- 'RETRN',
65
- 'Unexpected token. Did you mean RETURN?',
66
- );
67
-
68
- await editorPage
69
- .getEditor()
70
- .pressSequentially('veryveryveryverylongvariable');
71
- });
@@ -1,156 +0,0 @@
1
- import { expect, test } from '@playwright/experimental-ct-react';
2
- import { CypherEditor } from '../CypherEditor';
3
- import { CypherEditorPage } from './e2e-utils';
4
-
5
- test.use({ viewport: { width: 1000, height: 500 } });
6
- test('Prop lint set to false disables syntax validation', async ({
7
- page,
8
- mount,
9
- }) => {
10
- const query = 'METCH (n) RETURN n';
11
-
12
- await mount(<CypherEditor value={query} lint={false} />);
13
-
14
- await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
15
- timeout: 2000,
16
- });
17
- });
18
-
19
- test.skip('Can turn linting back on', async ({ page, mount }) => {
20
- const editorPage = new CypherEditorPage(page);
21
- const query = 'METCH (n) RETURN n';
22
-
23
- const component = await mount(<CypherEditor value={query} lint={false} />);
24
-
25
- await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
26
- timeout: 2000,
27
- });
28
-
29
- await component.update(<CypherEditor value={query} lint />);
30
-
31
- await editorPage.getEditor().fill('METCH (n) RETURN n');
32
-
33
- await editorPage.checkErrorMessage(
34
- 'METCH',
35
- 'Unrecognized keyword. Did you mean MATCH?',
36
- );
37
- });
38
-
39
- test('Syntactic errors are surfaced', async ({ page, mount }) => {
40
- const editorPage = new CypherEditorPage(page);
41
- const query = 'METCH (n) RETURN n';
42
-
43
- await mount(<CypherEditor value={query} />);
44
-
45
- await editorPage.checkErrorMessage(
46
- 'METCH',
47
- 'Unrecognized keyword. Did you mean MATCH?',
48
- );
49
- });
50
-
51
- test('Errors for undefined labels are surfaced', async ({ page, mount }) => {
52
- const editorPage = new CypherEditorPage(page);
53
- const query = 'MATCH (n: Person) RETURN n';
54
-
55
- await mount(
56
- <CypherEditor
57
- value={query}
58
- schema={{ labels: ['Movie'], relationshipTypes: [] }}
59
- />,
60
- );
61
-
62
- await editorPage.checkWarningMessage(
63
- 'Person',
64
- "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",
65
- );
66
- });
67
-
68
- test('Errors for multiline undefined labels are highlighted correctly', async ({
69
- page,
70
- mount,
71
- }) => {
72
- const editorPage = new CypherEditorPage(page);
73
- const query = `MATCH (n:\`Foo
74
- Bar\`) RETURN n`;
75
- const expectedMsg = `Label \`Foo
76
- 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`;
77
-
78
- await mount(
79
- <CypherEditor
80
- value={query}
81
- schema={{ labels: ['Movie'], relationshipTypes: [] }}
82
- />,
83
- );
84
-
85
- await editorPage.checkWarningMessage('`Foo', expectedMsg);
86
- await editorPage.checkWarningMessage('Bar`', expectedMsg);
87
- });
88
-
89
- test('Semantic errors are surfaced when there are no syntactic errors', async ({
90
- page,
91
- mount,
92
- }) => {
93
- const editorPage = new CypherEditorPage(page);
94
- const query = 'MATCH (n) RETURN m';
95
-
96
- await mount(<CypherEditor value={query} />);
97
-
98
- await editorPage.checkErrorMessage('m', 'Variable `m` not defined');
99
- });
100
-
101
- test('Semantic errors are correctly accumulated', async ({ page, mount }) => {
102
- const editorPage = new CypherEditorPage(page);
103
- const query = 'CALL { MATCH (n) } IN TRANSACTIONS OF -1 ROWS';
104
-
105
- await mount(<CypherEditor value={query} />);
106
-
107
- await editorPage.checkErrorMessage(
108
- 'MATCH (n)',
109
- 'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
110
- );
111
-
112
- await editorPage.checkErrorMessage(
113
- '-1',
114
- "Invalid input. '-1' is not a valid value. Must be a positive integer",
115
- );
116
- });
117
-
118
- test('Multiline errors are correctly placed', async ({ page, mount }) => {
119
- const editorPage = new CypherEditorPage(page);
120
- const query = `CALL {
121
- MATCH (n)
122
- } IN TRANSACTIONS
123
- OF -1 ROWS`;
124
-
125
- await mount(<CypherEditor value={query} />);
126
-
127
- await editorPage.checkErrorMessage(
128
- 'MATCH (n)',
129
- 'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
130
- );
131
-
132
- await editorPage.checkErrorMessage(
133
- '-1',
134
- "Invalid input. '-1' is not a valid value. Must be a positive integer",
135
- );
136
- });
137
-
138
- test('Validation errors are correctly overlapped', async ({ page, mount }) => {
139
- const editorPage = new CypherEditorPage(page);
140
- const query = `CALL { MATCH (n)
141
- RETURN n
142
- } IN TRANSACTIONS
143
- OF -1 ROWS`;
144
-
145
- await mount(<CypherEditor value={query} />);
146
-
147
- await editorPage.checkErrorMessage(
148
- '-1',
149
- 'Query cannot conclude with CALL (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
150
- );
151
-
152
- await editorPage.checkErrorMessage(
153
- '-1',
154
- "Invalid input. '-1' is not a valid value. Must be a positive integer",
155
- );
156
- });
@@ -1,92 +0,0 @@
1
- import { Facet } from '@codemirror/state';
2
- import { Input, NodeType, Parser, PartialParse, Tree } from '@lezer/common';
3
- import {
4
- applySyntaxColouring,
5
- CypherTokenType,
6
- ParsedCypherToken,
7
- } from '@neo4j-cypher/language-support';
8
- import { cypherTokenTypeToNode, parserAdapterNodeSet } from './constants';
9
-
10
- const DEFAULT_NODE_GROUP_SIZE = 4;
11
-
12
- export class ParserAdapter extends Parser {
13
- cypherTokenTypeToNode: Record<CypherTokenType, NodeType> & {
14
- topNode: NodeType;
15
- };
16
-
17
- constructor(facet: Facet<unknown>) {
18
- super();
19
- this.cypherTokenTypeToNode = cypherTokenTypeToNode(facet);
20
- }
21
-
22
- private createBufferForTokens(tokens: ParsedCypherToken[]) {
23
- return tokens.map((token) => {
24
- const nodeTypeId = this.cypherTokenTypeToNode[token.tokenType].id;
25
- const startOffset = token.position.startOffset;
26
- const endOffset = token.position.startOffset + token.length;
27
-
28
- return [nodeTypeId, startOffset, endOffset, DEFAULT_NODE_GROUP_SIZE];
29
- });
30
- }
31
-
32
- private addTopNodeToBuffer(buffer: number[][], document: string) {
33
- const id = this.cypherTokenTypeToNode.topNode.id;
34
- const startOffset = 0;
35
- const endOffset = document.length;
36
- const totalBufferLength = buffer.length * DEFAULT_NODE_GROUP_SIZE;
37
-
38
- buffer.push([
39
- id,
40
- startOffset,
41
- endOffset,
42
- totalBufferLength + DEFAULT_NODE_GROUP_SIZE,
43
- ]);
44
- }
45
-
46
- private buildTree(document: string) {
47
- const tokens = applySyntaxColouring(document);
48
-
49
- if (tokens.length < 1) {
50
- return Tree.build({
51
- buffer: [
52
- this.cypherTokenTypeToNode.topNode.id,
53
- 0,
54
- document.length,
55
- DEFAULT_NODE_GROUP_SIZE,
56
- ],
57
- nodeSet: parserAdapterNodeSet(this.cypherTokenTypeToNode),
58
- topID: this.cypherTokenTypeToNode.topNode.id,
59
- });
60
- }
61
-
62
- const buffer = this.createBufferForTokens(tokens);
63
- this.addTopNodeToBuffer(buffer, document);
64
-
65
- return Tree.build({
66
- buffer: buffer.flat(),
67
- nodeSet: parserAdapterNodeSet(this.cypherTokenTypeToNode),
68
- topID: this.cypherTokenTypeToNode.topNode.id,
69
- });
70
- }
71
-
72
- createParse(input: Input): PartialParse {
73
- return this.startParse(input);
74
- }
75
-
76
- /* There are more arguments, but since we don't do any incremental parsing, they are not useful */
77
- startParse(input: string | Input): PartialParse {
78
- const document =
79
- typeof input === 'string' ? input : input.read(0, input.length);
80
-
81
- const tree = this.buildTree(document);
82
-
83
- return {
84
- stoppedAt: input.length,
85
- parsedPos: input.length,
86
- stopAt: () => {
87
- return undefined;
88
- },
89
- advance: () => tree,
90
- };
91
- }
92
- }
@@ -1,32 +0,0 @@
1
- import {
2
- defineLanguageFacet,
3
- Language,
4
- LanguageSupport,
5
- } from '@codemirror/language';
6
- import type { DbSchema } from '@neo4j-cypher/language-support';
7
- import { cypherAutocomplete } from './autocomplete';
8
- import { ParserAdapter } from './ParserAdapter';
9
- import { cypherLinter } from './syntax-validation';
10
-
11
- const facet = defineLanguageFacet({
12
- commentTokens: { block: { open: '/*', close: '*/' }, line: '//' },
13
- closeBrackets: { brackets: ['(', '[', '{', "'", '"', '`'] },
14
- });
15
-
16
- const parserAdapter = new ParserAdapter(facet);
17
-
18
- const cypherLanguage = new Language(facet, parserAdapter, [], 'cypher');
19
-
20
- export type CypherConfig = {
21
- lint?: boolean;
22
- schema?: DbSchema;
23
- };
24
-
25
- export function cypher(config: CypherConfig) {
26
- return new LanguageSupport(cypherLanguage, [
27
- cypherLanguage.data.of({
28
- autocomplete: cypherAutocomplete(config),
29
- }),
30
- cypherLinter(config),
31
- ]);
32
- }
@@ -1,24 +0,0 @@
1
- import { linter } from '@codemirror/lint';
2
- import { Extension } from '@codemirror/state';
3
- import { validateSyntax } from '@neo4j-cypher/language-support';
4
- import { DiagnosticSeverity } from 'vscode-languageserver-types';
5
- import type { CypherConfig } from './lang-cypher';
6
-
7
- export const cypherLinter: (config: CypherConfig) => Extension = (config) =>
8
- linter((view) => {
9
- if (!config.lint) {
10
- return [];
11
- }
12
-
13
- return validateSyntax(view.state.doc.toString(), config.schema).map(
14
- (diagnostic) => ({
15
- from: diagnostic.offsets.start,
16
- to: diagnostic.offsets.end,
17
- severity:
18
- diagnostic.severity === DiagnosticSeverity.Error
19
- ? 'error'
20
- : 'warning',
21
- message: diagnostic.message,
22
- }),
23
- );
24
- });