@neo4j-cypher/react-codemirror 2.0.0-next.1 → 2.0.0-next.11

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 (156) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +4 -1
  3. package/dist/{types/CypherEditor.d.ts → CypherEditor.d.ts} +69 -8
  4. package/dist/CypherEditor.js +300 -0
  5. package/dist/CypherEditor.js.map +1 -0
  6. package/dist/CypherEditor.test.js +151 -0
  7. package/dist/CypherEditor.test.js.map +1 -0
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/constants.js +2 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/e2e_tests/autoCompletion.spec.js +267 -0
  12. package/dist/e2e_tests/autoCompletion.spec.js.map +1 -0
  13. package/dist/e2e_tests/configuration.spec.js +83 -0
  14. package/dist/e2e_tests/configuration.spec.js.map +1 -0
  15. package/dist/e2e_tests/debounce.spec.js +65 -0
  16. package/dist/e2e_tests/debounce.spec.js.map +1 -0
  17. package/dist/e2e_tests/e2eUtils.js +60 -0
  18. package/dist/e2e_tests/e2eUtils.js.map +1 -0
  19. package/dist/e2e_tests/extraKeybindings.spec.js +43 -0
  20. package/dist/e2e_tests/extraKeybindings.spec.js.map +1 -0
  21. package/dist/e2e_tests/historyNavigation.spec.js +227 -0
  22. package/dist/e2e_tests/historyNavigation.spec.js.map +1 -0
  23. package/dist/e2e_tests/performanceTest.spec.d.ts +6 -0
  24. package/dist/e2e_tests/performanceTest.spec.js +96 -0
  25. package/dist/e2e_tests/performanceTest.spec.js.map +1 -0
  26. package/dist/e2e_tests/sanityChecks.spec.js +53 -0
  27. package/dist/e2e_tests/sanityChecks.spec.js.map +1 -0
  28. package/dist/e2e_tests/signatureHelp.spec.js +179 -0
  29. package/dist/e2e_tests/signatureHelp.spec.js.map +1 -0
  30. package/dist/e2e_tests/snippets.spec.js +62 -0
  31. package/dist/e2e_tests/snippets.spec.js.map +1 -0
  32. package/dist/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  33. package/dist/e2e_tests/syntaxHighlighting.spec.js +90 -0
  34. package/dist/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  35. package/dist/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  36. package/dist/e2e_tests/syntaxValidation.spec.js +79 -0
  37. package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -0
  38. package/dist/historyNavigation.d.ts +7 -0
  39. package/dist/historyNavigation.js +163 -0
  40. package/dist/historyNavigation.js.map +1 -0
  41. package/dist/{types/icons.d.ts → icons.d.ts} +1 -1
  42. package/dist/icons.js +62 -0
  43. package/dist/icons.js.map +1 -0
  44. package/dist/index.d.ts +4 -0
  45. package/dist/index.js +5 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/lang-cypher/autocomplete.d.ts +6 -0
  48. package/dist/lang-cypher/autocomplete.js +124 -0
  49. package/dist/lang-cypher/autocomplete.js.map +1 -0
  50. package/dist/{types/lang-cypher → lang-cypher}/constants.d.ts +9 -0
  51. package/dist/lang-cypher/constants.js +65 -0
  52. package/dist/lang-cypher/constants.js.map +1 -0
  53. package/dist/lang-cypher/contants.test.d.ts +1 -0
  54. package/dist/lang-cypher/contants.test.js +103 -0
  55. package/dist/lang-cypher/contants.test.js.map +1 -0
  56. package/dist/lang-cypher/createCypherTheme.js +179 -0
  57. package/dist/lang-cypher/createCypherTheme.js.map +1 -0
  58. package/dist/lang-cypher/langCypher.d.ts +14 -0
  59. package/dist/lang-cypher/langCypher.js +30 -0
  60. package/dist/lang-cypher/langCypher.js.map +1 -0
  61. package/dist/lang-cypher/lintWorker.d.ts +8 -0
  62. package/dist/lang-cypher/lintWorker.js +4 -0
  63. package/dist/lang-cypher/lintWorker.js.map +1 -0
  64. package/dist/lang-cypher/parser-adapter.d.ts +19 -0
  65. package/dist/lang-cypher/parser-adapter.js +113 -0
  66. package/dist/lang-cypher/parser-adapter.js.map +1 -0
  67. package/dist/lang-cypher/signatureHelp.d.ts +4 -0
  68. package/dist/lang-cypher/signatureHelp.js +94 -0
  69. package/dist/lang-cypher/signatureHelp.js.map +1 -0
  70. package/dist/lang-cypher/syntaxValidation.d.ts +5 -0
  71. package/dist/lang-cypher/syntaxValidation.js +69 -0
  72. package/dist/lang-cypher/syntaxValidation.js.map +1 -0
  73. package/dist/lang-cypher/themeIcons.js +22 -0
  74. package/dist/lang-cypher/themeIcons.js.map +1 -0
  75. package/dist/lang-cypher/utils.d.ts +2 -0
  76. package/dist/lang-cypher/utils.js +10 -0
  77. package/dist/lang-cypher/utils.js.map +1 -0
  78. package/dist/ndlTokensCopy.js +380 -0
  79. package/dist/ndlTokensCopy.js.map +1 -0
  80. package/dist/ndlTokensCopy.test.d.ts +1 -0
  81. package/dist/ndlTokensCopy.test.js +12 -0
  82. package/dist/ndlTokensCopy.test.js.map +1 -0
  83. package/dist/neo4jSetup.js +120 -0
  84. package/dist/neo4jSetup.js.map +1 -0
  85. package/dist/{types/themes.d.ts → themes.d.ts} +1 -1
  86. package/dist/themes.js +114 -0
  87. package/dist/themes.js.map +1 -0
  88. package/dist/tsconfig.tsbuildinfo +1 -0
  89. package/package.json +30 -31
  90. package/src/CypherEditor.test.tsx +200 -0
  91. package/src/CypherEditor.tsx +292 -41
  92. package/src/constants.ts +1 -0
  93. package/src/e2e_tests/autoCompletion.spec.tsx +472 -0
  94. package/src/e2e_tests/configuration.spec.tsx +111 -0
  95. package/src/e2e_tests/debounce.spec.tsx +101 -0
  96. package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +11 -1
  97. package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
  98. package/src/e2e_tests/historyNavigation.spec.tsx +315 -0
  99. package/src/e2e_tests/performanceTest.spec.tsx +158 -0
  100. package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
  101. package/src/e2e_tests/signatureHelp.spec.tsx +380 -0
  102. package/src/e2e_tests/snippets.spec.tsx +92 -0
  103. package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +1 -3
  104. package/src/e2e_tests/{syntax-validation.spec.tsx → syntaxValidation.spec.tsx} +6 -7
  105. package/src/{repl-mode.ts → historyNavigation.ts} +7 -30
  106. package/src/icons.ts +3 -0
  107. package/src/index.ts +5 -2
  108. package/src/lang-cypher/autocomplete.ts +107 -15
  109. package/src/lang-cypher/constants.ts +23 -0
  110. package/src/lang-cypher/contants.test.ts +6 -2
  111. package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +41 -2
  112. package/src/lang-cypher/langCypher.ts +53 -0
  113. package/src/lang-cypher/lintWorker.ts +14 -0
  114. package/src/lang-cypher/parser-adapter.ts +145 -0
  115. package/src/lang-cypher/signatureHelp.ts +133 -0
  116. package/src/lang-cypher/syntaxValidation.ts +96 -0
  117. package/src/lang-cypher/utils.ts +9 -0
  118. package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
  119. package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +51 -1
  120. package/src/themes.ts +4 -2
  121. package/src/viteEnv.d.ts +1 -0
  122. package/dist/cjs/index.cjs +0 -1443
  123. package/dist/cjs/index.cjs.map +0 -7
  124. package/dist/esm/index.mjs +0 -1466
  125. package/dist/esm/index.mjs.map +0 -7
  126. package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
  127. package/dist/types/index.d.ts +0 -4
  128. package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
  129. package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
  130. package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
  131. package/dist/types/lang-cypher/syntax-validation.d.ts +0 -3
  132. package/dist/types/repl-mode.d.ts +0 -8
  133. package/dist/types/tsconfig.tsbuildinfo +0 -1
  134. package/src/e2e_tests/auto-completion.spec.tsx +0 -232
  135. package/src/e2e_tests/history-navigation.spec.tsx +0 -144
  136. package/src/e2e_tests/mock-data.ts +0 -4310
  137. package/src/e2e_tests/performance-test.spec.tsx +0 -71
  138. package/src/lang-cypher/ParserAdapter.ts +0 -92
  139. package/src/lang-cypher/lang-cypher.ts +0 -32
  140. package/src/lang-cypher/syntax-validation.ts +0 -24
  141. /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → CypherEditor.test.d.ts} +0 -0
  142. /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → e2e_tests/autoCompletion.spec.d.ts} +0 -0
  143. /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → e2e_tests/configuration.spec.d.ts} +0 -0
  144. /package/dist/{types/e2e_tests/performance-test.spec.d.ts → e2e_tests/debounce.spec.d.ts} +0 -0
  145. /package/dist/{types/e2e_tests/e2e-utils.d.ts → e2e_tests/e2eUtils.d.ts} +0 -0
  146. /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → e2e_tests/extraKeybindings.spec.d.ts} +0 -0
  147. /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → e2e_tests/historyNavigation.spec.d.ts} +0 -0
  148. /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → e2e_tests/sanityChecks.spec.d.ts} +0 -0
  149. /package/dist/{types/lang-cypher/contants.test.d.ts → e2e_tests/signatureHelp.spec.d.ts} +0 -0
  150. /package/dist/{types/ndl-tokens-copy.test.d.ts → e2e_tests/snippets.spec.d.ts} +0 -0
  151. /package/dist/{types/lang-cypher/create-cypher-theme.d.ts → lang-cypher/createCypherTheme.d.ts} +0 -0
  152. /package/dist/{types/lang-cypher/theme-icons.d.ts → lang-cypher/themeIcons.d.ts} +0 -0
  153. /package/dist/{types/ndl-tokens-copy.d.ts → ndlTokensCopy.d.ts} +0 -0
  154. /package/dist/{types/neo4j-setup.d.ts → neo4jSetup.d.ts} +0 -0
  155. /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
  156. /package/src/{ndl-tokens-copy.ts → ndlTokensCopy.ts} +0 -0
@@ -0,0 +1,96 @@
1
+ import { Diagnostic, linter } from '@codemirror/lint';
2
+ import { Extension } from '@codemirror/state';
3
+ import { parserWrapper, validateSyntax } from '@neo4j-cypher/language-support';
4
+ import { DiagnosticSeverity } from 'vscode-languageserver-types';
5
+ import workerpool from 'workerpool';
6
+ import type { CypherConfig } from './langCypher';
7
+ import type { LinterTask, LintWorker } from './lintWorker';
8
+ import WorkerURL from './lintWorker?worker&url';
9
+
10
+ const pool = workerpool.pool(WorkerURL, {
11
+ minWorkers: 2,
12
+ workerOpts: { type: 'module' },
13
+ workerTerminateTimeout: 2000,
14
+ });
15
+
16
+ let lastSemanticJob: LinterTask | undefined;
17
+
18
+ export const cypherLinter: (config: CypherConfig) => Extension = (config) =>
19
+ linter((view) => {
20
+ if (!config.lint) {
21
+ return [];
22
+ }
23
+
24
+ const query = view.state.doc.toString();
25
+ const syntaxErrors = validateSyntax(query, config.schema ?? {});
26
+
27
+ return syntaxErrors.map(
28
+ (diagnostic): Diagnostic => ({
29
+ from: diagnostic.offsets.start,
30
+ to: diagnostic.offsets.end,
31
+ severity:
32
+ diagnostic.severity === DiagnosticSeverity.Error
33
+ ? 'error'
34
+ : 'warning',
35
+ message: diagnostic.message,
36
+ }),
37
+ );
38
+ });
39
+
40
+ export const semanticAnalysisLinter: (config: CypherConfig) => Extension = (
41
+ config,
42
+ ) =>
43
+ linter(async (view) => {
44
+ if (!config.lint) {
45
+ return [];
46
+ }
47
+
48
+ const query = view.state.doc.toString();
49
+ if (query.length === 0) {
50
+ return [];
51
+ }
52
+
53
+ // we want to avoid the ANTLR4 reparse in the worker thread, this should hit our main thread cache
54
+ const parse = parserWrapper.parse(query);
55
+ const statements = parse.statementsParsing;
56
+
57
+ const anySyntacticError =
58
+ statements.filter((statement) => statement.diagnostics.length !== 0)
59
+ .length > 0;
60
+
61
+ if (anySyntacticError) {
62
+ return [];
63
+ }
64
+
65
+ try {
66
+ if (lastSemanticJob !== undefined && !lastSemanticJob.resolved) {
67
+ void lastSemanticJob.cancel();
68
+ }
69
+
70
+ const proxyWorker = (await pool.proxy()) as unknown as LintWorker;
71
+ lastSemanticJob = proxyWorker.validateSemantics(
72
+ query,
73
+ config.schema ?? {},
74
+ );
75
+ const result = await lastSemanticJob;
76
+
77
+ return result.map((diag) => {
78
+ return {
79
+ from: diag.offsets.start,
80
+ to: diag.offsets.end,
81
+ severity:
82
+ diag.severity === DiagnosticSeverity.Error ? 'error' : 'warning',
83
+ message: diag.message,
84
+ };
85
+ });
86
+ } catch (err) {
87
+ if (!(err instanceof workerpool.Promise.CancellationError)) {
88
+ console.error(String(err) + ' ' + query);
89
+ }
90
+ }
91
+ return [];
92
+ });
93
+
94
+ export const cleanupWorkers = () => {
95
+ void pool.terminate();
96
+ };
@@ -0,0 +1,9 @@
1
+ import { MarkupContent } from 'vscode-languageserver-types';
2
+
3
+ export function getDocString(result: string | MarkupContent): string {
4
+ if (MarkupContent.is(result)) {
5
+ result.value;
6
+ } else {
7
+ return result;
8
+ }
9
+ }
@@ -1,5 +1,6 @@
1
1
  import { tokens } from '@neo4j-ndl/base';
2
- import { tokens as tokensCopy } from './ndl-tokens-copy';
2
+ import { expect, test } from 'vitest';
3
+ import { tokens as tokensCopy } from './ndlTokensCopy';
3
4
 
4
5
  /*
5
6
  * Needle has some odd package configuration that made playwright stop working
@@ -1,9 +1,14 @@
1
1
  import {
2
2
  acceptCompletion,
3
3
  autocompletion,
4
+ clearSnippet,
4
5
  closeBrackets,
5
6
  closeBracketsKeymap,
7
+ closeCompletion,
6
8
  completionKeymap,
9
+ nextSnippetField,
10
+ prevSnippetField,
11
+ snippetKeymap,
7
12
  } from '@codemirror/autocomplete';
8
13
  import {
9
14
  defaultKeymap,
@@ -22,11 +27,13 @@ import {
22
27
  import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
23
28
  import { EditorState, Extension, StateCommand } from '@codemirror/state';
24
29
  import {
30
+ Command,
25
31
  crosshairCursor,
26
32
  drawSelection,
27
33
  dropCursor,
28
34
  EditorView,
29
35
  highlightSpecialChars,
36
+ KeyBinding,
30
37
  keymap,
31
38
  rectangularSelection,
32
39
  } from '@codemirror/view';
@@ -55,7 +62,7 @@ const insertTab: StateCommand = (cmd) => {
55
62
  };
56
63
 
57
64
  export const basicNeo4jSetup = (): Extension[] => {
58
- const keymaps = [
65
+ const keymaps: KeyBinding[] = [
59
66
  closeBracketsKeymap,
60
67
  defaultKeymap,
61
68
  searchKeymap,
@@ -125,5 +132,48 @@ export const basicNeo4jSetup = (): Extension[] => {
125
132
 
126
133
  extensions.push(keymap.of(keymaps));
127
134
 
135
+ extensions.push(
136
+ snippetKeymap.of([
137
+ {
138
+ key: 'Tab',
139
+ run: acceptCompletionOrGotoNextSnippet,
140
+ shift: acceptCompletionOrGotoPrevSnippet,
141
+ },
142
+ { key: 'Escape', run: closeCompletionsOrClearSnippets },
143
+ ]),
144
+ );
145
+
128
146
  return extensions;
129
147
  };
148
+
149
+ // The logic to check if there's a completion open is surprisingly complex
150
+ // https://github.com/codemirror/autocomplete/blob/5ad2ebc861f2f61cdc943fc087a5bfb756a7d0fa/src/view.ts#L31
151
+ // For example it respects an interaction delay, so we can't just check if the completion is open
152
+ // instead we just run the acceptCompletion command which returns true if a completion was accepted
153
+ // in that case we know that we shouldn't move to the next snippet field
154
+ const acceptCompletionOrGotoNextSnippet: Command = (view: EditorView) => {
155
+ const didCompletion = acceptCompletion(view);
156
+ if (didCompletion) {
157
+ return true;
158
+ }
159
+
160
+ return nextSnippetField(view);
161
+ };
162
+
163
+ const acceptCompletionOrGotoPrevSnippet: Command = (view: EditorView) => {
164
+ const didCompletion = acceptCompletion(view);
165
+ if (didCompletion) {
166
+ return true;
167
+ }
168
+
169
+ return prevSnippetField(view);
170
+ };
171
+
172
+ const closeCompletionsOrClearSnippets: Command = (view: EditorView) => {
173
+ const closedCompletions = closeCompletion(view);
174
+ if (closedCompletions) {
175
+ return true;
176
+ }
177
+
178
+ return clearSnippet(view);
179
+ };
package/src/themes.ts CHANGED
@@ -3,8 +3,8 @@ import { light, mirage } from 'ayu';
3
3
  import {
4
4
  createCypherTheme,
5
5
  ThemeOptions,
6
- } from './lang-cypher/create-cypher-theme';
7
- import { tokens } from './ndl-tokens-copy';
6
+ } from './lang-cypher/createCypherTheme';
7
+ import { tokens } from './ndlTokensCopy';
8
8
 
9
9
  /* ndl exports most tokens as hex colors but some tokens are exported as rgb colors, in the form of "10, 20, 30"
10
10
  This should be fixed in version 2 of ndl.
@@ -60,6 +60,7 @@ export const lightThemeConstants: ThemeOptions = {
60
60
  paramDollar: light.syntax.regexp.hex(),
61
61
  paramValue: light.syntax.regexp.hex(),
62
62
  namespace: light.syntax.special.hex(),
63
+ consoleCommand: light.editor.fg.hex(),
63
64
  },
64
65
  };
65
66
 
@@ -101,6 +102,7 @@ export const darkThemeConstants: ThemeOptions = {
101
102
  paramDollar: mirage.syntax.regexp.hex(),
102
103
  paramValue: mirage.syntax.regexp.hex(),
103
104
  namespace: mirage.syntax.special.hex(),
105
+ consoleCommand: mirage.editor.fg.hex(),
104
106
  },
105
107
  };
106
108
 
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />