History

Format Effect refactors

Cursor Agent committed 4 months ago

Commit faf9d871 parent 6cc87a32 files · +39 −24Browse files

Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.ts (1 of 2 files). Show all

Unified · Split

apps/server/src/workspace/WorkspaceFileSystem.ts+35−22
@@ -131,20 +131,22 @@ export const make = Effect.gen(function* () { · 130 unmodified lines
131 const workspacePaths = yield* WorkspacePaths.WorkspacePaths;131 const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
132 const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;132 const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
133 133
134 const operationError = (134 const operationError =
135 input: ProjectReadFileInput | ProjectWriteFileInput,135 (
136 resolvedPath: string,136 input: ProjectReadFileInput | ProjectWriteFileInput,
137 operationPath: string,137 resolvedPath: string,
138 operation: WorkspaceFileSystemOperationError["operation"],138 operationPath: string,
139 ) => (cause: unknown) =>139 operation: WorkspaceFileSystemOperationError["operation"],
140 new WorkspaceFileSystemOperationError({140 ) =>
141 workspaceRoot: input.cwd,141 (cause: unknown) =>
142 relativePath: input.relativePath,142 new WorkspaceFileSystemOperationError({
143 resolvedPath,143 workspaceRoot: input.cwd,
144 operationPath,144 relativePath: input.relativePath,
145 operation,145 resolvedPath,
146 cause,146 operationPath,
147 });147 operation,
148 cause,
149 });
148 150
149 const readFile: WorkspaceFileSystem["Service"]["readFile"] = Effect.fn(151 const readFile: WorkspaceFileSystem["Service"]["readFile"] = Effect.fn(
150 "WorkspaceFileSystem.readFile",152 "WorkspaceFileSystem.readFile",
@@ -203,10 +205,12 @@ export const make = Effect.gen(function* () { · 52 unmodified lines
203 const fileBytes =205 const fileBytes =
204 bytesToRead === 0206 bytesToRead === 0
205 ? new Uint8Array()207 ? new Uint8Array()
206 : yield* file.readAlloc(bytesToRead).pipe(208 : yield* file
207 Effect.map(Option.getOrElse(() => new Uint8Array())),209 .readAlloc(bytesToRead)
208 Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")),210 .pipe(
209 );211 Effect.map(Option.getOrElse(() => new Uint8Array())),
212 Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")),
213 );
210 if (fileBytes.includes(0)) {214 if (fileBytes.includes(0)) {
211 return yield* new WorkspaceBinaryFileError({215 return yield* new WorkspaceBinaryFileError({
212 workspaceRoot: input.cwd,216 workspaceRoot: input.cwd,
@@ -237,12 +241,21 @@ export const make = Effect.gen(function* () { · 24 unmodified lines
237 .makeDirectory(path.dirname(target.absolutePath), { recursive: true })241 .makeDirectory(path.dirname(target.absolutePath), { recursive: true })
238 .pipe(242 .pipe(
239 Effect.mapError(243 Effect.mapError(
240 operationError(input, target.absolutePath, path.dirname(target.absolutePath), "make-directory"),244 operationError(
245 input,
246 target.absolutePath,
247 path.dirname(target.absolutePath),
248 "make-directory",
249 ),
250 ),
251 );
252 yield* fileSystem
253 .writeFileString(target.absolutePath, input.contents)
254 .pipe(
255 Effect.mapError(
256 operationError(input, target.absolutePath, target.absolutePath, "write-file"),
241 ),257 ),
242 );258 );
243 yield* fileSystem.writeFileString(target.absolutePath, input.contents).pipe(
244 Effect.mapError(operationError(input, target.absolutePath, target.absolutePath, "write-file")),
245 );
246 yield* workspaceEntries.refresh(input.cwd);259 yield* workspaceEntries.refresh(input.cwd);
247 return { relativePath: target.relativePath };260 return { relativePath: target.relativePath };
248 });261 });