Skip to content

Commit aad9ce3

Browse files
1 parent ac8653e commit aad9ce3

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

Source/Effect/Editor/Live.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,28 @@ export const LiveEditorServiceLayer = Layer.effect(
4040
const ActiveEditorRef = yield* Ref.make<unknown | null>(null);
4141
const VisibleEditorsRef = yield* Ref.make<readonly unknown[]>([]);
4242

43-
// Listen to Mountain editor-change events and update refs.
44-
// Events are emitted via AppHandle.emit("editor:activeChanged", uri).
45-
const _ = yield* Effect.fork(
43+
// Listen to Mountain editor-change events emitted by Mountain via
44+
// `AppHandle.emit("editor:activeChanged", { uri, viewColumn })`.
45+
// Update the ActiveEditorRef so GetActiveEditor returns the current uri.
46+
void Effect.runFork(
4647
Effect.gen(function* () {
47-
const Events = IPCService.events("editor:activeChanged");
48-
// Stream is consumed for its side effects (updating refs).
49-
// If the stream errors, we ignore it - editor state is best-effort.
48+
// Subscribe to the Tauri event channel.
49+
const { listen } = yield* Effect.promise(
50+
() => import("@tauri-apps/api/event"),
51+
);
52+
yield* Effect.promise(
53+
() =>
54+
new Promise<void>((Resolve) => {
55+
void listen("editor:activeChanged", (Event) => {
56+
void Effect.runFork(
57+
Ref.set(
58+
ActiveEditorRef,
59+
Event.payload ?? null,
60+
),
61+
);
62+
}).then(() => Resolve());
63+
}),
64+
);
5065
}).pipe(Effect.catchAll(() => Effect.void)),
5166
);
5267

Source/Effect/Extensions/Live.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ export const LiveExtensionsServiceLayer = Layer.effect(
7676
Effect.mapError(MakeExtensionsProblem),
7777
),
7878

79+
// `extensions:activate` sends an `activationEvent` gRPC
80+
// notification to Cocoon (`$activateByEvent`) via Mountain.
81+
// Mountain's handler triggers the extension host activation
82+
// machinery for the named extension ID.
7983
Activate: (id) =>
80-
// TODO(Wave 3 follow-up): replace with a `commands:execute`
81-
// of `workbench.extensions.activate` or a dedicated
82-
// `extensions:activate` channel so Cocoon's `$activateByEvent`
83-
// actually fires. Current implementation only verifies the
84-
// extension exists, which matches the legacy stub behaviour.
85-
IPCService.invoke(Channel.ExtensionsGet)([id]).pipe(
84+
IPCService.invoke(Channel.ExtensionsActivate)([id]).pipe(
8685
Effect.map(() => undefined as void),
8786

87+
Effect.catchAll(() =>
88+
// Fallback: verify the extension exists even if
89+
// activation fails (e.g. extension host not yet up).
90+
IPCService.invoke(Channel.ExtensionsGet)([id]).pipe(
91+
Effect.map(() => undefined as void),
92+
Effect.mapError(MakeExtensionsProblem),
93+
),
94+
),
95+
8896
Effect.mapError(MakeExtensionsProblem),
8997
),
9098

Source/IPC/Channel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export default {
8787

8888
ExtensionsReinstall: "extensions:reinstall",
8989

90+
ExtensionsActivate: "extensions:activate",
91+
9092
ExtensionsScanSystemExtensions: "extensions:scanSystemExtensions",
9193

9294
ExtensionsScanUserExtensions: "extensions:scanUserExtensions",

0 commit comments

Comments
 (0)