prefer-effect-ts

Replace Promise-based async flows with type-safe Effect operations in the Apex language server.

11|2|Updated Apr 4, 2025
One-click install
npx skills add https://github.com/forcedotcom/apex-language-support --skill prefer-effect-ts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prefer-effect-ts
Source: https://github.com/forcedotcom/apex-language-support/tree/main/.cursor/skills/prefer-effect-ts
Command: npx skills add https://github.com/forcedotcom/apex-language-support --skill prefer-effect-ts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Effect-TS replaces scattered Promise-based code, try/catch blocks, and manual dependency handling with a unified, type-safe approach for asynchronous operations and error management in the Apex language server codebase. This reduces runtime errors, improves observability through integrated logging, and makes service dependencies explicit and testable.

Core Features & Use Cases

  • Type-safe async flows: Replace Promise and async/await patterns with composable Effect operations for predictable sequencing and failure handling.
  • Structured error handling: Use Effect.fail, catchTag, and catchAll to surface and handle typed errors rather than relying on ad-hoc exceptions.
  • Dependency management: Use Context.Tag and Layer to declare and provide dependencies for services and validators for easier testing and composition.
  • Integrated logging: Route Effect.log* calls through EffectLspLoggerLive to emit workspace/logMessage notifications to the LSP output channel.
  • Testability: Provide test logger layers such as EffectTestLoggerLive and use deterministic Effects in unit and integration tests.

Quick Start

Implement a new validator or service using Effect.gen, provide the EffectLspLoggerLive layer when running in production (or EffectTestLoggerLive in tests), and execute the program with Effect.runPromise.

Frequently Asked Questions about prefer-effect-ts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace async await and try/catch with type-safe error handling?

Type-safe error handling replaces try/catch and async/await by using Effect.gen for sequencing and Effect.fail to surface typed errors. You handle these errors explicitly using catchTag or catchAll for predictable failure management.

How do I inject dependencies in Effect-TS for testable services?

Dependency injection in Effect-TS uses Context.Tag to declare service dependencies and Layer to provide implementations. You supply test layers during unit testing and production layers like EffectLspLoggerLive for actual execution.

Does Effect logging work with the Apex language server output channel?

Effect logging works with the Apex language server by routing Effect.log* calls through the EffectLspLoggerLive layer. This layer emits workspace/logMessage notifications directly to the LSP output channel for integrated observability.

What is the best way to execute Effect async operations across development and test modes?

Executing Effect async operations across modes requires providing the appropriate layer before running the program. Provide EffectLspLoggerLive for production or EffectTestLoggerLive for tests, then execute the composed Effect using Effect.runPromise.

Why use Effect for asynchronous control flow instead of standard Promises?

Using Effect for asynchronous control flow replaces scattered Promises with a unified, composable approach. It makes service dependencies explicit, improves runtime observability through integrated logging, and reduces runtime errors via structured error handling.