fix(editor): continue completion after selecting schemas
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
isSqlLikeCompletionStatement,
|
||||
recordCompletionSelection,
|
||||
shouldAutoOpenSqlCompletion,
|
||||
shouldChainSqlCompletionAfterAccept,
|
||||
extractCteDefinitions,
|
||||
} from "@/lib/sql/sqlCompletion";
|
||||
import { sqlCompletionContextFromSemantic } from "@/lib/sql/semantic/completion";
|
||||
@@ -1762,8 +1763,8 @@ function isTypedCompletionActivation(explicit: boolean) {
|
||||
return explicit && typedCompletionActivationUntil >= Date.now();
|
||||
}
|
||||
|
||||
function markCompletionAccepted() {
|
||||
suppressNextSqlCompletionAutoStartUntil = Date.now() + 750;
|
||||
function markCompletionAccepted(item: QueryCompletionItem) {
|
||||
suppressNextSqlCompletionAutoStartUntil = shouldChainSqlCompletionAfterAccept(item) ? 0 : Date.now() + 750;
|
||||
completionEpoch++;
|
||||
}
|
||||
|
||||
@@ -1820,7 +1821,7 @@ function completionOptionForItem(item: QueryCompletionItem) {
|
||||
...completion,
|
||||
apply(view: EditorViewType, completionItem: unknown, from: number, to: number) {
|
||||
record();
|
||||
markCompletionAccepted();
|
||||
markCompletionAccepted(item);
|
||||
if (typeof originalApply === "function") {
|
||||
originalApply(view, completionItem as never, from, to);
|
||||
} else {
|
||||
@@ -1841,7 +1842,7 @@ function completionOptionForItem(item: QueryCompletionItem) {
|
||||
boost: item.boost,
|
||||
apply(view: EditorViewType, _completionItem: unknown, from: number, to: number) {
|
||||
record();
|
||||
markCompletionAccepted();
|
||||
markCompletionAccepted(item);
|
||||
const insert = item.apply ?? item.label;
|
||||
if (codeMirrorInsertCompletionText) {
|
||||
view.dispatch(codeMirrorInsertCompletionText(view.state, insert, from, to));
|
||||
|
||||
@@ -1121,6 +1121,10 @@ export interface SqlCompletionItem {
|
||||
exactMatch?: boolean;
|
||||
}
|
||||
|
||||
export function shouldChainSqlCompletionAfterAccept(item: { type?: string; apply?: string }): boolean {
|
||||
return item.type === "schema" && item.apply?.endsWith(".") === true;
|
||||
}
|
||||
|
||||
export type SqlKeywordCase = "preserve" | "upper" | "lower";
|
||||
|
||||
export interface SqlCompletionReferencedTable {
|
||||
|
||||
+13
@@ -10,6 +10,7 @@ import {
|
||||
extractCteDefinitions,
|
||||
getSqlCompletionContext,
|
||||
recordCompletionSelection,
|
||||
shouldChainSqlCompletionAfterAccept,
|
||||
type SqlCompletionColumn,
|
||||
type SqlCompletionForeignKey,
|
||||
type SqlCompletionObject,
|
||||
@@ -623,6 +624,16 @@ test("keeps schema-qualified FROM object input in table suggestion mode", () =>
|
||||
);
|
||||
});
|
||||
|
||||
test("keeps an accepted schema with trailing dot in table suggestion mode", () => {
|
||||
const sql = "SELECT *\nFROM DBX_TEST.";
|
||||
const context = getSqlCompletionContext(sql, sql.length);
|
||||
|
||||
assert.equal(context.qualifier, "DBX_TEST");
|
||||
assert.equal(context.prefix, "");
|
||||
assert.equal(context.suggestTables, true);
|
||||
assert.equal(context.exclusiveTableSuggestions, true);
|
||||
});
|
||||
|
||||
test("keeps database-qualified FROM input in table suggestion mode", () => {
|
||||
const sql = "select * from other_db.or";
|
||||
const context = getSqlCompletionContext(sql, sql.length);
|
||||
@@ -1827,6 +1838,8 @@ test("schema items include apply value with trailing dot", () => {
|
||||
const schemaItems = items.filter((item) => item.type === "schema");
|
||||
assert.equal(schemaItems.length, 1);
|
||||
assert.equal(schemaItems[0]?.apply, "public.");
|
||||
assert.equal(shouldChainSqlCompletionAfterAccept(schemaItems[0]!), true);
|
||||
assert.equal(shouldChainSqlCompletionAfterAccept({ type: "table", apply: "users" }), false);
|
||||
});
|
||||
|
||||
// --- Quoted identifier fix ---
|
||||
|
||||
Reference in New Issue
Block a user