diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index 5a1800b025..e18c9dc51e 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -3144,6 +3144,12 @@ async function handleQuickOpenSelect(item: any) { return; } + // Standalone plugin workbenches open without a database connection + if (item.type === "plugin_workbench" && item.pluginId && item.contributionId) { + queryStore.openPluginWorkbench(item.pluginId, item.contributionId, { title: item.label }); + return; + } + // For all other types, set the active connection connectionStore.activeConnectionId = item.connectionId; diff --git a/apps/desktop/src/components/quick-open/QuickOpenDialog.vue b/apps/desktop/src/components/quick-open/QuickOpenDialog.vue index c484a942bc..457e76a837 100644 --- a/apps/desktop/src/components/quick-open/QuickOpenDialog.vue +++ b/apps/desktop/src/components/quick-open/QuickOpenDialog.vue @@ -4,6 +4,7 @@ import { useI18n } from "vue-i18n"; import { Command, FileCode, FileText, Search, FolderPlus, SlidersHorizontal, X } from "@lucide/vue"; import { Dialog, DialogContent } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; +import PluginIcon from "@/components/plugins/PluginIcon.vue"; import { useQuickOpen, type QuickOpenItem } from "@/composables/useQuickOpen"; import { useSettingsStore } from "@/stores/settingsStore"; import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay"; @@ -21,7 +22,7 @@ const emit = defineEmits<{ }>(); const { t } = useI18n(); -const { searchQuery, filteredItems, selectedIndex, selectedItem, selectNext, selectPrevious, setQuery, loadExternalSqlFiles, contentMode, contentGroups, contentSelectedItem, contentSearching, setContentMode } = useQuickOpen(); +const { searchQuery, filteredItems, selectedIndex, selectedItem, selectNext, selectPrevious, setQuery, loadExternalSqlFiles, loadPluginWorkbenches, contentMode, contentGroups, contentSelectedItem, contentSearching, setContentMode } = useQuickOpen(); const inputRef = ref(null); const listRef = ref(null); const settingsStore = useSettingsStore(); @@ -198,6 +199,8 @@ function getTypeLabel(type: string): string { return t("quickOpen.sqlFile"); case "sql_library_file": return t("quickOpen.sqlLibraryFile"); + case "plugin_workbench": + return t("quickOpen.pluginWorkbench"); default: return type; } @@ -219,6 +222,8 @@ watch( refreshSearchSettings(); // Eagerly load external SQL files so they appear in the initial list void loadExternalSqlFiles(); + // Refresh plugin workbench entries so installs/uninstalls show up without a restart + void loadPluginWorkbenches(); nextTick(() => { inputRef.value?.focus(); }); @@ -362,6 +367,7 @@ watch(selectedIndex, async () => {
+
diff --git a/apps/desktop/src/composables/__tests__/useQuickOpen.spec.ts b/apps/desktop/src/composables/__tests__/useQuickOpen.spec.ts index 119734ea04..de40c677c1 100644 --- a/apps/desktop/src/composables/__tests__/useQuickOpen.spec.ts +++ b/apps/desktop/src/composables/__tests__/useQuickOpen.spec.ts @@ -17,6 +17,7 @@ vi.mock("@/stores/savedSqlStore", () => ({ vi.mock("@/lib/backend/api", () => ({ listSqlFilesInFolder: vi.fn(), readExternalSqlFile: vi.fn(), + listPlugins: vi.fn(), })); vi.mock("@/lib/sqlFile/sqlFileFolders", async () => { @@ -532,6 +533,65 @@ describe("useQuickOpen", () => { }); }); + describe("plugin workbenches", () => { + function installedPluginFixture(id: string, name: string, contributions: any[]) { + return { + manifest: { id, name, version: "1.0.0", contributions }, + compatibility: { compatible: true }, + } as any; + } + + it("lists standalone workbenches and skips ones bound to a connection provider", async () => { + vi.mocked(useConnectionStore).mockReturnValue({ connections: [], treeNodes: [] } as any); + vi.mocked(api.listPlugins).mockResolvedValue([ + installedPluginFixture("io.leetcode", "LeetCode", [{ type: "workbench", id: "main", label: "LeetCode" }]), + installedPluginFixture("io.kafka", "Kafka", [ + { type: "connection-provider", id: "kafka", label: "Kafka", database_type: "kafka", fields: [], workbench: "browser" }, + { type: "workbench", id: "browser", label: "Kafka Browser" }, + ]), + installedPluginFixture("io.terminal", "Terminal", [ + { type: "connection-provider", id: "ssh", label: "SSH", database_type: "ssh", fields: [] }, + { type: "workbench", id: "shell", label: "Terminal" }, + ]), + installedPluginFixture("io.mixed", "Mixed", [ + { type: "connection-provider", id: "cp", label: "Mixed", database_type: "mixed", fields: [], workbench: "bound" }, + { type: "workbench", id: "bound", label: "Bound Panel" }, + { type: "workbench", id: "free", label: "Free Panel" }, + ]), + ]); + + const { filteredItems, loadPluginWorkbenches } = useQuickOpen(); + await loadPluginWorkbenches(); + + const labels = filteredItems.value.map((item) => item.label); + expect(labels).toContain("LeetCode"); + // A provider without a workbench pointer leaves its sibling workbench standalone. + expect(labels).toContain("Terminal"); + // Only the unbound workbench of a mixed plugin is listed. + expect(labels).toContain("Free Panel"); + expect(labels).not.toContain("Kafka Browser"); + expect(labels).not.toContain("Bound Panel"); + }); + + it("finds workbenches by plugin name and carries the dispatch fields", async () => { + vi.mocked(useConnectionStore).mockReturnValue({ connections: [], treeNodes: [] } as any); + vi.mocked(api.listPlugins).mockResolvedValue([installedPluginFixture("io.leetcode", "LeetCode", [{ type: "workbench", id: "main", label: "刷题面板", icon: "assets/icon.png" }])]); + + const { filteredItems, loadPluginWorkbenches, setQuery } = useQuickOpen(); + await loadPluginWorkbenches(); + + setQuery("leetcode"); + expect(filteredItems.value.length).toBe(1); + const item = filteredItems.value[0]; + expect(item.type).toBe("plugin_workbench"); + expect(item.pluginId).toBe("io.leetcode"); + expect(item.contributionId).toBe("main"); + expect(item.description).toBe("LeetCode"); + expect(item.pluginIcon).toBe("assets/icon.png"); + expect(item.connectionId).toBe(""); + }); + }); + describe("item selection navigation", () => { it("should initialize with selectedIndex at 0", () => { const mockStore = { diff --git a/apps/desktop/src/composables/useQuickOpen.ts b/apps/desktop/src/composables/useQuickOpen.ts index 26a63bf242..b327bec1cb 100644 --- a/apps/desktop/src/composables/useQuickOpen.ts +++ b/apps/desktop/src/composables/useQuickOpen.ts @@ -9,7 +9,8 @@ import type { SqlFileEntry } from "@/lib/backend/api"; import { getSqlFileFilter, getSqlFileFolderPaths, sqlFileFoldersVersion } from "@/lib/sqlFile/sqlFileFolders"; import { composeGlobalSearchRoots, getGlobalSearchExtensions, globalSearchSettingsVersion } from "@/lib/globalSearch/globalSearchSettings"; import { containsHan, pinyinFirstLetters } from "@/lib/common/pinyin"; -import i18n from "@/i18n"; +import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin"; +import i18n, { currentLocale } from "@/i18n"; const REMOTE_SEARCH_DEBOUNCE_MS = 180; const REMOTE_SEARCH_MIN_QUERY_LENGTH = 2; @@ -28,7 +29,7 @@ const REMOTE_SEARCH_UNSUPPORTED_TYPES = new Set(["r export interface QuickOpenItem { id: string; - type: "connection" | "database" | "schema" | "table" | "view" | "materialized_view" | "procedure" | "function" | "sequence" | "package" | "package-body" | "sql_file" | "sql_library_file" | "content_match"; + type: "connection" | "plugin_workbench" | "database" | "schema" | "table" | "view" | "materialized_view" | "procedure" | "function" | "sequence" | "package" | "package-body" | "sql_file" | "sql_library_file" | "content_match"; label: string; description?: string; connectionId: string; @@ -46,6 +47,9 @@ export interface QuickOpenItem { matchText?: string; // For content matches: matched slice lineText?: string; // For content matches: full matching line highlightIndices?: [number, number]; // For content matches: [start, end) chars into lineText to highlight + pluginId?: string; // For plugin workbenches: plugin manifest id + contributionId?: string; // For plugin workbenches: workbench contribution id + pluginIcon?: string; // For plugin workbenches: contribution icon path, falling back to the manifest icon } export type QuickOpenMatchKind = "exact" | "initials" | "prefix" | "word-prefix" | "substring" | "fuzzy"; @@ -282,6 +286,8 @@ export function useQuickOpen() { let sqlFilesLoaded = false; let sqlFilesLoadingPromise: Promise | null = null; let sqlFilesLoadGeneration = 0; + const pluginWorkbenchItems = ref([]); + let pluginWorkbenchesLoading = false; // --- Content search mode (global search of local SQL/text file contents) --- const contentMode = ref(false); @@ -477,6 +483,47 @@ export function useQuickOpen() { return sqlFileItems.value.slice(0, INITIAL_SQL_FILE_LIMIT); }); + /** + * Refresh quick-open entries for plugin workbenches that no connection + * provider claims. A workbench bound via a provider's `workbench` pointer is + * opened through its connection (which quick open already lists as a + * connection item with full context), so listing it here would only offer a + * contextless dead end. Unclaimed workbenches otherwise have no entry point + * outside the Plugin Center's Installed tab. + * Re-runs on every dialog open so installs/uninstalls show up without a restart. + */ + async function loadPluginWorkbenches(): Promise { + if (pluginWorkbenchesLoading) return; + pluginWorkbenchesLoading = true; + try { + const registry = createFrontendPluginRegistry(await api.listPlugins(), currentLocale()); + const connectionBound = new Set( + registry + .listConnectionProviders() + .filter((entry) => entry.contribution.workbench) + .map((entry) => `${entry.plugin.manifest.id}/${entry.contribution.workbench}`), + ); + pluginWorkbenchItems.value = registry + .listWorkbenches() + .filter((entry) => !connectionBound.has(`${entry.plugin.manifest.id}/${entry.contribution.id}`)) + .map((entry) => ({ + id: `pluginwb-${entry.plugin.manifest.id}-${entry.contribution.id}`, + type: "plugin_workbench" as const, + label: entry.contribution.label, + description: entry.plugin.manifest.name, + connectionId: "", + pluginId: entry.plugin.manifest.id, + contributionId: entry.contribution.id, + pluginIcon: entry.contribution.icon || entry.plugin.manifest.icon, + searchText: `${entry.plugin.manifest.name} ${entry.contribution.label} ${entry.contribution.id}`, + })); + } catch { + // Plugin listings are best-effort; quick open keeps working without them. + } finally { + pluginWorkbenchesLoading = false; + } + } + const allItems = computed((): QuickOpenItem[] => { const items: QuickOpenItem[] = []; const connections = connectionStore.connections; @@ -494,6 +541,10 @@ export function useQuickOpen() { }); } + // Standalone plugin workbenches sit right after connections so they stay + // reachable in the no-query list before the (much longer) tree items. + items.push(...pluginWorkbenchItems.value); + // Add databases and tables from tree nodes // Filter tree nodes by connection for (const conn of connections) { @@ -851,6 +902,9 @@ export function useQuickOpen() { if (normalizedQuery.length > 0 && !sqlFilesLoaded && !sqlFilesLoadingPromise) { void loadExternalSqlFiles(); } + if (normalizedQuery.length > 0) { + void loadPluginWorkbenches(); + } if (normalizedQuery.length < REMOTE_SEARCH_MIN_QUERY_LENGTH) return; const contexts = remoteSearchContexts(); @@ -902,19 +956,20 @@ export function useQuickOpen() { const typeOrder = { connection: 0, - database: 1, - schema: 2, - table: 3, - view: 4, - materialized_view: 5, - procedure: 6, - function: 7, - sequence: 8, - package: 9, - "package-body": 10, - sql_library_file: 11, - sql_file: 12, - content_match: 13, + plugin_workbench: 1, + database: 2, + schema: 3, + table: 4, + view: 5, + materialized_view: 6, + procedure: 7, + function: 8, + sequence: 9, + package: 10, + "package-body": 11, + sql_library_file: 12, + sql_file: 13, + content_match: 14, }; const typeDifference = typeOrder[a.type] - typeOrder[b.type]; if (typeDifference !== 0) return typeDifference; @@ -1016,5 +1071,6 @@ export function useQuickOpen() { resetSelection, setQuery, loadExternalSqlFiles, + loadPluginWorkbenches, }; } diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts index 1d466e6528..9d7a5b081c 100644 --- a/apps/desktop/src/i18n/locales/az.ts +++ b/apps/desktop/src/i18n/locales/az.ts @@ -2552,6 +2552,7 @@ export default withEnglishFallback({ close: "Bağla", sqlFile: "SQL faylı", sqlLibraryFile: "SQL kitabxanası", + pluginWorkbench: "Plagin", searchingContent: "Fayl məzmunu axtarılır…", globalSearchHint: "Qlobal fayl məzmunu axtarışı", modeObjects: "Obyektlər və faylları axtar", diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 8a23e4ede7..2d0a51e554 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -2724,6 +2724,7 @@ export default { close: "Close", sqlFile: "SQL File", sqlLibraryFile: "SQL Library", + pluginWorkbench: "Plugin", searchingContent: "Searching file contents…", globalSearchHint: "Global content search", modeObjects: "Search objects and files", diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index 55922701db..30f77b0134 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -2624,6 +2624,7 @@ export default withEnglishFallback({ close: "Cerrar", sqlFile: "Archivo SQL", sqlLibraryFile: "Biblioteca SQL", + pluginWorkbench: "Plugin", searchingContent: "Buscando en el contenido de archivos…", globalSearchHint: "Búsqueda global de contenido de archivos", modeObjects: "Buscar objetos y archivos", diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index 245f95f7ac..df2f6b3379 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -2621,6 +2621,7 @@ export default withEnglishFallback({ close: "Chiudi", sqlFile: "File SQL", sqlLibraryFile: "Libreria SQL", + pluginWorkbench: "Plugin", searchingContent: "Ricerca nel contenuto dei file…", globalSearchHint: "Ricerca globale nel contenuto dei file", modeObjects: "Cerca oggetti e file", diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts index 7696866342..a860c8918a 100644 --- a/apps/desktop/src/i18n/locales/ja.ts +++ b/apps/desktop/src/i18n/locales/ja.ts @@ -2647,6 +2647,7 @@ export default withEnglishFallback({ close: "閉じる", sqlFile: "SQLファイル", sqlLibraryFile: "SQLライブラリ", + pluginWorkbench: "プラグイン", searchingContent: "ファイル内容を検索中…", globalSearchHint: "グローバルファイル内容検索", modeObjects: "オブジェクトとファイルを検索", diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts index 7b69357663..fe92b07c47 100644 --- a/apps/desktop/src/i18n/locales/ko.ts +++ b/apps/desktop/src/i18n/locales/ko.ts @@ -2530,6 +2530,7 @@ export default withEnglishFallback({ close: "닫기", sqlFile: "SQL 파일", sqlLibraryFile: "SQL 라이브러리", + pluginWorkbench: "플러그인", searchingContent: "파일 내용 검색 중…", globalSearchHint: "전역 파일 내용 검색", modeObjects: "객체 및 파일 검색", diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index 4857689c6a..fbbadce3b4 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -2623,6 +2623,7 @@ export default withEnglishFallback({ close: "Fechar", sqlFile: "Arquivo SQL", sqlLibraryFile: "Biblioteca SQL", + pluginWorkbench: "Plugin", searchingContent: "Pesquisando conteúdo dos arquivos…", globalSearchHint: "Pesquisa global de conteúdo de arquivos", modeObjects: "Pesquisar objetos e arquivos", diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts index 8f3ba843ca..4157920058 100644 --- a/apps/desktop/src/i18n/locales/tr.ts +++ b/apps/desktop/src/i18n/locales/tr.ts @@ -2530,6 +2530,7 @@ export default withEnglishFallback({ close: "Kapat", sqlFile: "SQL Dosyası", sqlLibraryFile: "SQL Kitaplığı", + pluginWorkbench: "Eklenti", searchingContent: "Dosya içerikleri aranıyor…", globalSearchHint: "Genel dosya içeriği arama", modeObjects: "Nesne ve dosya ara", diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index 43b08c80f9..8dcad4869e 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -2636,6 +2636,7 @@ export default withEnglishFallback({ close: "关闭", sqlFile: "SQL文件", sqlLibraryFile: "SQL库", + pluginWorkbench: "插件", searchingContent: "正在搜索文件内容…", globalSearchHint: "全局文件内容搜索", modeObjects: "搜索对象与文件", diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts index ecb9109d33..0448381733 100644 --- a/apps/desktop/src/i18n/locales/zh-TW.ts +++ b/apps/desktop/src/i18n/locales/zh-TW.ts @@ -2621,6 +2621,7 @@ export default withEnglishFallback({ close: "關閉", sqlFile: "SQL檔案", sqlLibraryFile: "SQL庫", + pluginWorkbench: "外掛", searchingContent: "正在搜尋檔案內容…", globalSearchHint: "全域檔案內容搜尋", modeObjects: "搜尋物件與檔案",