Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extension/src/layers/KernelManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Effect, FiberSet, Layer, Option, Queue, Stream } from "effect";
import { Effect, Layer, Option, Queue, Runtime, Stream } from "effect";
import { unreachable } from "../assert.ts";
import { routeOperation } from "../operations.ts";
import { Config } from "../services/Config.ts";
Expand Down Expand Up @@ -47,7 +47,7 @@ export const KernelManagerLive = Layer.scopedDiscard(
const variables = yield* VariablesService;
const datasources = yield* DatasourcesService;

const runPromise = yield* FiberSet.makeRuntimePromise();
const runPromise = Runtime.runPromise(yield* Effect.runtime());

const queue = yield* Queue.unbounded<MarimoOperation>();

Expand Down
7 changes: 4 additions & 3 deletions extension/src/services/CellStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export class CellStateManager extends Effect.Service<CellStateManager>()(

// Helper to update context based on current state
const updateContext = Effect.fnUntraced(function* () {
const staleMap = yield* SubscriptionRef.get(staleStateRef);
const activeMarimoNotebook =
yield* editorRegistry.getActiveNotebookUri();
const [staleMap, activeMarimoNotebook] = yield* Effect.all([
SubscriptionRef.get(staleStateRef),
editorRegistry.getActiveNotebookUri(),
]);

// Check if the active marimo notebook has any stale cells
const hasStaleCells = Option.match(activeMarimoNotebook, {
Expand Down
12 changes: 7 additions & 5 deletions extension/src/services/DebugAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Effect, Fiber, FiberSet, Option, Stream } from "effect";
import { Effect, Option, Runtime, Stream } from "effect";
import type * as vscode from "vscode";

import { LanguageClient } from "./LanguageClient.ts";
Expand All @@ -19,7 +19,9 @@ export class DebugAdapter extends Effect.Service<DebugAdapter>()(
const client = yield* LanguageClient;
const serializer = yield* NotebookSerializer;

const runFork = yield* FiberSet.makeRuntime();
const runtime = yield* Effect.runtime();
const runFork = Runtime.runFork(runtime);
const runPromise = Runtime.runPromise(runtime);

const emitters = new Map<
string,
Expand Down Expand Up @@ -51,7 +53,7 @@ export class DebugAdapter extends Effect.Service<DebugAdapter>()(
return new code.DebugAdapterInlineImplementation({
onDidSendMessage: emitter.event,
handleMessage(message) {
runFork<never, void>(
runFork<void, never>(
Effect.gen(function* () {
yield* Effect.logDebug("Sending DAP message to LSP").pipe(
Effect.annotateLogs({
Expand Down Expand Up @@ -87,7 +89,7 @@ export class DebugAdapter extends Effect.Service<DebugAdapter>()(

yield* code.debug.registerDebugConfigurationProvider(debugType, {
resolveDebugConfiguration(_workspaceFolder, config) {
return runFork<never, vscode.DebugConfiguration | undefined>(
return runPromise<vscode.DebugConfiguration | undefined, never>(
Effect.gen(function* () {
yield* Effect.logInfo("Resolving debug configuration").pipe(
Effect.annotateLogs({ config }),
Expand Down Expand Up @@ -118,7 +120,7 @@ export class DebugAdapter extends Effect.Service<DebugAdapter>()(
);
return config;
}),
).pipe(Fiber.join, Effect.runPromise);
);
},
});

Expand Down
7 changes: 5 additions & 2 deletions extension/src/services/ExecutionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
type Brand,
Data,
Effect,
FiberSet,
HashMap,
Option,
Ref,
Runtime,
String,
} from "effect";
import type * as vscode from "vscode";
Expand Down Expand Up @@ -39,7 +39,10 @@ export class ExecutionRegistry extends Effect.Service<ExecutionRegistry>()(
return HashMap.empty();
}),
);
const runFork = yield* FiberSet.makeRuntime();

const runtime = yield* Effect.runtime();
const runFork = Runtime.runFork(runtime);

return {
handleInterrupted(editor: vscode.NotebookEditor) {
return Ref.update(ref, (map) =>
Expand Down
5 changes: 3 additions & 2 deletions extension/src/services/NotebookControllerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as semver from "@std/semver";
import type * as py from "@vscode/python-extension";
import { Brand, Data, Effect, FiberSet, Option } from "effect";
import { Brand, Data, Effect, Option, Runtime } from "effect";
import type * as vscode from "vscode";
import { unreachable } from "../assert.ts";
import { getNotebookUri } from "../types.ts";
Expand Down Expand Up @@ -34,7 +34,8 @@ export class NotebookControllerFactory extends Effect.Service<NotebookController
const validator = yield* EnvironmentValidator;
const serializer = yield* NotebookSerializer;

const runPromise = yield* FiberSet.makeRuntimePromise();
const runtime = yield* Effect.runtime();
const runPromise = Runtime.runPromise(runtime);

return {
createNotebookController: Effect.fnUntraced(function* (options: {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/services/NotebookSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
type Brand,
Effect,
Fiber,
FiberSet,
Option,
type ParseResult,
Runtime,
Schema,
} from "effect";
import type * as vscode from "vscode";
Expand Down Expand Up @@ -83,7 +83,7 @@ export class NotebookSerializer extends Effect.Service<NotebookSerializer>()(

if (Option.isSome(code)) {
// Register with VS Code if present
const runPromise = yield* FiberSet.makeRuntimePromise();
const runPromise = Runtime.runPromise(yield* Effect.runtime());

yield* code.value.workspace.registerNotebookSerializer(NOTEBOOK_TYPE, {
serializeNotebook(notebook, token) {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/services/PythonExtension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as py from "@vscode/python-extension";
import { Effect, FiberSet } from "effect";
import { Effect, Runtime } from "effect";

/**
* Provides access to the VS Code Python extension API for
Expand All @@ -10,7 +10,7 @@ export class PythonExtension extends Effect.Service<PythonExtension>()(
{
scoped: Effect.gen(function* () {
const api = yield* Effect.promise(() => py.PythonExtension.api());
const runPromise = yield* FiberSet.makeRuntimePromise();
const runPromise = Runtime.runPromise(yield* Effect.runtime());
return {
getKnownEnvironments() {
return api.environments.known;
Expand Down
23 changes: 10 additions & 13 deletions extension/src/services/VsCode.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Data, Effect, Either, Fiber, FiberSet, Option, Stream } from "effect";
import { Data, Effect, Either, Fiber, Option, Runtime, Stream } from "effect";
// VsCode.ts is the centralized service that wraps the VS Code API.
//
// All other modules should use type-only imports and access the API through this service.
//
// biome-ignore lint: See above
import * as vscode from "vscode";
import type { AssertionError } from "../assert.ts";
import type { MarimoCommandKey } from "../constants.ts";
import { tokenFromSignal } from "../utils/tokenFromSignal.ts";

Expand All @@ -16,7 +15,7 @@ export class VsCodeError extends Data.TaggedError("VsCodeError")<{
export class Window extends Effect.Service<Window>()("Window", {
scoped: Effect.gen(function* () {
const api = vscode.window;
const runPromise = yield* FiberSet.makeRuntimePromise();
const runPromise = Runtime.runPromise(yield* Effect.runtime());

return {
showInputBox(
Expand Down Expand Up @@ -142,7 +141,7 @@ export class Window extends Effect.Service<Window>()("Window", {
message: string;
increment?: number;
}>,
) => Effect.Effect<void, never, never>,
) => Effect.Effect<void>,
) {
return Effect.promise((signal) =>
api.withProgress(options, (progress, token) =>
Expand All @@ -163,7 +162,7 @@ export class Window extends Effect.Service<Window>()("Window", {
Effect.sync(() => signal.removeEventListener("abort", kill)),
);

yield* fiber.await;
yield* Fiber.join(fiber);
}).pipe(Effect.scoped, runPromise),
),
);
Expand All @@ -184,19 +183,17 @@ export class Commands extends Effect.Service<Commands>()("Commands", {
scoped: Effect.gen(function* () {
const win = yield* Window;
const api = vscode.commands;
const runPromise = yield* FiberSet.makeRuntimePromise();
const runPromise = Runtime.runPromise(yield* Effect.runtime());

return {
executeCommand(command: ExecutableCommand, ...args: unknown[]) {
return Effect.promise(() => api.executeCommand(command, ...args));
},
registerCommand(
command: MarimoCommandKey,
effect: Effect.Effect<void, AssertionError | VsCodeError, never>,
) {
registerCommand(command: MarimoCommandKey, effect: Effect.Effect<void>) {
return Effect.acquireRelease(
Effect.sync(() =>
api.registerCommand(command, () =>
runPromise<never, void>(
runPromise(
effect.pipe(
Effect.catchAllCause((cause) =>
Effect.gen(function* () {
Expand Down Expand Up @@ -351,6 +348,7 @@ export class AuthError extends Data.TaggedError("AuthError")<{

export class Auth extends Effect.Service<Auth>()("Auth", {
effect: Effect.gen(function* () {
const api = vscode.authentication;
return {
getSession(
providerId: "github" | "microsoft", // could be custom but these are default
Expand All @@ -359,8 +357,7 @@ export class Auth extends Effect.Service<Auth>()("Auth", {
) {
return Effect.map(
Effect.tryPromise({
try: () =>
vscode.authentication.getSession(providerId, scopes, options),
try: () => api.getSession(providerId, scopes, options),
catch: (cause) => new AuthError({ cause }),
}),
Option.fromNullable,
Expand Down