import { findCaret } from '../helpers.js';
import { createParsingResult, } from '../cypherLanguageService.js';
import { completionCoreCompletion } from './completionCoreCompletions.js';
export function autocomplete(query, dbSchema, { symbolsInfo, parsingResult, caretPosition = query.length, manual = false, consoleCommandsEnabled = true, } = {}) {
    const resolvedParsingResult = parsingResult ?? createParsingResult(query, { consoleCommandsEnabled });
    /* We try to locate the statement where the caret is and the token of the caret
  
       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
  
    */
    const caret = findCaret(resolvedParsingResult, caretPosition);
    if (caret) {
        const statement = caret.statement;
        const caretToken = caret.token;
        return completionCoreCompletion(statement, dbSchema, caretToken, symbolsInfo, manual, consoleCommandsEnabled);
    }
    return [];
}
//# sourceMappingURL=autocompletion.js.map