@neo4j-cypher/react-codemirror 2.0.0-next.16 → 2.0.0-next.17

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 (41) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/CypherEditor.d.ts +5 -1
  3. package/dist/CypherEditor.js +20 -0
  4. package/dist/CypherEditor.js.map +1 -1
  5. package/dist/e2e_tests/autoCompletion.spec.js +80 -35
  6. package/dist/e2e_tests/autoCompletion.spec.js.map +1 -1
  7. package/dist/e2e_tests/e2eUtils.d.ts +1 -0
  8. package/dist/e2e_tests/e2eUtils.js +13 -2
  9. package/dist/e2e_tests/e2eUtils.js.map +1 -1
  10. package/dist/e2e_tests/performanceTest.spec.js +1 -1
  11. package/dist/e2e_tests/performanceTest.spec.js.map +1 -1
  12. package/dist/e2e_tests/signatureHelp.spec.js +59 -13
  13. package/dist/e2e_tests/signatureHelp.spec.js.map +1 -1
  14. package/dist/e2e_tests/snippets.spec.js +2 -2
  15. package/dist/e2e_tests/snippets.spec.js.map +1 -1
  16. package/dist/e2e_tests/syntaxValidation.spec.js +25 -10
  17. package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -1
  18. package/dist/lang-cypher/autocomplete.js +9 -4
  19. package/dist/lang-cypher/autocomplete.js.map +1 -1
  20. package/dist/lang-cypher/langCypher.d.ts +1 -0
  21. package/dist/lang-cypher/langCypher.js +1 -8
  22. package/dist/lang-cypher/langCypher.js.map +1 -1
  23. package/dist/lang-cypher/lintWorker.d.ts +8 -4
  24. package/dist/lang-cypher/lintWorker.js +12 -2
  25. package/dist/lang-cypher/lintWorker.js.map +1 -1
  26. package/dist/lang-cypher/syntaxValidation.d.ts +0 -1
  27. package/dist/lang-cypher/syntaxValidation.js +2 -25
  28. package/dist/lang-cypher/syntaxValidation.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +2 -2
  31. package/src/CypherEditor.tsx +32 -4
  32. package/src/e2e_tests/autoCompletion.spec.tsx +119 -54
  33. package/src/e2e_tests/e2eUtils.ts +14 -2
  34. package/src/e2e_tests/performanceTest.spec.tsx +1 -1
  35. package/src/e2e_tests/signatureHelp.spec.tsx +74 -13
  36. package/src/e2e_tests/snippets.spec.tsx +2 -2
  37. package/src/e2e_tests/syntaxValidation.spec.tsx +58 -17
  38. package/src/lang-cypher/autocomplete.ts +13 -7
  39. package/src/lang-cypher/langCypher.ts +3 -12
  40. package/src/lang-cypher/lintWorker.ts +24 -7
  41. package/src/lang-cypher/syntaxValidation.ts +2 -39
@@ -1,14 +1,31 @@
1
- import { validateSemantics } from '@neo4j-cypher/language-support';
1
+ import {
2
+ DbSchema,
3
+ lintCypherQuery as _lintCypherQuery,
4
+ _internalFeatureFlags,
5
+ } from '@neo4j-cypher/language-support';
2
6
  import workerpool from 'workerpool';
3
7
 
4
- workerpool.worker({ validateSemantics });
8
+ function lintCypherQuery(
9
+ query: string,
10
+ dbSchema: DbSchema,
11
+ featureFlags: { consoleCommands?: boolean; cypher25?: boolean } = {},
12
+ ) {
13
+ // We allow to override the consoleCommands feature flag
14
+ if (featureFlags.consoleCommands !== undefined) {
15
+ _internalFeatureFlags.consoleCommands = featureFlags.consoleCommands;
16
+ }
17
+ if (featureFlags.cypher25 !== undefined) {
18
+ _internalFeatureFlags.cypher25 = featureFlags.cypher25;
19
+ }
20
+ return _lintCypherQuery(query, dbSchema);
21
+ }
5
22
 
6
- type LinterArgs = Parameters<typeof validateSemantics>;
23
+ workerpool.worker({ lintCypherQuery });
7
24
 
8
- export type LinterTask = workerpool.Promise<
9
- ReturnType<typeof validateSemantics>
10
- >;
25
+ type LinterArgs = Parameters<typeof lintCypherQuery>;
26
+
27
+ export type LinterTask = workerpool.Promise<ReturnType<typeof lintCypherQuery>>;
11
28
 
12
29
  export type LintWorker = {
13
- validateSemantics: (...args: LinterArgs) => LinterTask;
30
+ lintCypherQuery: (...args: LinterArgs) => LinterTask;
14
31
  };
@@ -1,6 +1,5 @@
1
1
  import { Diagnostic, linter } from '@codemirror/lint';
2
2
  import { Extension } from '@codemirror/state';
3
- import { parserWrapper, validateSyntax } from '@neo4j-cypher/language-support';
4
3
  import { DiagnosticSeverity, DiagnosticTag } from 'vscode-languageserver-types';
5
4
  import workerpool from 'workerpool';
6
5
  import type { CypherConfig } from './langCypher';
@@ -16,61 +15,25 @@ const pool = workerpool.pool(WorkerURL, {
16
15
  let lastSemanticJob: LinterTask | undefined;
17
16
 
18
17
  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
18
  linter(async (view) => {
44
19
  if (!config.lint) {
45
20
  return [];
46
21
  }
47
-
48
22
  const query = view.state.doc.toString();
49
23
  if (query.length === 0) {
50
24
  return [];
51
25
  }
52
26
 
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 = statements.some(
58
- (statement) => statement.syntaxErrors.length !== 0,
59
- );
60
-
61
- if (anySyntacticError) {
62
- return [];
63
- }
64
-
65
27
  try {
66
28
  if (lastSemanticJob !== undefined && !lastSemanticJob.resolved) {
67
29
  void lastSemanticJob.cancel();
68
30
  }
69
31
 
70
32
  const proxyWorker = (await pool.proxy()) as unknown as LintWorker;
71
- lastSemanticJob = proxyWorker.validateSemantics(
33
+ lastSemanticJob = proxyWorker.lintCypherQuery(
72
34
  query,
73
35
  config.schema ?? {},
36
+ config.featureFlags ?? {},
74
37
  );
75
38
  const result = await lastSemanticJob;
76
39