fix(completion): stop appending space before statement terminators
This commit is contained in:
4 files changed
+11
-1
No files matched your search
@@ -17,6 +17,13 @@ describe("SQL completion insertion", () => {
|
||||
expect(appendSqlCompletionSpace("orders", { enabled: true, itemType: "table", nextCharacter: "," })).toBe("orders");
|
||||
});
|
||||
|
||||
it("keeps the space when a statement terminator follows the cursor", () => {
|
||||
// Completing `BETWEEN` before an existing `;` must not glue the two together,
|
||||
// otherwise the user cannot keep typing the operand without fixing the text.
|
||||
expect(appendSqlCompletionSpace("BETWEEN", { enabled: true, itemType: "keyword", nextCharacter: ";" })).toBe("BETWEEN ");
|
||||
expect(appendSqlCompletionSpace("SALARY", { enabled: true, itemType: "column", nextCharacter: ";" })).toBe("SALARY ");
|
||||
});
|
||||
|
||||
it("honors the setting and leaves snippet-like completions unchanged", () => {
|
||||
expect(appendSqlCompletionSpace("SELECT", { enabled: false, itemType: "keyword" })).toBe("SELECT");
|
||||
expect(appendSqlCompletionSpace("CASE ${value}", { enabled: true, itemType: "snippet" })).toBe("CASE ${value}");
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "property" | "text";
|
||||
|
||||
const COMPLETION_SPACE_BLOCKING_CHARACTERS = new Set([",", ";", ":", ")", "]", "}", "'", '"']);
|
||||
// `;` is deliberately absent: a statement terminator is never glued to the token
|
||||
// in front of it, and accepting `BETWEEN` before an existing `;` used to insert
|
||||
// `BETWEEN;`, leaving the user no way to keep typing the operand.
|
||||
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 === "variable" || options.itemType === "snippet" || options.itemType === "function") return insertText;
|
||||
|
||||
Reference in new issue
Block a user