feat(search): open standalone plugin workbenches from quick open
This commit is contained in:
14 files changed
+154
-16
No files matched your search
@@ -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<ConnectionConfig["db_type"]>(["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<void> | null = null;
|
||||
let sqlFilesLoadGeneration = 0;
|
||||
const pluginWorkbenchItems = ref<QuickOpenItem[]>([]);
|
||||
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<void> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user