feat(database): support DuckDB SQL and browse attached catalogs (#6254)

DuckDB sources get DuckDB's SQL dialect (highlighting, completion, formatting and resolution) and the database tree lists attached catalogs with their schemas, tables and columns. The JDBC bridge gains a catalogs command and catalog-scoped schema and table metadata, matched by exact catalog and schema names; tables in another catalog open and page through the source session. DDL that attaches, detaches or changes a catalog refreshes the tree.

Co-authored-by: principalwater <[email protected]>
Цей коміт міститься в:
Vladislav Kuzmin authored and GitHub committed 2026-11-28 09:07:53 +08:00
1 джерело c04d9381be
коміт bd396485c2
38 files changed
+1743 -318

No files matched your search

+11 -5
Переглянути файл
@@ -17,25 +17,26 @@ import {
} from "@/editor/api";
import { setFileDiagnostics } from "@/editor/lsp/diagnostics";
import { showHint } from "@/editor/lsp/hint";
import type { DbCompletion, DbCompletionTable, DbDriver } from "@/platform/ipc";
import type { DbCompletion, DbCompletionTable } from "@/platform/ipc";
import { sqlDriverOf, type SqlDriver } from "./sql/dialect";
import { formatSql } from "./sql/format";
import { editorPrefs, sqlCaseStyle } from "@/platform/editorSettings";
import { SqlResolver, type SqlSymbol } from "./sql/resolve";
import { useProject } from "@/platform/project";
import { consoleSchema, consoleSource, revealInTree, sourceById, useDatabase } from "./store";
import { consoleSchema, consoleSource, duckdbCatalogTree, revealInTree, sourceById, useDatabase } from "./store";
/** Producer id of the console's diagnostics (Problems view, hover). */
const INSPECTIONS = "sql-inspections";
const INSPECT_DELAY = 400;
function sourceOf(path: string): { id: string | null; driver: DbDriver; model: DbCompletion | null } {
function sourceOf(path: string): { id: string | null; driver: SqlDriver; model: DbCompletion | null } {
const id = consoleSource(path);
const model = id ? (useDatabase.getState().completion[id] ?? null) : null;
// Unqualified names resolve in the console's active schema (IDEA's schema dropdown).
const schema = consoleSchema(path);
return {
id,
driver: sourceById(id)?.driver ?? "sqlite",
driver: sqlDriverOf(sourceById(id)),
model: model && schema ? { ...model, defaultSchema: schema } : model,
};
}
@@ -113,9 +114,14 @@ function definition(path: string, sql: SqlText): ContributedDefinition {
if (sql.at && !sql.at(view.state, pos)) return false;
const r = resolver(path, view.state, sql).resolveAt(pos);
const sym = r?.symbol;
const id = consoleSource(path);
if (r?.catalogTable && id && duckdbCatalogTree(sourceById(id))) {
const { catalog, schema, table } = r.catalogTable;
void revealInTree(id, schema, table, undefined, undefined, catalog);
return true;
}
// Outside SQL names, other providers (the XML language server) may know the place.
if (!sym && sql.at) return false;
const id = consoleSource(path);
const reveal = (t: DbCompletionTable, column?: string) => {
if (id) void revealInTree(id, t.schema, t.name, t.kind, column);
};