@neo4j-cypher/react-codemirror 2.0.0-next.2 → 2.0.0-next.20
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 +166 -0
- package/dist/{types/CypherEditor.d.ts → CypherEditor.d.ts} +82 -3
- package/dist/CypherEditor.js +326 -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 +318 -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 +66 -0
- package/dist/e2e_tests/debounce.spec.js.map +1 -0
- package/dist/{types/e2e_tests/e2e-utils.d.ts → e2e_tests/e2eUtils.d.ts} +1 -0
- package/dist/e2e_tests/e2eUtils.js +71 -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 +97 -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 +228 -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 +116 -0
- package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -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 +115 -0
- package/dist/lang-cypher/autocomplete.js.map +1 -0
- package/dist/{types/lang-cypher → lang-cypher}/constants.d.ts +11 -0
- package/dist/lang-cypher/constants.js +69 -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 +182 -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 +23 -0
- package/dist/lang-cypher/langCypher.js.map +1 -0
- package/dist/lang-cypher/lintWorker.d.ts +12 -0
- package/dist/lang-cypher/lintWorker.js +14 -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 +109 -0
- package/dist/lang-cypher/signatureHelp.js.map +1 -0
- package/dist/{types/lang-cypher/syntax-validation.d.ts → lang-cypher/syntaxValidation.d.ts} +2 -1
- package/dist/lang-cypher/syntaxValidation.js +52 -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.d.ts +570 -0
- package/dist/ndlTokensCopy.js +571 -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.d.ts +6 -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 +93 -0
- package/dist/themes.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +32 -34
- package/src/CypherEditor.test.tsx +200 -0
- package/src/CypherEditor.tsx +311 -41
- package/src/constants.ts +1 -0
- package/src/e2e_tests/autoCompletion.spec.tsx +546 -0
- package/src/e2e_tests/configuration.spec.tsx +111 -0
- package/src/e2e_tests/debounce.spec.tsx +106 -0
- package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +24 -2
- package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
- package/src/e2e_tests/{history-navigation.spec.tsx → historyNavigation.spec.tsx} +137 -18
- package/src/e2e_tests/performanceTest.spec.tsx +163 -0
- package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
- package/src/e2e_tests/signatureHelp.spec.tsx +445 -0
- package/src/e2e_tests/snippets.spec.tsx +92 -0
- package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +26 -24
- package/src/e2e_tests/{syntax-validation.spec.tsx → syntaxValidation.spec.tsx} +97 -10
- package/src/{history-navigation.ts → historyNavigation.ts} +1 -1
- package/src/icons.ts +3 -0
- package/src/index.ts +2 -2
- package/src/lang-cypher/autocomplete.ts +100 -18
- package/src/lang-cypher/constants.ts +27 -0
- package/src/lang-cypher/contants.test.ts +6 -2
- package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +44 -2
- package/src/lang-cypher/langCypher.ts +43 -0
- package/src/lang-cypher/lintWorker.ts +31 -0
- package/src/lang-cypher/parser-adapter.ts +145 -0
- package/src/lang-cypher/signatureHelp.ts +151 -0
- package/src/lang-cypher/syntaxValidation.ts +66 -0
- package/src/lang-cypher/utils.ts +9 -0
- package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
- package/src/ndlTokensCopy.ts +570 -0
- package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +78 -17
- package/src/themes.ts +45 -70
- package/src/viteEnv.d.ts +1 -0
- package/dist/cjs/index.cjs +0 -1440
- package/dist/cjs/index.cjs.map +0 -7
- package/dist/esm/index.mjs +0 -1463
- 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 -4
- 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/ndl-tokens-copy.d.ts +0 -379
- package/dist/types/neo4j-setup.d.ts +0 -2
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/src/e2e_tests/auto-completion.spec.tsx +0 -232
- 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/src/ndl-tokens-copy.ts +0 -379
- /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/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/history-navigation.d.ts → historyNavigation.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/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
import { Input, NodeType, Parser, PartialParse, Tree } from '@lezer/common';
|
|
3
|
+
import {
|
|
4
|
+
applySyntaxColouring,
|
|
5
|
+
ParsedCypherToken,
|
|
6
|
+
} from '@neo4j-cypher/language-support';
|
|
7
|
+
|
|
8
|
+
import Prism from 'prismjs';
|
|
9
|
+
import {
|
|
10
|
+
CodemirrorParseTokenType,
|
|
11
|
+
cypherTokenTypeToNode,
|
|
12
|
+
parserAdapterNodeSet,
|
|
13
|
+
} from './constants';
|
|
14
|
+
// This import will load the cypher support in prisma
|
|
15
|
+
import 'prismjs/components/prism-cypher';
|
|
16
|
+
import { CypherConfig } from './langCypher';
|
|
17
|
+
|
|
18
|
+
const DEFAULT_NODE_GROUP_SIZE = 4;
|
|
19
|
+
Prism.manual = true;
|
|
20
|
+
|
|
21
|
+
export class ParserAdapter extends Parser {
|
|
22
|
+
cypherTokenTypeToNode: Record<CodemirrorParseTokenType, NodeType>;
|
|
23
|
+
|
|
24
|
+
constructor(facet: Facet<unknown>, private config: CypherConfig) {
|
|
25
|
+
super();
|
|
26
|
+
this.cypherTokenTypeToNode = cypherTokenTypeToNode(facet);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
createParse(input: Input): PartialParse {
|
|
30
|
+
return this.startParse(input);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* There are more arguments, but since we don't do any incremental parsing, they are not useful */
|
|
34
|
+
startParse(input: string | Input): PartialParse {
|
|
35
|
+
const document =
|
|
36
|
+
typeof input === 'string' ? input : input.read(0, input.length);
|
|
37
|
+
|
|
38
|
+
const tree = this.buildTree(document);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
stoppedAt: input.length,
|
|
42
|
+
parsedPos: input.length,
|
|
43
|
+
stopAt: () => {
|
|
44
|
+
return undefined;
|
|
45
|
+
},
|
|
46
|
+
advance: () => tree,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private buildTree(document: string) {
|
|
51
|
+
const parse = this.config.useLightVersion
|
|
52
|
+
? this.prismParse(document)
|
|
53
|
+
: this.antlrParse(document);
|
|
54
|
+
|
|
55
|
+
if (parse.tokens.length === 0) {
|
|
56
|
+
return this.createEmptyTree(document);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const buffer =
|
|
60
|
+
parse.type === 'prism'
|
|
61
|
+
? this.createBufferForPrismTokens(parse.tokens)
|
|
62
|
+
: this.createBufferForAntlrTokens(parse.tokens);
|
|
63
|
+
|
|
64
|
+
this.addTopNodeToBuffer(buffer, document);
|
|
65
|
+
|
|
66
|
+
return Tree.build({
|
|
67
|
+
buffer: buffer.flat(),
|
|
68
|
+
nodeSet: parserAdapterNodeSet(this.cypherTokenTypeToNode),
|
|
69
|
+
topID: this.cypherTokenTypeToNode.topNode.id,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private antlrParse(document: string) {
|
|
74
|
+
const startTime = performance.now();
|
|
75
|
+
const tokens = applySyntaxColouring(document);
|
|
76
|
+
const timeTaken = performance.now() - startTime;
|
|
77
|
+
if (timeTaken > 300) {
|
|
78
|
+
this.config.setUseLightVersion?.(true);
|
|
79
|
+
}
|
|
80
|
+
return { type: 'antlr' as const, tokens };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private prismParse(document: string) {
|
|
84
|
+
if (document.length === 0) {
|
|
85
|
+
this.config.setUseLightVersion?.(false);
|
|
86
|
+
}
|
|
87
|
+
const tokens = Prism.tokenize(document, Prism.languages.cypher);
|
|
88
|
+
return {
|
|
89
|
+
type: 'prism' as const,
|
|
90
|
+
tokens,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
private createBufferForAntlrTokens(tokens: ParsedCypherToken[]) {
|
|
94
|
+
return tokens.map((token) => {
|
|
95
|
+
const nodeTypeId = this.cypherTokenTypeToNode[token.tokenType].id;
|
|
96
|
+
const startOffset = token.position.startOffset;
|
|
97
|
+
const endOffset = token.position.startOffset + token.length;
|
|
98
|
+
|
|
99
|
+
return [nodeTypeId, startOffset, endOffset, DEFAULT_NODE_GROUP_SIZE];
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private createBufferForPrismTokens(tokens: (string | Prism.Token)[]) {
|
|
104
|
+
let totalOffset = 0;
|
|
105
|
+
return tokens.map((token) => {
|
|
106
|
+
const tokenType = (
|
|
107
|
+
typeof token === 'string' ? 'variable' : token.type
|
|
108
|
+
) as CodemirrorParseTokenType;
|
|
109
|
+
|
|
110
|
+
const nodeTypeId = this.cypherTokenTypeToNode[tokenType].id;
|
|
111
|
+
const startOffset = totalOffset;
|
|
112
|
+
const endOffset = startOffset + token.length;
|
|
113
|
+
totalOffset = endOffset;
|
|
114
|
+
|
|
115
|
+
return [nodeTypeId, startOffset, endOffset, DEFAULT_NODE_GROUP_SIZE];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private createEmptyTree(document: string) {
|
|
120
|
+
return Tree.build({
|
|
121
|
+
buffer: [
|
|
122
|
+
this.cypherTokenTypeToNode.topNode.id,
|
|
123
|
+
0,
|
|
124
|
+
document.length,
|
|
125
|
+
DEFAULT_NODE_GROUP_SIZE,
|
|
126
|
+
],
|
|
127
|
+
nodeSet: parserAdapterNodeSet(this.cypherTokenTypeToNode),
|
|
128
|
+
topID: this.cypherTokenTypeToNode.topNode.id,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private addTopNodeToBuffer(buffer: number[][], document: string) {
|
|
133
|
+
const id = this.cypherTokenTypeToNode.topNode.id;
|
|
134
|
+
const startOffset = 0;
|
|
135
|
+
const endOffset = document.length;
|
|
136
|
+
const totalBufferLength = buffer.length * DEFAULT_NODE_GROUP_SIZE;
|
|
137
|
+
|
|
138
|
+
buffer.push([
|
|
139
|
+
id,
|
|
140
|
+
startOffset,
|
|
141
|
+
endOffset,
|
|
142
|
+
totalBufferLength + DEFAULT_NODE_GROUP_SIZE,
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { EditorState, StateField } from '@codemirror/state';
|
|
2
|
+
import { showTooltip, Tooltip } from '@codemirror/view';
|
|
3
|
+
import { signatureHelp } from '@neo4j-cypher/language-support';
|
|
4
|
+
import {
|
|
5
|
+
MarkupContent,
|
|
6
|
+
SignatureInformation,
|
|
7
|
+
} from 'vscode-languageserver-types';
|
|
8
|
+
import { CypherConfig } from './langCypher';
|
|
9
|
+
import { getDocString } from './utils';
|
|
10
|
+
|
|
11
|
+
function getTriggerCharacter(query: string, caretPosition: number) {
|
|
12
|
+
let i = caretPosition - 1;
|
|
13
|
+
let triggerCharacter = query.at(i);
|
|
14
|
+
|
|
15
|
+
// Discard all space characters. Note that a space can be more than just a ' '
|
|
16
|
+
while (/\s/.test(triggerCharacter) && i > 0) {
|
|
17
|
+
i -= 1;
|
|
18
|
+
triggerCharacter = query.at(i);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return triggerCharacter;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const createSignatureHelpElement =
|
|
25
|
+
({
|
|
26
|
+
signature,
|
|
27
|
+
activeParameter,
|
|
28
|
+
}: {
|
|
29
|
+
signature: SignatureInformation;
|
|
30
|
+
activeParameter: number;
|
|
31
|
+
}) =>
|
|
32
|
+
() => {
|
|
33
|
+
const parameters = signature.parameters;
|
|
34
|
+
const doc = getDocString(signature.documentation);
|
|
35
|
+
const dom = document.createElement('div');
|
|
36
|
+
dom.className = 'cm-signature-help-panel';
|
|
37
|
+
|
|
38
|
+
const contents = document.createElement('div');
|
|
39
|
+
contents.className = 'cm-signature-help-panel-contents';
|
|
40
|
+
dom.appendChild(contents);
|
|
41
|
+
|
|
42
|
+
const signatureLabel = document.createElement('div');
|
|
43
|
+
signatureLabel.className = 'cm-signature-help-panel-name';
|
|
44
|
+
const methodName = signature.label.slice(0, signature.label.indexOf('('));
|
|
45
|
+
const returnType = signature.label.slice(signature.label.indexOf(')') + 1);
|
|
46
|
+
signatureLabel.appendChild(document.createTextNode(`${methodName}(`));
|
|
47
|
+
let currentParamDescription: string | undefined = undefined;
|
|
48
|
+
|
|
49
|
+
parameters.forEach((param, index) => {
|
|
50
|
+
if (typeof param.label === 'string') {
|
|
51
|
+
const span = document.createElement('span');
|
|
52
|
+
span.appendChild(document.createTextNode(param.label));
|
|
53
|
+
if (index !== parameters.length - 1) {
|
|
54
|
+
span.appendChild(document.createTextNode(', '));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (index === activeParameter) {
|
|
58
|
+
span.className = 'cm-signature-help-panel-current-argument';
|
|
59
|
+
const paramDoc = param.documentation;
|
|
60
|
+
currentParamDescription = MarkupContent.is(paramDoc)
|
|
61
|
+
? paramDoc.value
|
|
62
|
+
: paramDoc;
|
|
63
|
+
}
|
|
64
|
+
signatureLabel.appendChild(span);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
signatureLabel.appendChild(document.createTextNode(')'));
|
|
69
|
+
signatureLabel.appendChild(document.createTextNode(returnType));
|
|
70
|
+
|
|
71
|
+
contents.appendChild(signatureLabel);
|
|
72
|
+
|
|
73
|
+
const separator = document.createElement('div');
|
|
74
|
+
separator.className = 'cm-signature-help-panel-separator';
|
|
75
|
+
|
|
76
|
+
contents.appendChild(separator);
|
|
77
|
+
|
|
78
|
+
if (currentParamDescription !== undefined) {
|
|
79
|
+
const argDescription = document.createElement('div');
|
|
80
|
+
argDescription.className = 'cm-signature-help-panel-arg-description';
|
|
81
|
+
argDescription.appendChild(
|
|
82
|
+
document.createTextNode(currentParamDescription),
|
|
83
|
+
);
|
|
84
|
+
contents.appendChild(argDescription);
|
|
85
|
+
}
|
|
86
|
+
const methodDescription = document.createElement('div');
|
|
87
|
+
methodDescription.className = 'cm-signature-help-panel-description';
|
|
88
|
+
methodDescription.appendChild(document.createTextNode(doc));
|
|
89
|
+
contents.appendChild(methodDescription);
|
|
90
|
+
|
|
91
|
+
return { dom };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function getSignatureHelpTooltip(
|
|
95
|
+
state: EditorState,
|
|
96
|
+
config: CypherConfig,
|
|
97
|
+
): Tooltip[] {
|
|
98
|
+
let result: Tooltip[] = [];
|
|
99
|
+
const schema = config.schema;
|
|
100
|
+
const ranges = state.selection.ranges;
|
|
101
|
+
const range = ranges.at(0);
|
|
102
|
+
|
|
103
|
+
if (schema && ranges.length === 1 && range.from === range.to) {
|
|
104
|
+
const caretPosition = range.from;
|
|
105
|
+
const query = state.doc.toString();
|
|
106
|
+
|
|
107
|
+
const triggerCharacter = getTriggerCharacter(query, caretPosition);
|
|
108
|
+
|
|
109
|
+
if (triggerCharacter === '(' || triggerCharacter === ',') {
|
|
110
|
+
const signatureHelpInfo = signatureHelp(query, schema, caretPosition);
|
|
111
|
+
const activeSignature = signatureHelpInfo.activeSignature;
|
|
112
|
+
const signatures = signatureHelpInfo.signatures;
|
|
113
|
+
const activeParameter = signatureHelpInfo.activeParameter;
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
activeSignature !== undefined &&
|
|
117
|
+
activeSignature >= 0 &&
|
|
118
|
+
activeSignature < signatures.length &&
|
|
119
|
+
signatures[activeSignature].documentation !== undefined
|
|
120
|
+
) {
|
|
121
|
+
const signature = signatures[activeSignature];
|
|
122
|
+
const showSignatureTooltipBelow =
|
|
123
|
+
config.showSignatureTooltipBelow ?? true;
|
|
124
|
+
|
|
125
|
+
result = [
|
|
126
|
+
{
|
|
127
|
+
pos: caretPosition,
|
|
128
|
+
above: !showSignatureTooltipBelow,
|
|
129
|
+
arrow: true,
|
|
130
|
+
create: createSignatureHelpElement({ signature, activeParameter }),
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function signatureHelpTooltip(config: CypherConfig) {
|
|
141
|
+
return StateField.define<readonly Tooltip[]>({
|
|
142
|
+
create: (state) => getSignatureHelpTooltip(state, config),
|
|
143
|
+
|
|
144
|
+
update(tooltips, tr) {
|
|
145
|
+
if (!tr.docChanged && !tr.selection) return tooltips;
|
|
146
|
+
return getSignatureHelpTooltip(tr.state, config);
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
provide: (f) => showTooltip.computeN([f], (state) => state.field(f)),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Diagnostic, linter } from '@codemirror/lint';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
import { DiagnosticSeverity, DiagnosticTag } from 'vscode-languageserver-types';
|
|
4
|
+
import workerpool from 'workerpool';
|
|
5
|
+
import type { CypherConfig } from './langCypher';
|
|
6
|
+
import type { LinterTask, LintWorker } from './lintWorker';
|
|
7
|
+
import WorkerURL from './lintWorker?worker&url';
|
|
8
|
+
|
|
9
|
+
const pool = workerpool.pool(WorkerURL, {
|
|
10
|
+
minWorkers: 2,
|
|
11
|
+
workerOpts: { type: 'module' },
|
|
12
|
+
workerTerminateTimeout: 2000,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
let lastSemanticJob: LinterTask | undefined;
|
|
16
|
+
|
|
17
|
+
export const cypherLinter: (config: CypherConfig) => Extension = (config) =>
|
|
18
|
+
linter(async (view) => {
|
|
19
|
+
if (!config.lint) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const query = view.state.doc.toString();
|
|
23
|
+
if (query.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
if (lastSemanticJob !== undefined && !lastSemanticJob.resolved) {
|
|
29
|
+
void lastSemanticJob.cancel();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const proxyWorker = (await pool.proxy()) as unknown as LintWorker;
|
|
33
|
+
lastSemanticJob = proxyWorker.lintCypherQuery(
|
|
34
|
+
query,
|
|
35
|
+
config.schema ?? {},
|
|
36
|
+
config.featureFlags ?? {},
|
|
37
|
+
);
|
|
38
|
+
const result = await lastSemanticJob;
|
|
39
|
+
|
|
40
|
+
const a: Diagnostic[] = result.map((diagnostic) => {
|
|
41
|
+
return {
|
|
42
|
+
from: diagnostic.offsets.start,
|
|
43
|
+
to: diagnostic.offsets.end,
|
|
44
|
+
severity:
|
|
45
|
+
diagnostic.severity === DiagnosticSeverity.Error
|
|
46
|
+
? 'error'
|
|
47
|
+
: 'warning',
|
|
48
|
+
message: diagnostic.message,
|
|
49
|
+
...(diagnostic.tags !== undefined &&
|
|
50
|
+
diagnostic.tags.includes(DiagnosticTag.Deprecated)
|
|
51
|
+
? { markClass: 'cm-deprecated-element' }
|
|
52
|
+
: {}),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
return a;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (!(err instanceof workerpool.Promise.CancellationError)) {
|
|
58
|
+
console.error(String(err) + ' ' + query);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [];
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const cleanupWorkers = () => {
|
|
65
|
+
void pool.terminate();
|
|
66
|
+
};
|
|
@@ -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
|