Skip to content

Commit fd4a8da

Browse files
Update Effect v4 beta Context API usage (#726)
1 parent 14d5798 commit fd4a8da

176 files changed

Lines changed: 1705 additions & 634 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/old-pugs-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/language-service": patch
3+
---
4+
5+
Update the Effect v4 beta examples and type parsing to match the renamed Context APIs in the latest 4.0.0-beta releases.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Some diagnostics are off by default or have a default severity of suggestion, bu
124124
<tr><td><code>redundantSchemaTagIdentifier</code></td><td>💡</td><td>🔧</td><td>Suggests removing redundant identifier argument when it equals the tag value in Schema.TaggedClass/TaggedError/TaggedRequest</td><td>✓</td><td>✓</td></tr>
125125
<tr><td><code>schemaStructWithTag</code></td><td>💡</td><td>🔧</td><td>Suggests using Schema.TaggedStruct instead of Schema.Struct with _tag field</td><td>✓</td><td>✓</td></tr>
126126
<tr><td><code>schemaUnionOfLiterals</code></td><td>➖</td><td>🔧</td><td>Simplifies Schema.Union of multiple Schema.Literal calls into single Schema.Literal</td><td>✓</td><td></td></tr>
127-
<tr><td><code>serviceNotAsClass</code></td><td>➖</td><td>🔧</td><td>Warns when ServiceMap.Service is used as a variable instead of a class declaration</td><td></td><td>✓</td></tr>
127+
<tr><td><code>serviceNotAsClass</code></td><td>➖</td><td>🔧</td><td>Warns when Context.Service is used as a variable instead of a class declaration</td><td></td><td>✓</td></tr>
128128
<tr><td><code>strictBooleanExpressions</code></td><td>➖</td><td></td><td>Enforces boolean types in conditional expressions for type safety</td><td>✓</td><td>✓</td></tr>
129129
<tr><td><code>unnecessaryArrowBlock</code></td><td>➖</td><td>🔧</td><td>Suggests using a concise arrow body when the block only returns an expression</td><td>✓</td><td>✓</td></tr>
130130
<tr><td><code>unnecessaryEffectGen</code></td><td>💡</td><td>🔧</td><td>Suggests removing Effect.gen when it contains only a single return statement</td><td>✓</td><td>✓</td></tr>

packages/harness-effect-v4/__snapshots__/completions.test.ts.snap

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -335,27 +335,27 @@ exports[`Completion genFunctionStar > genFunctionStar.ts at 4:24 1`] = `
335335

336336
exports[`Completion genFunctionStar > genFunctionStar_imports.ts at 2:16 1`] = `[]`;
337337

338-
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses.ts at 4:43 1`] = `
338+
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses.ts at 4:40 1`] = `
339339
[
340340
{
341-
"insertText": "ServiceMap.Service<MyService, {\${0}}>()("@effect/harness-effect-v4/MyService"){}",
341+
"insertText": "Context.Service<MyService, {\${0}}>()("@effect/harness-effect-v4/MyService"){}",
342342
"isSnippet": true,
343343
"kind": "const",
344344
"name": "Service<MyService, {}>",
345345
"replacementSpan": {
346-
"length": 11,
347-
"start": 153,
346+
"length": 8,
347+
"start": 147,
348348
},
349349
"sortText": "11",
350350
},
351351
{
352-
"insertText": "ServiceMap.Service<MyService>()("@effect/harness-effect-v4/MyService", { make: \${0} }){}",
352+
"insertText": "Context.Service<MyService>()("@effect/harness-effect-v4/MyService", { make: \${0} }){}",
353353
"isSnippet": true,
354354
"kind": "const",
355355
"name": "Service<MyService>({ make })",
356356
"replacementSpan": {
357-
"length": 11,
358-
"start": 153,
357+
"length": 8,
358+
"start": 147,
359359
},
360360
"sortText": "11",
361361
},
@@ -371,7 +371,7 @@ exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_directImpo
371371
"name": "Service<MyService, {}>",
372372
"replacementSpan": {
373373
"length": 7,
374-
"start": 149,
374+
"start": 146,
375375
},
376376
"sortText": "11",
377377
},
@@ -382,61 +382,61 @@ exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_directImpo
382382
"name": "Service<MyService>({ make })",
383383
"replacementSpan": {
384384
"length": 7,
385-
"start": 149,
385+
"start": 146,
386386
},
387387
"sortText": "11",
388388
},
389389
]
390390
`;
391391

392-
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_identifierKey.ts at 5:43 1`] = `
392+
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_identifierKey.ts at 5:40 1`] = `
393393
[
394394
{
395-
"insertText": "ServiceMap.Service<MyService, {\${0}}>()("@effect/harness-effect-v4/MyService"){}",
395+
"insertText": "Context.Service<MyService, {\${0}}>()("@effect/harness-effect-v4/MyService"){}",
396396
"isSnippet": true,
397397
"kind": "const",
398398
"name": "Service<MyService, {}>",
399399
"replacementSpan": {
400-
"length": 11,
401-
"start": 249,
400+
"length": 8,
401+
"start": 243,
402402
},
403403
"sortText": "11",
404404
},
405405
{
406-
"insertText": "ServiceMap.Service<MyService>()("@effect/harness-effect-v4/MyService", { make: \${0} }){}",
406+
"insertText": "Context.Service<MyService>()("@effect/harness-effect-v4/MyService", { make: \${0} }){}",
407407
"isSnippet": true,
408408
"kind": "const",
409409
"name": "Service<MyService>({ make })",
410410
"replacementSpan": {
411-
"length": 11,
412-
"start": 249,
411+
"length": 8,
412+
"start": 243,
413413
},
414414
"sortText": "11",
415415
},
416416
]
417417
`;
418418

419-
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_middle.ts at 4:31 1`] = `
419+
exports[`Completion serviceMapSelfInClasses > serviceMapSelfInClasses_middle.ts at 4:28 1`] = `
420420
[
421421
{
422-
"insertText": "ServiceMap.Service<Foo, {\${0}}>()("@effect/harness-effect-v4/Foo"){}",
422+
"insertText": "Context.Service<Foo, {\${0}}>()("@effect/harness-effect-v4/Foo"){}",
423423
"isSnippet": true,
424424
"kind": "const",
425425
"name": "Service<Foo, {}>",
426426
"replacementSpan": {
427-
"length": 12,
428-
"start": 144,
427+
"length": 9,
428+
"start": 141,
429429
},
430430
"sortText": "11",
431431
},
432432
{
433-
"insertText": "ServiceMap.Service<Foo>()("@effect/harness-effect-v4/Foo", { make: \${0} }){}",
433+
"insertText": "Context.Service<Foo>()("@effect/harness-effect-v4/Foo", { make: \${0} }){}",
434434
"isSnippet": true,
435435
"kind": "const",
436436
"name": "Service<Foo>({ make })",
437437
"replacementSpan": {
438-
"length": 12,
439-
"start": 144,
438+
"length": 9,
439+
"start": 141,
440440
},
441441
"sortText": "11",
442442
},
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
anyUnknownInErrorContext_skipNextLine from 1140 to 1152
2-
anyUnknownInErrorContext_skipFile from 1140 to 1152
3-
anyUnknownInErrorContext_skipNextLine from 1086 to 1106
4-
anyUnknownInErrorContext_skipFile from 1086 to 1106
5-
anyUnknownInErrorContext_skipNextLine from 1059 to 1071
6-
anyUnknownInErrorContext_skipFile from 1059 to 1071
7-
anyUnknownInErrorContext_skipNextLine from 1024 to 1036
8-
anyUnknownInErrorContext_skipFile from 1024 to 1036
9-
anyUnknownInErrorContext_skipNextLine from 991 to 1017
10-
anyUnknownInErrorContext_skipFile from 991 to 1017
11-
anyUnknownInErrorContext_skipNextLine from 976 to 988
12-
anyUnknownInErrorContext_skipFile from 976 to 988
13-
anyUnknownInErrorContext_skipNextLine from 596 to 616
14-
anyUnknownInErrorContext_skipFile from 596 to 616
15-
anyUnknownInErrorContext_skipNextLine from 553 to 579
16-
anyUnknownInErrorContext_skipFile from 553 to 579
17-
anyUnknownInErrorContext_skipNextLine from 499 to 516
18-
anyUnknownInErrorContext_skipFile from 499 to 516
19-
anyUnknownInErrorContext_skipNextLine from 457 to 481
20-
anyUnknownInErrorContext_skipFile from 457 to 481
21-
anyUnknownInErrorContext_skipNextLine from 395 to 413
22-
anyUnknownInErrorContext_skipFile from 395 to 413
23-
anyUnknownInErrorContext_skipNextLine from 357 to 377
24-
anyUnknownInErrorContext_skipFile from 357 to 377
25-
anyUnknownInErrorContext_skipNextLine from 299 to 313
26-
anyUnknownInErrorContext_skipFile from 299 to 313
27-
anyUnknownInErrorContext_skipNextLine from 259 to 281
28-
anyUnknownInErrorContext_skipFile from 259 to 281
29-
anyUnknownInErrorContext_skipNextLine from 208 to 222
30-
anyUnknownInErrorContext_skipFile from 208 to 222
31-
anyUnknownInErrorContext_skipNextLine from 164 to 190
32-
anyUnknownInErrorContext_skipFile from 164 to 190
1+
anyUnknownInErrorContext_skipNextLine from 1136 to 1148
2+
anyUnknownInErrorContext_skipFile from 1136 to 1148
3+
anyUnknownInErrorContext_skipNextLine from 1082 to 1102
4+
anyUnknownInErrorContext_skipFile from 1082 to 1102
5+
anyUnknownInErrorContext_skipNextLine from 1055 to 1067
6+
anyUnknownInErrorContext_skipFile from 1055 to 1067
7+
anyUnknownInErrorContext_skipNextLine from 1020 to 1032
8+
anyUnknownInErrorContext_skipFile from 1020 to 1032
9+
anyUnknownInErrorContext_skipNextLine from 988 to 1013
10+
anyUnknownInErrorContext_skipFile from 988 to 1013
11+
anyUnknownInErrorContext_skipNextLine from 973 to 985
12+
anyUnknownInErrorContext_skipFile from 973 to 985
13+
anyUnknownInErrorContext_skipNextLine from 593 to 613
14+
anyUnknownInErrorContext_skipFile from 593 to 613
15+
anyUnknownInErrorContext_skipNextLine from 551 to 576
16+
anyUnknownInErrorContext_skipFile from 551 to 576
17+
anyUnknownInErrorContext_skipNextLine from 497 to 514
18+
anyUnknownInErrorContext_skipFile from 497 to 514
19+
anyUnknownInErrorContext_skipNextLine from 455 to 479
20+
anyUnknownInErrorContext_skipFile from 455 to 479
21+
anyUnknownInErrorContext_skipNextLine from 393 to 411
22+
anyUnknownInErrorContext_skipFile from 393 to 411
23+
anyUnknownInErrorContext_skipNextLine from 355 to 375
24+
anyUnknownInErrorContext_skipFile from 355 to 375
25+
anyUnknownInErrorContext_skipNextLine from 297 to 311
26+
anyUnknownInErrorContext_skipFile from 297 to 311
27+
anyUnknownInErrorContext_skipNextLine from 258 to 279
28+
anyUnknownInErrorContext_skipFile from 258 to 279
29+
anyUnknownInErrorContext_skipNextLine from 207 to 221
30+
anyUnknownInErrorContext_skipFile from 207 to 221
31+
anyUnknownInErrorContext_skipNextLine from 164 to 189
32+
anyUnknownInErrorContext_skipFile from 164 to 189
3333
anyUnknownInErrorContext_skipNextLine from 109 to 127
3434
anyUnknownInErrorContext_skipFile from 109 to 127

packages/harness-effect-v4/__snapshots__/diagnostics/anyUnknownInErrorContext.ts.output

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ withUnknownContext
22
4:13 - 4:31 | 0 | This has unknown in the requirements channel which is not recommended.
33
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
44

5-
Effect.services<unknown>()
6-
5:9 - 5:35 | 0 | This has unknown in the requirements channel which is not recommended.
5+
Effect.context<unknown>()
6+
5:9 - 5:34 | 0 | This has unknown in the requirements channel which is not recommended.
77
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
88

99
withAnyContext
1010
8:13 - 8:27 | 0 | This has any in the requirements channel which is not recommended.
1111
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
1212

13-
Effect.services<any>()
14-
9:9 - 9:31 | 0 | This has any in the requirements channel which is not recommended.
13+
Effect.context<any>()
14+
9:9 - 9:30 | 0 | This has any in the requirements channel which is not recommended.
1515
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
1616

1717
withAnyFailure
@@ -35,8 +35,8 @@ hasBothAnyUnknown
3535
Only service identifiers should appear in the requirements channel.
3636
Having an unknown or any error type is not useful. Consider instead using specific error types baked by Data.TaggedError for example. effect(anyUnknownInErrorContext)
3737

38-
Effect.services<unknown>()
39-
21:9 - 21:35 | 0 | This has unknown in the requirements channel which is not recommended.
38+
Effect.context<unknown>()
39+
21:9 - 21:34 | 0 | This has unknown in the requirements channel which is not recommended.
4040
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
4141

4242
Effect.fail<any>(42)
@@ -47,8 +47,8 @@ effectUnkown
4747
37:6 - 37:18 | 0 | This has unknown in the requirements channel which is not recommended.
4848
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
4949

50-
Effect.services<unknown>()
51-
37:21 - 37:47 | 0 | This has unknown in the requirements channel which is not recommended.
50+
Effect.context<unknown>()
51+
37:21 - 37:46 | 0 | This has unknown in the requirements channel which is not recommended.
5252
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
5353

5454
layerUnknown
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
anyUnknownInErrorContext_skipNextLine from 218 to 242
2-
anyUnknownInErrorContext_skipFile from 218 to 242
3-
anyUnknownInErrorContext_skipNextLine from 175 to 201
4-
anyUnknownInErrorContext_skipFile from 175 to 201
1+
anyUnknownInErrorContext_skipNextLine from 217 to 241
2+
anyUnknownInErrorContext_skipFile from 217 to 241
3+
anyUnknownInErrorContext_skipNextLine from 175 to 200
4+
anyUnknownInErrorContext_skipFile from 175 to 200
55
anyUnknownInErrorContext_skipNextLine from 131 to 138
66
anyUnknownInErrorContext_skipFile from 131 to 138

packages/harness-effect-v4/__snapshots__/diagnostics/anyUnknownInErrorContext_preview.ts.output

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ preview
33
Only service identifiers should appear in the requirements channel.
44
Having an unknown or any error type is not useful. Consider instead using specific error types baked by Data.TaggedError for example. effect(anyUnknownInErrorContext)
55

6-
Effect.services<unknown>()
7-
6:9 - 6:35 | 0 | This has unknown in the requirements channel which is not recommended.
6+
Effect.context<unknown>()
7+
6:9 - 6:34 | 0 | This has unknown in the requirements channel which is not recommended.
88
Only service identifiers should appear in the requirements channel. effect(anyUnknownInErrorContext)
99

1010
Effect.fail<any>("boom")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// code fix classSelfMismatch_fix output for range 308 - 319
2+
import { Context, Effect } from "effect"
3+
4+
export class CorrectName extends Context.Service<CorrectName, {
5+
writeCache: () => Effect.Effect<void, never, FileSystem | Cache>
6+
readCache: Effect.Effect<void, never, FileSystem | Cache>
7+
}>()("CorrectName") {}
8+
9+
export class WrongName extends Context.Service<WrongName, {
10+
writeCache: () => Effect.Effect<void, never, FileSystem | Cache>
11+
readCache: Effect.Effect<void, never, FileSystem | Cache>
12+
}>()("WrongName") {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
classSelfMismatch_fix from 317 to 328
2-
classSelfMismatch_skipNextLine from 317 to 328
3-
classSelfMismatch_skipFile from 317 to 328
1+
classSelfMismatch_fix from 308 to 319
2+
classSelfMismatch_skipNextLine from 308 to 319
3+
classSelfMismatch_skipFile from 308 to 319
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CorrectName
2-
8:50 - 8:61 | 1 | The `Self` type parameter for this class should be `WrongName`. effect(classSelfMismatch)
2+
8:47 - 8:58 | 1 | The `Self` type parameter for this class should be `WrongName`. effect(classSelfMismatch)

0 commit comments

Comments
 (0)