fix(editor): improve SQL completion insertion
This commit is contained in:
11 files changed
+101
-2
No files matched your search
@@ -0,0 +1,14 @@
|
||||
export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "property" | "text";
|
||||
|
||||
const COMPLETION_SPACE_BLOCKING_CHARACTERS = new Set([",", ";", ":", ")", "]", "}", "'", '"']);
|
||||
|
||||
export function appendSqlCompletionSpace(insertText: string, options: { enabled: boolean; itemType: SqlCompletionItemType; nextCharacter?: string }): string {
|
||||
if (!options.enabled || options.itemType === "property" || options.itemType === "text" || options.itemType === "schema" || options.itemType === "snippet" || options.itemType === "function") return insertText;
|
||||
if (!insertText || /\s$/.test(insertText) || insertText.endsWith(".")) return insertText;
|
||||
|
||||
const nextCharacter = options.nextCharacter ?? "";
|
||||
if (/\s/.test(nextCharacter) || COMPLETION_SPACE_BLOCKING_CHARACTERS.has(nextCharacter)) return insertText;
|
||||
|
||||
// Avoid producing `table AS t,` or `column)` when the cursor is before SQL punctuation.
|
||||
return `${insertText} `;
|
||||
}
|
||||
Reference in new issue
Block a user