дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
The Services tool window listed services nobody added: an injected Docker connection, Spring Boot by default and every configuration that had ever run. Now only added types, connections and registries are listed, removal takes effect at once, an untouched injected Docker connection is dropped from older docker.json files, and the detail pane has a single scrollbar with console controls only (Run/Debug/Stop stay on the window toolbar). Co-authored-by: qtvbwfn <[email protected]>
99 рядки
3.3 KiB
TypeScript
99 рядки
3.3 KiB
TypeScript
/**
|
|
* The Services tree host: the root nodes service providers contribute, the
|
|
* selection and expansion, and which provider owns a node.
|
|
*/
|
|
import { create } from "zustand";
|
|
import type { MenuItem } from "@/ui";
|
|
import { serviceProviders, type ServiceProviderContribution, type ServiceTreeItem } from "@/workbench/contributions";
|
|
|
|
/** The service view (Services tool window tab) hosting the tree. */
|
|
export const SERVICES_TREE_VIEW = "services";
|
|
|
|
interface TreeState {
|
|
/** Root nodes per provider id (reported by each provider's `useRoots`). */
|
|
roots: Record<string, ServiceTreeItem[]>;
|
|
selectedKey: string | null;
|
|
selectedKeys: Set<string>;
|
|
expanded: Set<string>;
|
|
}
|
|
|
|
export const useServicesTree = create<TreeState>(() => ({
|
|
roots: {},
|
|
selectedKey: null,
|
|
selectedKeys: new Set(),
|
|
expanded: new Set(),
|
|
}));
|
|
|
|
/** Keys of nodes asking to start expanded that were shown once (collapsing them then sticks). */
|
|
const seenExpanded = new Set<string>();
|
|
|
|
export function setProviderRoots(provider: string, items: ServiceTreeItem[]) {
|
|
useServicesTree.setState((s) => {
|
|
if (s.roots[provider] === items) return s;
|
|
const fresh: string[] = [];
|
|
const visit = (i: ServiceTreeItem) => {
|
|
if (i.expanded && !seenExpanded.has(i.key)) {
|
|
seenExpanded.add(i.key);
|
|
fresh.push(i.key);
|
|
}
|
|
i.children?.forEach(visit);
|
|
};
|
|
items.forEach(visit);
|
|
const roots = { ...s.roots, [provider]: items };
|
|
return fresh.length ? { roots, expanded: new Set([...s.expanded, ...fresh]) } : { roots };
|
|
});
|
|
}
|
|
|
|
export function clearProviderRoots(provider: string) {
|
|
useServicesTree.setState((s) => {
|
|
if (!(provider in s.roots)) return s;
|
|
const roots = { ...s.roots };
|
|
delete roots[provider];
|
|
return { roots };
|
|
});
|
|
}
|
|
|
|
export interface Located {
|
|
item: ServiceTreeItem;
|
|
provider: string;
|
|
parent: ServiceTreeItem | null;
|
|
}
|
|
|
|
/** Every node by key, with the provider owning it. */
|
|
export function indexTree(roots: Record<string, readonly ServiceTreeItem[]>): Map<string, Located> {
|
|
const out = new Map<string, Located>();
|
|
const visit = (provider: string, item: ServiceTreeItem, parent: ServiceTreeItem | null) => {
|
|
out.set(item.key, { item, provider, parent });
|
|
item.children?.forEach((c) => visit(provider, c, item));
|
|
};
|
|
for (const [provider, items] of Object.entries(roots)) items.forEach((i) => visit(provider, i, null));
|
|
return out;
|
|
}
|
|
|
|
/** Roots of all providers, in provider order. */
|
|
export function orderedRoots(
|
|
roots: Record<string, readonly ServiceTreeItem[]>,
|
|
providers: readonly ServiceProviderContribution[],
|
|
): ServiceTreeItem[] {
|
|
return providers.flatMap((p) => roots[p.id] ?? []);
|
|
}
|
|
|
|
/** Keys of every expandable node (Expand All). */
|
|
export function expandableKeys(items: readonly ServiceTreeItem[]): string[] {
|
|
const out: string[] = [];
|
|
const visit = (i: ServiceTreeItem) => {
|
|
if (i.children?.length || i.expandable) {
|
|
out.push(i.key);
|
|
i.children?.forEach(visit);
|
|
}
|
|
};
|
|
items.forEach(visit);
|
|
return out;
|
|
}
|
|
|
|
/** The "Add Service" menu: every provider's entries, separated per provider. */
|
|
export function addServiceMenu(providers = serviceProviders()): MenuItem[] {
|
|
const groups = providers.map((p) => p.addMenu?.() ?? []).filter((g) => g.length > 0);
|
|
return groups.flatMap((g, i) => (i === 0 ? g : [{ kind: "separator" } as MenuItem, ...g]));
|
|
}
|