feat(editor): batch-select and insert SQL completion columns

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-30 00:47:57 +08:00
1 parent 1637948023
commit bd3e585628
15 files changed
+440 -14

No files matched your search

@@ -0,0 +1,19 @@
export type BatchColumnSelectionMode = "select" | "insert";
export function batchColumnSelectionColumnList(candidates: string[], mode: BatchColumnSelectionMode, qualifier?: string): string {
return candidates.map((candidate, index) => (mode === "select" && qualifier && index > 0 ? `${qualifier}.${candidate}` : candidate)).join(", ");
}
export function shouldResolveSqlColumnCompletion(options: { suggestColumns: boolean; hasReferencedTables: boolean; prefix: string; typedActivation: boolean; selectListColumnContext: boolean }): boolean {
return options.suggestColumns && options.hasReferencedTables && (options.prefix.length > 0 || options.typedActivation || options.selectListColumnContext);
}
/**
* The INSERT batch action writes its own closing parenthesis before VALUES.
* Consume an existing one (normally inserted by CodeMirror's auto-close
* brackets extension) so the resulting statement has exactly one `)`.
*/
export function batchColumnSelectionReplaceTo(options: { to: number; mode: BatchColumnSelectionMode; nextCharacter: string; replaceClosingQuote?: string }): number {
const { to, mode, nextCharacter, replaceClosingQuote } = options;
return replaceClosingQuote === nextCharacter || (mode === "insert" && nextCharacter === ")") ? to + 1 : to;
}