дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
feat(plugins): reload linked plugins when their files change (#7888)
Plugins linked with openidea-plugin link are read in place, but edits showed only after Reload. Each linked folder is now watched (.git, target, node_modules and editor temp files ignored); a change wakes the plugin event pump, which reloads the plugin under the lifecycle lock. Installed and project plugins are not watched. A reloaded plugin that provides the selected theme restyles in place: the theme setting is reconciled after the contribution swap instead of in between, so the IDE no longer drops to the built-in theme. Co-authored-by: Bruno0416 <[email protected]>
Цей коміт міститься в:
1 джерело
ab08c3d245
коміт
5bfdaf679d
12 files changed
+490
-21
No files matched your search
@@ -32,6 +32,7 @@ import {
|
||||
pluginActionId,
|
||||
startPluginBridge,
|
||||
syncProjection,
|
||||
trackPluginTheme,
|
||||
} from "../bridge";
|
||||
import { iconResolver, selectedIconTheme, useIconThemes } from "../iconThemes";
|
||||
import { markerIcon, placeMarkers } from "../lineMarkerGutter";
|
||||
@@ -429,6 +430,47 @@ describe("store", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("restyles the selected plugin theme in place when its plugin reloads with new tokens", async () => {
|
||||
const stop = [syncProjection(), followThemeSetting(), trackPluginTheme()];
|
||||
const root = document.documentElement;
|
||||
const observer = new MutationObserver(() => {});
|
||||
try {
|
||||
useProject.setState({ settings: { appearance: { theme: "plugin:theme-harbor-night/harbor-night" } } as never });
|
||||
await refreshPlugins();
|
||||
await waitFor(() => expect(usePlugins.getState().activeTheme?.theme.id).toBe("harbor-night"));
|
||||
expect(document.getElementById(PLUGIN_THEME_STYLE_ID)?.textContent).toContain("--bg-frame: #1f252e");
|
||||
|
||||
// A reload swaps the contribution: the host announces the new theme and the list follows.
|
||||
const snapshot = await backend.list();
|
||||
const edit = <T extends { tokens?: Record<string, string> }>(t: T): T => ({
|
||||
...t,
|
||||
tokens: { ...t.tokens, "--bg-frame": "#123456" },
|
||||
});
|
||||
const reloaded = {
|
||||
...snapshot,
|
||||
ui: snapshot.ui.map((c) => (c.point === "themes" ? { ...c, decl: edit(c.decl as never) } : c)),
|
||||
activeTheme: { ...snapshot.activeTheme!, theme: edit(snapshot.activeTheme!.theme) },
|
||||
};
|
||||
const setTheme = vi.spyOn(backend, "setTheme");
|
||||
setPluginsBackend({ ...backend, list: async () => reloaded });
|
||||
observer.observe(root, { attributes: true, attributeOldValue: true, attributeFilter: ["data-plugin-theme"] });
|
||||
handlePluginEvent({ type: "themeChanged", theme: reloaded.activeTheme });
|
||||
expect(document.getElementById(PLUGIN_THEME_STYLE_ID)?.textContent).toContain("--bg-frame: #123456");
|
||||
await refreshPlugins();
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
|
||||
expect(document.getElementById(PLUGIN_THEME_STYLE_ID)?.textContent).toContain("--bg-frame: #123456");
|
||||
expect(setTheme).not.toHaveBeenCalled();
|
||||
// The theme attribute was never dropped on the way (no flash to the built-in theme).
|
||||
expect(observer.takeRecords().every((r) => r.oldValue === "theme-harbor-night/harbor-night")).toBe(true);
|
||||
expect(usePlugins.getState().activeTheme?.theme.tokens["--bg-frame"]).toBe("#123456");
|
||||
} finally {
|
||||
observer.disconnect();
|
||||
stop.forEach((s) => s());
|
||||
useProject.setState({ settings: null as never });
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves a theme another window selected alone until this window's settings change", async () => {
|
||||
const stop = [syncProjection(), followThemeSetting()];
|
||||
try {
|
||||
|
||||
@@ -223,7 +223,20 @@ export function followThemeSetting(): () => void {
|
||||
void selectPluginTheme(want && target ? want.pluginId : null, want && target ? want.themeId : null);
|
||||
};
|
||||
reconcile();
|
||||
// A reloaded plugin replaces its theme (removed, then added again within one synchronous
|
||||
// sync): looking in between would read the selected theme as gone and deselect it.
|
||||
let scheduled = false;
|
||||
let stopped = false;
|
||||
const reconcileSoon = () => {
|
||||
if (scheduled) return;
|
||||
scheduled = true;
|
||||
queueMicrotask(() => {
|
||||
scheduled = false;
|
||||
if (!stopped) reconcile();
|
||||
});
|
||||
};
|
||||
const disposers = [
|
||||
() => (stopped = true),
|
||||
// Not on the host's theme changing: another window selects it before this one's settings
|
||||
// say so, and selecting this window's choice back would flip it until they agree.
|
||||
usePlugins.subscribe((s, prev) => {
|
||||
@@ -233,7 +246,7 @@ export function followThemeSetting(): () => void {
|
||||
if (s.settings?.appearance !== prev.settings?.appearance) reconcile();
|
||||
}),
|
||||
useThemeOverride.subscribe(reconcile),
|
||||
useContributedThemes.subscribe(reconcile),
|
||||
useContributedThemes.subscribe(reconcileSoon),
|
||||
subscribeScheme(reconcile),
|
||||
];
|
||||
return () => disposers.forEach((d) => d());
|
||||
|
||||
Reference in new issue
Заблокувати користувача