fix(sqlserver): honor USE context in completions
This commit is contained in:
1 parent
f64d363abe
commit
486a73ef09
16 files changed
+974
-114
No files matched your search
@@ -10,6 +10,7 @@ import type {
|
||||
DatabaseType,
|
||||
DatabaseConnectionInfo,
|
||||
DatabaseStorageInfo,
|
||||
SqlServerCompletionContext,
|
||||
CatalogInfo,
|
||||
ForeignKeyInfo,
|
||||
ObjectInfo,
|
||||
@@ -340,6 +341,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const completionColumnsCache = ref<Record<string, ColumnInfo[]>>({});
|
||||
const completionForeignKeysCache = ref<Record<string, ForeignKeyInfo[]>>({});
|
||||
const completionDatabasesCache = ref<Record<string, string[]>>({});
|
||||
const sqlServerCompletionContextCache = ref<Record<string, SqlServerCompletionContext>>({});
|
||||
const elasticsearchCompletionIndicesCache = ref<Record<string, string[]>>({});
|
||||
const redisCompletionKeysCache = ref<Record<string, string[]>>({});
|
||||
const mongoCompletionCollectionsCache = ref<Record<string, string[]>>({});
|
||||
@@ -2310,6 +2312,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
for (const key of Object.keys(schemaListCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete schemaListCache.value[key];
|
||||
}
|
||||
for (const key of Object.keys(sqlServerCompletionContextCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete sqlServerCompletionContextCache.value[key];
|
||||
}
|
||||
for (const key of Object.keys(elasticsearchCompletionIndicesCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete elasticsearchCompletionIndicesCache.value[key];
|
||||
}
|
||||
@@ -5417,8 +5422,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
): Promise<SqlCompletionObject[]> {
|
||||
const databaseType = getConfig(connectionId)?.db_type;
|
||||
const oracleAssistant = databaseType === "oracle";
|
||||
const requestedSchema = currentSchema?.trim() || schema?.trim() || undefined;
|
||||
const preferredSchema = oracleAssistant ? completionPreferredSchema(connectionId, currentSchema) : requestedSchema || (databaseType === "sqlserver" ? "dbo" : databaseType === "postgres" ? "public" : databaseType === "mysql" ? database : undefined);
|
||||
const requestedSchema = schema?.trim() || currentSchema?.trim() || undefined;
|
||||
const preferredSchema = oracleAssistant ? completionPreferredSchema(connectionId, currentSchema) : requestedSchema || (databaseType === "postgres" ? "public" : databaseType === "mysql" ? database : undefined);
|
||||
const response = await completionAssistantSearch({
|
||||
connection_id: connectionId,
|
||||
database,
|
||||
@@ -5666,6 +5671,20 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
);
|
||||
}
|
||||
|
||||
async function getSqlServerCompletionContext(connectionId: string, database: string): Promise<SqlServerCompletionContext> {
|
||||
const cacheKey = `${connectionId}:${database}`;
|
||||
if (sqlServerCompletionContextCache.value[cacheKey]) {
|
||||
return sqlServerCompletionContextCache.value[cacheKey];
|
||||
}
|
||||
return withCompletionInFlight(`${cacheKey}:sqlserver-completion-context`, async () => {
|
||||
await ensureConnected(connectionId);
|
||||
const context = await api.getSqlServerCompletionContext(connectionId, database);
|
||||
sqlServerCompletionContextCache.value[cacheKey] = context;
|
||||
evictOldestCacheEntries(sqlServerCompletionContextCache.value, COMPLETION_CACHE_MAX);
|
||||
return context;
|
||||
});
|
||||
}
|
||||
|
||||
async function listCompletionSchemas(connectionId: string, database: string): Promise<string[]> {
|
||||
const cacheKey = `${connectionId}:${database}`;
|
||||
if (schemaListCache.value[cacheKey]) {
|
||||
@@ -6776,6 +6795,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
listCompletionForeignKeys,
|
||||
listCompletionSchemas,
|
||||
listCompletionDatabases,
|
||||
getSqlServerCompletionContext,
|
||||
lookupLocalCompletionTables,
|
||||
lookupLocalCompletionObjects,
|
||||
lookupLocalCompletionColumns,
|
||||
|
||||
Reference in new issue
Block a user