-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathautocompletion.ts
36 lines (29 loc) · 1.22 KB
/
autocompletion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { CompletionItem } from 'vscode-languageserver-types';
import { DbSchema } from '../dbSchema';
import { findLatestStatement } from '../helpers';
import { parserWrapper } from '../parserWrapper';
import { completionCoreCompletion } from './completionCoreCompletions';
export function autocomplete(
textUntilPosition: string,
dbSchema: DbSchema,
): CompletionItem[] {
let parsingResult = parserWrapper.parse(textUntilPosition);
/* We try to locate the latest statement by finding the latest available `;`
in the query and take from that point to the end of the query
The reason for doing that is we need a way to "resynchronise" when the
previous statements have errors and the parser fails from them onwards:
MATCH (m) REUT m; CREATE (n) R
^ we should still be getting autocompletions here
If there was no ;, we don't want to reparse, so we return undefined
inside findLatestStatement
*/
const lastStatement = findLatestStatement(parsingResult);
if (lastStatement != undefined) {
parsingResult = parserWrapper.parse(lastStatement);
}
return completionCoreCompletion(
parsingResult,
dbSchema,
parserWrapper.enableConsoleCommands,
);
}