Skip to content

Commit 61e2f82

Browse files
Add devtools page (#1238)
1 parent ab1aa8c commit 61e2f82

File tree

9 files changed

+269
-8
lines changed

9 files changed

+269
-8
lines changed

content/src/content/docs/docs/getting-started/building-pipelines.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Building Pipelines
33
description: Learn to create modular, readable pipelines for composing and sequencing operations in Effect, enabling clear and efficient data transformations.
44
sidebar:
5-
order: 9
5+
order: 10
66
---
77

88
import { Aside } from "@astrojs/starlight/components"

content/src/content/docs/docs/getting-started/control-flow.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Control Flow Operators
33
description: Learn to control execution flow in Effect programs using advanced constructs for conditional branching, iteration, and combining effects seamlessly.
44
sidebar:
5-
order: 10
5+
order: 11
66
---
77

88
Even though JavaScript provides built-in control flow structures, Effect offers additional control flow functions that are useful in Effect applications. In this section, we will introduce different ways to control the flow of execution.

content/src/content/docs/docs/getting-started/create-effect-app.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Create Effect App
33
description: Quickly set up a new Effect application with a customizable template or example, streamlining your development start.
44
sidebar:
5-
order: 3
5+
order: 4
66
---
77

88
import { Tabs, TabItem } from "@astrojs/starlight/components"

content/src/content/docs/docs/getting-started/creating-effects.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Creating Effects
33
description: Learn to create and manage effects for structured handling of success, failure, and side effects in synchronous and asynchronous workflows.
44
sidebar:
5-
order: 6
5+
order: 7
66
---
77

88
import { Aside } from "@astrojs/starlight/components"
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
---
2+
title: Devtools
3+
description: Enhance your Effect development experience with the Effect Language Service and official VS Code/Cursor extension for advanced diagnostics, refactors, and intelligent code completion.
4+
sidebar:
5+
order: 3
6+
---
7+
8+
import { Aside, Steps, Tabs, TabItem } from "@astrojs/starlight/components"
9+
10+
Effect provides powerful development tools to enhance your coding experience and help you write safer, more maintainable code. These tools integrate directly into your editor, providing real-time feedback, intelligent refactors, and helpful diagnostics.
11+
12+
## Effect LSP
13+
14+
The Effect LSP extends your editor with Effect-specific features. It analyzes your Effect code and provides intelligent assistance through diagnostics, quick info, completions, and automated refactors.
15+
16+
It works in editors that supports the standard TypeScript LSP, such as Code, Cursor, Zed, NVim, etc.
17+
18+
### Installation
19+
20+
To install the Effect Language Service in your project:
21+
22+
<Steps>
23+
24+
1. Install the package as a development dependency:
25+
26+
For monorepos, we suggest to install the language service at the root level. For single-package projects, install it in the package directory.
27+
28+
<Tabs syncKey="package-manager">
29+
30+
<TabItem label="npm" icon="seti:npm">
31+
32+
```sh showLineNumbers=false
33+
npm install @effect/language-service --save-dev
34+
```
35+
36+
</TabItem>
37+
38+
<TabItem label="pnpm" icon="pnpm">
39+
40+
```sh showLineNumbers=false
41+
pnpm add -D @effect/language-service
42+
```
43+
44+
</TabItem>
45+
46+
<TabItem label="Yarn" icon="seti:yarn">
47+
48+
```sh showLineNumbers=false
49+
yarn add --dev @effect/language-service
50+
```
51+
52+
</TabItem>
53+
54+
<TabItem label="Bun" icon="bun">
55+
56+
```sh showLineNumbers=false
57+
bun add --dev @effect/language-service
58+
```
59+
60+
</TabItem>
61+
62+
</Tabs>
63+
64+
2. Add the plugin to your `tsconfig.json`:
65+
66+
```json title="tsconfig.json"
67+
{
68+
"compilerOptions": {
69+
"plugins": [
70+
{
71+
"name": "@effect/language-service"
72+
}
73+
]
74+
}
75+
}
76+
```
77+
78+
3. Ensure your editor uses the workspace TypeScript version:
79+
80+
This step is critical for the language service to function properly. The plugin must run on the TypeScript version installed in your project, not the one bundled with your editor.
81+
82+
<Aside type="tip">
83+
In VS Code or Cursor, you can select the workspace TypeScript version by opening a TypeScript file, clicking on the TypeScript version number in the status bar, and selecting "Use Workspace Version".
84+
</Aside>
85+
86+
4. You're ready to play!
87+
88+
Writing the following code in a file.ts inside your project, should result in an error diagnostic appearing, saying that Effect's must be yielded or assigned to a variable:
89+
90+
```ts
91+
import { Effect } from "effect"
92+
93+
Effect.log("Hello world!")
94+
// ^- should be run or assigned to a variable!
95+
```
96+
97+
</Steps>
98+
99+
100+
### Features
101+
102+
The Effect Language Service provides a comprehensive set of features to enhance your development workflow:
103+
104+
#### Intelligent Quick Info
105+
106+
Hover over Effect values to see extended type information and detailed insights:
107+
108+
- **Effect Types**: See comprehensive type information for Effect values
109+
- **Generator Parameters**: When hovering over `yield*` in `Effect.gen`, view detailed information about the yielded value
110+
- **Layer Composition**: Visualize layer dependencies with interactive graphs showing how layers compose together
111+
- **Service Dependencies**: Understand service requirements and their relationships at a glance
112+
113+
#### Real-time Diagnostics
114+
115+
Catch common mistakes and potential issues as you write code:
116+
117+
- **Floating Effects**: Detect Effect values that aren't assigned or yielded, preventing silent bugs
118+
- **Layer Issues**: Catch layer requirement leaks and scope violations before runtime
119+
- **Unnecessary Code**: Identify redundant `Effect.gen` or `pipe()` calls
120+
- **Error Handling**: Detect misuse of catch functions on Effects that cannot fail
121+
- **Version Conflicts**: Detect when multiple Effect versions are present in your project
122+
123+
#### Smart Completions
124+
125+
Speed up your coding with context-aware suggestions:
126+
127+
- **Generator Boilerplate**: Quickly scaffold `Effect.gen` functions
128+
- **Scaffolds**: For `Effect.Service`, `Data.TaggedError` and friends.
129+
- **Self Parameters**: Auto-complete for `Self` parameters in service declarations
130+
131+
#### Powerful Refactors
132+
133+
Transform your code with intelligent automated refactors:
134+
135+
- **Async to Effect**: Convert async functions to Effect using `gen` or `fn` syntax
136+
- **Error Generation**: Generate tagged errors from promise-based code
137+
- **Service Accessors**: Automatically implement service accessor functions
138+
- **Pipe Conversion**: Transform function calls to pipe syntax
139+
- **Pipe Styles**: Toggle between different pipe style formats
140+
- **Layer Magic**: Automatically compose layers with correct dependencies
141+
142+
### Configuration
143+
144+
The Effect LSP provides also lots of configuration options such as changing severity or disabling diagnostic messages.
145+
146+
To see the full list of options and features, please visit the [README from the LSP repository](https://github.com/Effect-TS/language-service).
147+
148+
### Build-Time Diagnostics
149+
150+
While LSPs only activate during editing sessions, you may want to catch diagnostics during your build process.
151+
152+
Usually that's done through linting rules, but since almost all of the Effect diagnostics relies on types, that would mean enabling type-aware linting, which means performing type checking again on the project files.
153+
154+
To solve this, the Effect Language Service allows you to patch your local TypeScript installation, so diagnostics are emitted while performing type checking.
155+
156+
To enable it run the following command to modify your local TypeScript installation:
157+
158+
```sh showLineNumbers=false
159+
effect-language-service patch
160+
```
161+
162+
To make this automatic for all developers, add it to your `package.json`:
163+
164+
```json title="package.json"
165+
{
166+
"scripts": {
167+
"prepare": "effect-language-service patch"
168+
}
169+
}
170+
```
171+
172+
This ensures the language service runs during compilation with the standard `tsc` command.
173+
174+
175+
## VS Code / Cursor Extension
176+
177+
<Aside type="caution">
178+
The editor extension does not include the Effect LSP! Installation of that should be performed per-project, this allows fine grained control on when to load it, for which projects and with a version pinned with your repository lockfile.
179+
</Aside>
180+
181+
The editor extension provides utilities in helping you debug your Effect applications.
182+
183+
At the moment only Code and Code forks like Cursor are supported.
184+
185+
### Installation
186+
187+
The extension can be installed by searching directly in your editor extension page or from the [Code Marketplace](https://marketplace.visualstudio.com/items?itemName=effectful-tech.effect-vscode) or the [Open VSX Marketplace](https://open-vsx.org/extension/effectful-tech/effect-vscode).
188+
189+
### Debugger Features
190+
191+
With the Effect Extension, you'll find couple of new sections inside the Debug section of your editor that, once you pause execution, will .
192+
193+
- **Context**: Allows you to inspect the context of the currently paused Effect Fiber.
194+
- **Span Stack**: Shows you the stack of telemetry spans that lead you into the execution of the currently paused Effect.
195+
- **Fibers**: List all the Effect Fibers running in your application, allows you to inspect informations such as interrupt-ability and allows to request interruption of them.
196+
- **Breakpoints**: Allows to enable "pause on defect"; letting your debugger pause when a Effect Fiber fails with a defect.
197+
198+
### Built-in Tracer and Metrics
199+
200+
The built-in tracer and metrics view allows to quickly see Effect Spans and Metrics of your app without spinning up an entire telemetry service.
201+
202+
To enable it, you need to install the following dependency in your project:
203+
204+
<Tabs syncKey="package-manager">
205+
206+
<TabItem label="npm" icon="seti:npm">
207+
208+
```sh showLineNumbers=false
209+
npm install @effect/experimental
210+
```
211+
212+
</TabItem>
213+
214+
<TabItem label="pnpm" icon="pnpm">
215+
216+
```sh showLineNumbers=false
217+
pnpm install @effect/experimental
218+
```
219+
220+
</TabItem>
221+
222+
<TabItem label="Yarn" icon="seti:yarn">
223+
224+
```sh showLineNumbers=false
225+
yarn add @effect/experimental
226+
```
227+
228+
</TabItem>
229+
230+
<TabItem label="Bun" icon="bun">
231+
232+
```sh showLineNumbers=false
233+
bun add @effect/experimental
234+
```
235+
236+
</TabItem>
237+
238+
</Tabs>
239+
240+
You can then import and use the DevTools module in your Effect app:
241+
242+
```ts
243+
import { DevTools } from "@effect/experimental"
244+
import { NodeRuntime, NodeSocket } from "@effect/platform-node"
245+
import { Effect, Layer } from "effect"
246+
247+
const program = Effect.log("Hello!").pipe(
248+
Effect.delay(2000),
249+
Effect.withSpan("Hi", { attributes: { foo: "bar" } }),
250+
Effect.forever,
251+
)
252+
const DevToolsLive = DevTools.layer()
253+
254+
program.pipe(Effect.provide(DevToolsLive), NodeRuntime.runMain)
255+
```
256+
257+
If you are using `@effect/opentelemetry` in your project, then it is important that you provide the DevTools layer before your tracing layers, so the tracer is patched correctly.
258+
259+
Now start both your editor and your app. Inside the Effect panel, in the clients section you'll see a newly connected client.
260+
261+
In the bottom of your editor, near your terminal, a new tab "Effect Tracer" will appear as well, showing visually your spans as they happen in real time.

content/src/content/docs/docs/getting-started/importing-effect.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Importing Effect
33
description: Get started with Effect by installing the package and importing essential modules and functions for building type-safe, modular applications.
44
sidebar:
5-
order: 4
5+
order: 5
66
---
77

88
import { Aside, Tabs, TabItem } from "@astrojs/starlight/components"

content/src/content/docs/docs/getting-started/running-effects.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Running Effects
33
description: Learn how to execute effects in Effect with various functions for synchronous and asynchronous execution, including handling results and managing error outcomes.
44
sidebar:
5-
order: 7
5+
order: 8
66
---
77

88
import { Aside } from "@astrojs/starlight/components"

content/src/content/docs/docs/getting-started/the-effect-type.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: The Effect Type
33
description: Understand the Effect type in the Effect ecosystem, which models immutable, lazy workflows with type-safe success, error, and requirement handling for effectful computations.
44
sidebar:
5-
order: 5
5+
order: 6
66
---
77

88
import { Aside } from "@astrojs/starlight/components"

content/src/content/docs/docs/getting-started/using-generators.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Using Generators
33
description: Learn how to use generators in Effect for writing effectful code, enhancing control flow, handling errors, and simplifying asynchronous operations with a syntax similar to async/await.
44
sidebar:
5-
order: 8
5+
order: 9
66
---
77

88
import {

0 commit comments

Comments
 (0)