fix(completion): add contains fallback for first fuzzy input
This commit is contained in:
5 files changed
+106
-12
No files matched your search
@@ -6,6 +6,7 @@ import { DEFAULT_QUERY_TIMEOUT_SECS } from "@/lib/connection/timeoutLimits";
|
||||
import type {
|
||||
ColumnInfo,
|
||||
CompletionAssistantCandidate,
|
||||
CompletionAssistantMatchMode,
|
||||
CompletionAssistantObjectKind,
|
||||
CompletionAssistantRequest,
|
||||
ConnectionConfig,
|
||||
@@ -7625,7 +7626,29 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}));
|
||||
}
|
||||
|
||||
async function listCompletionAssistantTables(connectionId: string, database: string, filter: string, limit?: number, schema?: string, globalSearch = false, currentSchema?: string, requestRevision = completionCacheRevision(connectionId, database)): Promise<SqlCompletionTable[]> {
|
||||
/**
|
||||
* The completion assistant matches names by prefix only, while the warm local
|
||||
* index also matches substrings. Without widening, the very first fuzzy lookup
|
||||
* of a connection (empty local index) returns far fewer candidates than the
|
||||
* same lookup once the index is warm. Widening to a substring search keeps the
|
||||
* two paths consistent whenever the prefix search left room in the result list.
|
||||
*/
|
||||
function shouldWidenCompletionMatch(filter: string, resultCount: number, limit?: number): boolean {
|
||||
if (filter.trim().length < 3) return false;
|
||||
return limit === undefined || resultCount < limit;
|
||||
}
|
||||
|
||||
async function listCompletionAssistantTables(
|
||||
connectionId: string,
|
||||
database: string,
|
||||
filter: string,
|
||||
limit?: number,
|
||||
schema?: string,
|
||||
globalSearch = false,
|
||||
currentSchema?: string,
|
||||
requestRevision = completionCacheRevision(connectionId, database),
|
||||
matchMode: CompletionAssistantMatchMode = "prefix",
|
||||
): Promise<SqlCompletionTable[]> {
|
||||
const oracleAssistant = getConfig(connectionId)?.db_type === "oracle";
|
||||
const preferredSchema = oracleAssistant ? completionPreferredSchema(connectionId, globalSearch ? currentSchema : (schema ?? currentSchema)) : schema?.trim() || undefined;
|
||||
const objectKinds: CompletionAssistantObjectKind[] = ["table", "view"];
|
||||
@@ -7639,7 +7662,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
max_results: limit ?? 200,
|
||||
global_search: globalSearch,
|
||||
parent_schema: globalSearch ? null : (schema ?? null),
|
||||
match_mode: "prefix",
|
||||
match_mode: matchMode,
|
||||
},
|
||||
requestRevision,
|
||||
);
|
||||
@@ -7659,6 +7682,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
currentSchema: string | undefined,
|
||||
objectKinds: CompletionAssistantObjectKind[],
|
||||
caseSensitive: boolean,
|
||||
matchMode: CompletionAssistantMatchMode = "prefix",
|
||||
): Promise<SqlCompletionObject[]> {
|
||||
const databaseType = getConfig(connectionId)?.db_type;
|
||||
const oracleAssistant = databaseType === "oracle";
|
||||
@@ -7676,7 +7700,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
global_search: globalSearch,
|
||||
parent_schema: globalSearch || sequenceOnly ? null : (schema ?? null),
|
||||
parent_name: parentName ?? null,
|
||||
match_mode: "prefix",
|
||||
match_mode: matchMode,
|
||||
});
|
||||
const objects = completionAssistantObjects(response.candidates, preferredSchema, oracleAssistant).map((object) => ({
|
||||
...object,
|
||||
@@ -8176,6 +8200,14 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
try {
|
||||
results = await listCompletionAssistantTables(connectionId, database, trimmedFilter, limit, schema, globalSearch, currentSchema, requestRevision);
|
||||
assistantCompleted = true;
|
||||
if (shouldWidenCompletionMatch(trimmedFilter, results.length, limit)) {
|
||||
try {
|
||||
const widenedTables = await listCompletionAssistantTables(connectionId, database, trimmedFilter, limit, schema, globalSearch, currentSchema, requestRevision, "contains");
|
||||
results = dedupeCompletionTables([...results, ...widenedTables]);
|
||||
} catch {
|
||||
// Keep the prefix matches when the widened lookup is unavailable.
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
if (schema) {
|
||||
const tables = await listCompletionTableMetadata(connectionId, database, schema, trimmedFilter, limit, catalog);
|
||||
@@ -8309,7 +8341,16 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await ensureConnected(connectionId);
|
||||
if (filteredRoutineAssistant) {
|
||||
try {
|
||||
completionObjectsCache.value[cacheKey] = dedupeCompletionObjects(await listCompletionAssistantObjects(connectionId, database, filter, limit, schema, parentName, globalSearch, currentSchema, objectKinds, caseSensitive));
|
||||
let assistantObjects = await listCompletionAssistantObjects(connectionId, database, filter, limit, schema, parentName, globalSearch, currentSchema, objectKinds, caseSensitive);
|
||||
if (shouldWidenCompletionMatch(filter, assistantObjects.length, limit)) {
|
||||
try {
|
||||
const widenedObjects = await listCompletionAssistantObjects(connectionId, database, filter, limit, schema, parentName, globalSearch, currentSchema, objectKinds, caseSensitive, "contains");
|
||||
assistantObjects = [...assistantObjects, ...widenedObjects];
|
||||
} catch {
|
||||
// Keep the prefix matches when the widened lookup is unavailable.
|
||||
}
|
||||
}
|
||||
completionObjectsCache.value[cacheKey] = dedupeCompletionObjects(assistantObjects);
|
||||
} catch {
|
||||
if (objectKinds.length === 1 && objectKinds[0] === "sequence") {
|
||||
completionObjectsCache.value[cacheKey] = [];
|
||||
|
||||
Reference in new issue
Block a user