@effect/language-service 0.15.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,12 +26,39 @@ This package implements a TypeScript language service plugin that allows additio
26
26
 
27
27
  And you're done! You'll now be able to use a set of refactor and diagnostics that targets Effect!
28
28
 
29
- ## Enable diagnostics at compile time
29
+ ## Provided functionalities
30
30
 
31
- TypeScript LSP are loaded only while editing your files. That means that if you run `tsc` in your project, the plugin won't be loaded and you'll miss out on the Effect diagnostics.
31
+ ### Quickinfo
32
32
 
33
- HOWEVER, if you use `ts-patch` you can enable the transform as well to get the diagnostics also at compile time.
34
- Your `tsconfig.json` should look like this:
33
+ - Show the extended type of the current Effect
34
+ - Hovering yield\* of Effect.gen will show the Effect type parameters
35
+
36
+ ### Diagnostics
37
+
38
+ - Better error readability when you're missing errors or service types in your Effect definitions
39
+ - Floating Effects that are not yielded or run
40
+ - Wrong usage of yield inside Effect.gen
41
+ - Unnecessary usages of Effect.gen
42
+ - Multiple versions of Effect in your project
43
+
44
+ ### Completions
45
+
46
+ - Autocomplete 'Self' in Effect.Service, Context.Tag, Schema.TaggedClass, Schema.TaggedRequest and family
47
+
48
+ ### Refactors
49
+
50
+ - Transform an async function definition, into an Effect by using Effect.gen.
51
+ - Transform an async function definition, into an Effect by using Effect.gen, and generating a tagged error for each promise call.
52
+ - Transform a function returning an Effect.gen into a Effect.fn
53
+ - Function calls to pipe: Transform a set of function calls to a pipe() call.
54
+ - Pipe to datafirst: Transform a pipe() call into a series of datafirst function calls (where available).
55
+ - Toggle return type signature: With a single refactor, adds or removes type annotations from the definition.
56
+ - Remove unnecessary `Effect.gen` definitions that contains a single `yield` statement.
57
+ - Wrap an `Effect` expression with `Effect.gen`
58
+
59
+ ## Options
60
+
61
+ Few options can be provided alongside the initialization of the Language Service Plugin.
35
62
 
36
63
  ```json
37
64
  {
@@ -39,30 +66,22 @@ Your `tsconfig.json` should look like this:
39
66
  "plugins": [
40
67
  {
41
68
  "name": "@effect/language-service",
42
- "transform": "@effect/language-service/transform" // enables diagnostics at compile time when using ts-patch
69
+ "diagnostics": true, // controls Effect diagnostics (default: true)
70
+ "quickinfo": true, // controls quickinfo over Effect (default: true)
71
+ "completions": true, // controls Effect completions (default: true)
72
+ "multipleEffectCheck": true // controls if multiple versions of Effect are referenced (default: true)
43
73
  }
44
74
  ]
45
75
  }
46
76
  }
47
77
  ```
48
78
 
49
- To get diagnostics you need to install `ts-patch` which will make it possible to run `tspc`.
50
-
51
- Running `tspc` in your project will now also run the plugin and give you the diagnostics at compile time.
52
-
53
- ```ts
54
- $ npx tspc
55
- index.ts:3:1 - error TS3: Effect must be yielded or assigned to a variable.
56
-
57
- 3 Effect.succeed(1)
58
- ~~~~~~~~~~~~~~~~~
59
-
60
- Found 1 error in index.ts:3 
61
- ```
79
+ ## Why diagnostics does not appear at compile time?
62
80
 
63
- ## Options
81
+ TypeScript LSP are loaded only while editing your files. That means that if you run `tsc` in your project, the plugin won't be loaded and you'll miss out on the Effect diagnostics.
64
82
 
65
- Few options can be provided alongside the initialization of the Language Service Plugin.
83
+ HOWEVER, if you use `ts-patch` you can enable the transform as well to get the diagnostics also at compile time.
84
+ Your `tsconfig.json` should look like this:
66
85
 
67
86
  ```json
68
87
  {
@@ -70,44 +89,27 @@ Few options can be provided alongside the initialization of the Language Service
70
89
  "plugins": [
71
90
  {
72
91
  "name": "@effect/language-service",
73
- "diagnostics": true, // controls Effect diagnostics
74
- "quickinfo": true, // controls quickinfo over Effect
75
- "completions": true, // controls Effect completions
76
- "multipleEffectCheck": true // controls if multiple versions of Effect are referenced
92
+ "transform": "@effect/language-service/transform" // enables diagnostics at compile time when using ts-patch
77
93
  }
78
94
  ]
79
95
  }
80
96
  }
81
97
  ```
82
98
 
83
- ## Provided functionalities
84
-
85
- ### Quickinfo
86
-
87
- - Show the extended type of the current Effect
88
-
89
- ### Diagnostics
90
-
91
- - Better error readability when you're missing errors or service types in your Effect definitions
92
- - Floating Effects that are not yielded or run
93
- - Wrong usage of yield inside Effect.gen
94
- - Unnecessary usages of Effect.gen
95
- - Multiple versions of Effect in your project
99
+ To get diagnostics you need to install `ts-patch` which will make it possible to run `tspc`.
96
100
 
97
- ### Completions
101
+ Running `tspc` in your project will now also run the plugin and give you the diagnostics at compile time.
102
+ Effect diagnostics will be shown only after standard TypeScript diagnostics has been satisfied.
98
103
 
99
- - Autocomplete 'Self' in Effect.Service, Context.Tag, Schema.TaggedClass, Schema.TaggedRequest and family
104
+ ```ts
105
+ $ npx tspc
106
+ index.ts:3:1 - error TS3: Effect must be yielded or assigned to a variable.
100
107
 
101
- ### Refactors
108
+ 3 Effect.succeed(1)
109
+ ~~~~~~~~~~~~~~~~~
102
110
 
103
- - Transform an async function definition, into an Effect by using Effect.gen.
104
- - Transform an async function definition, into an Effect by using Effect.gen, and generating a tagged error for each promise call.
105
- - Transform a function returning an Effect.gen into a Effect.fn
106
- - Function calls to pipe: Transform a set of function calls to a pipe() call.
107
- - Pipe to datafirst: Transform a pipe() call into a series of datafirst function calls (where available).
108
- - Toggle return type signature: With a single refactor, adds or removes type annotations from the definition.
109
- - Remove unnecessary `Effect.gen` definitions that contains a single `yield` statement.
110
- - Wrap an `Effect` expression with `Effect.gen`
111
+ Found 1 error in index.ts:3 
112
+ ```
111
113
 
112
114
  ## Configuring diagnostics
113
115
 
package/index.js CHANGED
@@ -2614,6 +2614,7 @@ var JSDocTagInfoEq = make(
2614
2614
  (fa, fb) => fa.name === fb.name && typeof fa.text === typeof fb.text && (typeof fa.text !== "undefined" ? array(SymbolDisplayPartEq)(fa.text, fb.text) : true)
2615
2615
  );
2616
2616
  function dedupeJsDocTags(quickInfo) {
2617
+ if (!quickInfo) return quickInfo;
2617
2618
  if (quickInfo.tags) {
2618
2619
  return {
2619
2620
  ...quickInfo,
@@ -2639,21 +2640,33 @@ function prependEffectTypeArguments(sourceFile, position, quickInfo) {
2639
2640
  gen2(function* () {
2640
2641
  const ts = yield* service(TypeScriptApi);
2641
2642
  const typeChecker = yield* service(TypeCheckerApi);
2642
- const hasTruncationHappened = ts.displayPartsToString(quickInfo.displayParts).indexOf("...") > -1;
2643
- if (!hasTruncationHappened) return quickInfo;
2644
2643
  const maybeNode = pipe(
2645
2644
  yield* getAncestorNodesInRange(sourceFile, toTextRange(position)),
2646
2645
  head
2647
2646
  );
2648
2647
  if (isNone2(maybeNode)) return quickInfo;
2648
+ const node = maybeNode.value;
2649
+ const hasTruncationHappened = quickInfo && ts.displayPartsToString(quickInfo.displayParts).indexOf("...") > -1;
2650
+ const nodeForType = !quickInfo && ts.isYieldExpression(node) && node.asteriskToken && node.expression ? node.expression : hasTruncationHappened ? node : void 0;
2651
+ if (!nodeForType) return quickInfo;
2649
2652
  const effectType2 = yield* effectType(
2650
- typeChecker.getTypeAtLocation(maybeNode.value),
2651
- maybeNode.value
2653
+ typeChecker.getTypeAtLocation(nodeForType),
2654
+ nodeForType
2652
2655
  );
2653
2656
  const effectTypeArgsDocumentation = [{
2654
2657
  kind: "text",
2655
2658
  text: "```ts\n/* Effect Type Parameters */\n" + (yield* formatTypeForQuickInfo(effectType2.A, "Success")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.E, "Failure")) + "\n" + (yield* formatTypeForQuickInfo(effectType2.R, "Requirements")) + "\n```\n"
2656
2659
  }];
2660
+ if (!quickInfo) {
2661
+ const start = node.getStart();
2662
+ const end = node.getEnd();
2663
+ return {
2664
+ kind: ts.ScriptElementKind.callSignatureElement,
2665
+ kindModifiers: "",
2666
+ textSpan: { start, length: end - start },
2667
+ documentation: effectTypeArgsDocumentation
2668
+ };
2669
+ }
2657
2670
  if (quickInfo.documentation) {
2658
2671
  return {
2659
2672
  ...quickInfo,
@@ -4287,7 +4300,7 @@ var init = (modules) => {
4287
4300
  };
4288
4301
  proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {
4289
4302
  const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args);
4290
- if (pluginOptions.quickinfo && quickInfo) {
4303
+ if (pluginOptions.quickinfo) {
4291
4304
  const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo);
4292
4305
  const program = languageService.getProgram();
4293
4306
  if (program) {