@neo4j-cypher/react-codemirror 2.0.0-next.0 → 2.0.0-next.10
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.
- package/CHANGELOG.md +85 -0
- package/README.md +4 -1
- package/dist/{types/CypherEditor.d.ts → CypherEditor.d.ts} +69 -8
- package/dist/CypherEditor.js +300 -0
- package/dist/CypherEditor.js.map +1 -0
- package/dist/CypherEditor.test.js +151 -0
- package/dist/CypherEditor.test.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/e2e_tests/autoCompletion.spec.js +267 -0
- package/dist/e2e_tests/autoCompletion.spec.js.map +1 -0
- package/dist/e2e_tests/configuration.spec.js +83 -0
- package/dist/e2e_tests/configuration.spec.js.map +1 -0
- package/dist/e2e_tests/debounce.spec.js +65 -0
- package/dist/e2e_tests/debounce.spec.js.map +1 -0
- package/dist/e2e_tests/e2eUtils.js +60 -0
- package/dist/e2e_tests/e2eUtils.js.map +1 -0
- package/dist/e2e_tests/extraKeybindings.spec.js +43 -0
- package/dist/e2e_tests/extraKeybindings.spec.js.map +1 -0
- package/dist/e2e_tests/historyNavigation.spec.js +227 -0
- package/dist/e2e_tests/historyNavigation.spec.js.map +1 -0
- package/dist/e2e_tests/performanceTest.spec.d.ts +6 -0
- package/dist/e2e_tests/performanceTest.spec.js +96 -0
- package/dist/e2e_tests/performanceTest.spec.js.map +1 -0
- package/dist/e2e_tests/sanityChecks.spec.js +53 -0
- package/dist/e2e_tests/sanityChecks.spec.js.map +1 -0
- package/dist/e2e_tests/signatureHelp.spec.js +179 -0
- package/dist/e2e_tests/signatureHelp.spec.js.map +1 -0
- package/dist/e2e_tests/snippets.spec.js +62 -0
- package/dist/e2e_tests/snippets.spec.js.map +1 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.js +90 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
- package/dist/e2e_tests/syntaxValidation.spec.d.ts +1 -0
- package/dist/e2e_tests/syntaxValidation.spec.js +79 -0
- package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -0
- package/dist/historyNavigation.d.ts +7 -0
- package/dist/historyNavigation.js +163 -0
- package/dist/historyNavigation.js.map +1 -0
- package/dist/{types/icons.d.ts → icons.d.ts} +1 -1
- package/dist/icons.js +62 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lang-cypher/autocomplete.d.ts +6 -0
- package/dist/lang-cypher/autocomplete.js +124 -0
- package/dist/lang-cypher/autocomplete.js.map +1 -0
- package/dist/{types/lang-cypher → lang-cypher}/constants.d.ts +9 -0
- package/dist/lang-cypher/constants.js +65 -0
- package/dist/lang-cypher/constants.js.map +1 -0
- package/dist/lang-cypher/contants.test.d.ts +1 -0
- package/dist/lang-cypher/contants.test.js +103 -0
- package/dist/lang-cypher/contants.test.js.map +1 -0
- package/dist/lang-cypher/createCypherTheme.js +179 -0
- package/dist/lang-cypher/createCypherTheme.js.map +1 -0
- package/dist/lang-cypher/langCypher.d.ts +14 -0
- package/dist/lang-cypher/langCypher.js +30 -0
- package/dist/lang-cypher/langCypher.js.map +1 -0
- package/dist/lang-cypher/lintWorker.d.ts +8 -0
- package/dist/lang-cypher/lintWorker.js +4 -0
- package/dist/lang-cypher/lintWorker.js.map +1 -0
- package/dist/lang-cypher/parser-adapter.d.ts +19 -0
- package/dist/lang-cypher/parser-adapter.js +113 -0
- package/dist/lang-cypher/parser-adapter.js.map +1 -0
- package/dist/lang-cypher/signatureHelp.d.ts +4 -0
- package/dist/lang-cypher/signatureHelp.js +94 -0
- package/dist/lang-cypher/signatureHelp.js.map +1 -0
- package/dist/lang-cypher/syntaxValidation.d.ts +5 -0
- package/dist/lang-cypher/syntaxValidation.js +69 -0
- package/dist/lang-cypher/syntaxValidation.js.map +1 -0
- package/dist/lang-cypher/themeIcons.js +22 -0
- package/dist/lang-cypher/themeIcons.js.map +1 -0
- package/dist/lang-cypher/utils.d.ts +2 -0
- package/dist/lang-cypher/utils.js +10 -0
- package/dist/lang-cypher/utils.js.map +1 -0
- package/dist/ndlTokensCopy.js +380 -0
- package/dist/ndlTokensCopy.js.map +1 -0
- package/dist/ndlTokensCopy.test.d.ts +1 -0
- package/dist/ndlTokensCopy.test.js +12 -0
- package/dist/ndlTokensCopy.test.js.map +1 -0
- package/dist/neo4jSetup.js +120 -0
- package/dist/neo4jSetup.js.map +1 -0
- package/dist/{types/themes.d.ts → themes.d.ts} +1 -1
- package/dist/themes.js +114 -0
- package/dist/themes.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +30 -31
- package/src/CypherEditor.test.tsx +200 -0
- package/src/CypherEditor.tsx +292 -41
- package/src/constants.ts +1 -0
- package/src/e2e_tests/autoCompletion.spec.tsx +472 -0
- package/src/e2e_tests/configuration.spec.tsx +111 -0
- package/src/e2e_tests/debounce.spec.tsx +101 -0
- package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +11 -1
- package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
- package/src/e2e_tests/historyNavigation.spec.tsx +315 -0
- package/src/e2e_tests/performanceTest.spec.tsx +158 -0
- package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
- package/src/e2e_tests/signatureHelp.spec.tsx +380 -0
- package/src/e2e_tests/snippets.spec.tsx +92 -0
- package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +1 -3
- package/src/e2e_tests/{syntax-validation.spec.tsx → syntaxValidation.spec.tsx} +6 -7
- package/src/{repl-mode.ts → historyNavigation.ts} +7 -30
- package/src/icons.ts +3 -0
- package/src/index.ts +5 -3
- package/src/lang-cypher/autocomplete.ts +107 -15
- package/src/lang-cypher/constants.ts +23 -0
- package/src/lang-cypher/contants.test.ts +6 -2
- package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +41 -2
- package/src/lang-cypher/langCypher.ts +53 -0
- package/src/lang-cypher/lintWorker.ts +14 -0
- package/src/lang-cypher/parser-adapter.ts +145 -0
- package/src/lang-cypher/signatureHelp.ts +133 -0
- package/src/lang-cypher/syntaxValidation.ts +96 -0
- package/src/lang-cypher/utils.ts +9 -0
- package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
- package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +51 -1
- package/src/themes.ts +4 -2
- package/src/viteEnv.d.ts +1 -0
- package/dist/cjs/index.cjs +0 -1455
- package/dist/cjs/index.cjs.map +0 -7
- package/dist/esm/index.mjs +0 -1468
- package/dist/esm/index.mjs.map +0 -7
- package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
- package/dist/types/index.d.ts +0 -5
- package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
- package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
- package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
- package/dist/types/lang-cypher/syntax-validation.d.ts +0 -3
- package/dist/types/repl-mode.d.ts +0 -8
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/src/e2e_tests/auto-completion.spec.tsx +0 -232
- package/src/e2e_tests/history-navigation.spec.tsx +0 -144
- package/src/e2e_tests/mock-data.ts +0 -4310
- package/src/e2e_tests/performance-test.spec.tsx +0 -71
- package/src/lang-cypher/ParserAdapter.ts +0 -92
- package/src/lang-cypher/lang-cypher.ts +0 -32
- package/src/lang-cypher/syntax-validation.ts +0 -24
- /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → CypherEditor.test.d.ts} +0 -0
- /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → e2e_tests/autoCompletion.spec.d.ts} +0 -0
- /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → e2e_tests/configuration.spec.d.ts} +0 -0
- /package/dist/{types/e2e_tests/performance-test.spec.d.ts → e2e_tests/debounce.spec.d.ts} +0 -0
- /package/dist/{types/e2e_tests/e2e-utils.d.ts → e2e_tests/e2eUtils.d.ts} +0 -0
- /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → e2e_tests/extraKeybindings.spec.d.ts} +0 -0
- /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → e2e_tests/historyNavigation.spec.d.ts} +0 -0
- /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → e2e_tests/sanityChecks.spec.d.ts} +0 -0
- /package/dist/{types/lang-cypher/contants.test.d.ts → e2e_tests/signatureHelp.spec.d.ts} +0 -0
- /package/dist/{types/ndl-tokens-copy.test.d.ts → e2e_tests/snippets.spec.d.ts} +0 -0
- /package/dist/{types/lang-cypher/create-cypher-theme.d.ts → lang-cypher/createCypherTheme.d.ts} +0 -0
- /package/dist/{types/lang-cypher/theme-icons.d.ts → lang-cypher/themeIcons.d.ts} +0 -0
- /package/dist/{types/ndl-tokens-copy.d.ts → ndlTokensCopy.d.ts} +0 -0
- /package/dist/{types/neo4j-setup.d.ts → neo4jSetup.d.ts} +0 -0
- /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
- /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
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@neo4j-ndl/base';
|
|
2
|
-
import {
|
|
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/
|
|
7
|
-
import { tokens } from './
|
|
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
|
|
package/src/viteEnv.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|