@effect/language-service 0.16.7 → 0.17.1

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
@@ -45,6 +45,7 @@ And you're done! You'll now be able to use a set of refactor and diagnostics tha
45
45
  ### Completions
46
46
 
47
47
  - Autocomplete 'Self' in Effect.Service, Context.Tag, Schema.TaggedClass, Schema.TaggedRequest and family
48
+ - Autocomplete Effect.gen with `function*(){}`
48
49
 
49
50
  ### Refactors
50
51
 
package/index.js CHANGED
@@ -159,13 +159,13 @@ var array = (item) => make((self, that) => {
159
159
  });
160
160
 
161
161
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/internal/doNotation.js
162
- var let_ = (map4) => dual(3, (self, name, f) => map4(self, (a) => Object.assign({}, a, {
162
+ var let_ = (map5) => dual(3, (self, name, f) => map5(self, (a) => Object.assign({}, a, {
163
163
  [name]: f(a)
164
164
  })));
165
- var bindTo = (map4) => dual(2, (self, name) => map4(self, (a) => ({
165
+ var bindTo = (map5) => dual(2, (self, name) => map5(self, (a) => ({
166
166
  [name]: a
167
167
  })));
168
- var bind = (map4, flatMap4) => dual(3, (self, name, f) => flatMap4(self, (a) => map4(f(a), (b) => Object.assign({}, a, {
168
+ var bind = (map5, flatMap4) => dual(3, (self, name, f) => flatMap4(self, (a) => map5(f(a), (b) => Object.assign({}, a, {
169
169
  [name]: b
170
170
  }))));
171
171
 
@@ -907,6 +907,7 @@ var getOrElse2 = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNon
907
907
  var orElse2 = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
908
908
  var fromNullable2 = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
909
909
  var getOrUndefined2 = /* @__PURE__ */ getOrElse2(constUndefined);
910
+ var map2 = /* @__PURE__ */ dual(2, (self, f) => isNone2(self) ? none2() : some2(f(self.value)));
910
911
 
911
912
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Array.js
912
913
  var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
@@ -936,7 +937,7 @@ var sort = /* @__PURE__ */ dual(2, (self, O) => {
936
937
  return out;
937
938
  });
938
939
  var empty = () => [];
939
- var map2 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
940
+ var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
940
941
  var flatMap2 = /* @__PURE__ */ dual(2, (self, f) => {
941
942
  if (isEmptyReadonlyArray(self)) {
942
943
  return [];
@@ -1052,7 +1053,7 @@ var flatMap3 = dual(2, (fa, f) => make3((ctx) => {
1052
1053
  if (result._tag !== "Right") return result;
1053
1054
  return f(result.value).run(ctx);
1054
1055
  }));
1055
- var map3 = dual(2, (fa, f) => make3((ctx) => {
1056
+ var map4 = dual(2, (fa, f) => make3((ctx) => {
1056
1057
  const result = fa.run(ctx);
1057
1058
  if (result._tag !== "Right") return result;
1058
1059
  return makeInternalSuccess(f(result.value));
@@ -1372,50 +1373,62 @@ var tryPreserveDeclarationSemantics = fn("AST.tryPreserveDeclarationSemantics")(
1372
1373
  return node;
1373
1374
  }
1374
1375
  );
1376
+ var parseAccessedExpressionForCompletion = fn(
1377
+ "AST.parseAccessedExpressionForCompletion"
1378
+ )(
1379
+ function* (sourceFile, position) {
1380
+ const ts = yield* service(TypeScriptApi);
1381
+ const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
1382
+ if (!precedingToken) return yield* fail(new NodeNotFoundError());
1383
+ let accessedObject = precedingToken;
1384
+ let replacementSpan = ts.createTextSpan(position, 0);
1385
+ let outerNode = precedingToken;
1386
+ if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
1387
+ replacementSpan = ts.createTextSpan(
1388
+ precedingToken.parent.getStart(sourceFile),
1389
+ precedingToken.end - precedingToken.parent.getStart(sourceFile)
1390
+ );
1391
+ accessedObject = precedingToken.parent.expression;
1392
+ outerNode = precedingToken.parent;
1393
+ } else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
1394
+ replacementSpan = ts.createTextSpan(
1395
+ precedingToken.parent.getStart(sourceFile),
1396
+ precedingToken.end - precedingToken.parent.getStart(sourceFile)
1397
+ );
1398
+ accessedObject = precedingToken.parent.expression;
1399
+ outerNode = precedingToken.parent;
1400
+ } else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
1401
+ replacementSpan = ts.createTextSpan(
1402
+ precedingToken.getStart(sourceFile),
1403
+ precedingToken.end - precedingToken.getStart(sourceFile)
1404
+ );
1405
+ accessedObject = precedingToken;
1406
+ outerNode = precedingToken;
1407
+ } else {
1408
+ return yield* fail(new NodeNotFoundError());
1409
+ }
1410
+ return { accessedObject, outerNode, replacementSpan };
1411
+ }
1412
+ );
1375
1413
  var parseDataForExtendsClassCompletion = fn(
1376
1414
  "AST.parseDataForExtendsClassCompletion"
1377
1415
  )(function* (sourceFile, position) {
1378
1416
  const ts = yield* service(TypeScriptApi);
1379
- const precedingToken = ts.findPrecedingToken(position, sourceFile, void 0, true);
1380
- if (!precedingToken) return none2();
1381
- let accessedObject = precedingToken;
1382
- let replacementSpan = ts.createTextSpan(position, 0);
1383
- let outerNode = precedingToken;
1384
- if (ts.isIdentifier(precedingToken) && precedingToken.parent && ts.isPropertyAccessExpression(precedingToken.parent)) {
1385
- replacementSpan = ts.createTextSpan(
1386
- precedingToken.parent.getStart(sourceFile),
1387
- precedingToken.end - precedingToken.parent.getStart(sourceFile)
1388
- );
1389
- accessedObject = precedingToken.parent.expression;
1390
- outerNode = precedingToken.parent;
1391
- } else if (ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken && ts.isPropertyAccessExpression(precedingToken.parent)) {
1392
- replacementSpan = ts.createTextSpan(
1393
- precedingToken.parent.getStart(sourceFile),
1394
- precedingToken.end - precedingToken.parent.getStart(sourceFile)
1395
- );
1396
- accessedObject = precedingToken.parent.expression;
1397
- outerNode = precedingToken.parent;
1398
- } else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {
1399
- replacementSpan = ts.createTextSpan(
1400
- precedingToken.getStart(sourceFile),
1401
- precedingToken.end - precedingToken.getStart(sourceFile)
1402
- );
1403
- accessedObject = precedingToken;
1404
- outerNode = precedingToken;
1405
- } else {
1406
- return none2();
1407
- }
1408
- if (!ts.isIdentifier(accessedObject)) return none2();
1417
+ const { accessedObject, outerNode, replacementSpan } = yield* parseAccessedExpressionForCompletion(sourceFile, position);
1418
+ if (!ts.isIdentifier(accessedObject)) return yield* fail(new NodeNotFoundError());
1409
1419
  let classDeclaration = outerNode.parent;
1410
1420
  while (ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)) {
1411
1421
  if (!classDeclaration.parent) break;
1412
1422
  classDeclaration = classDeclaration.parent;
1413
1423
  }
1414
- if (!ts.isClassDeclaration(classDeclaration)) return none2();
1415
- if (!classDeclaration.name) return none2();
1416
- return some2(
1417
- { accessedObject, classDeclaration, className: classDeclaration.name, replacementSpan }
1418
- );
1424
+ if (!ts.isClassDeclaration(classDeclaration)) return yield* fail(new NodeNotFoundError());
1425
+ if (!classDeclaration.name) return yield* fail(new NodeNotFoundError());
1426
+ return {
1427
+ accessedObject,
1428
+ classDeclaration,
1429
+ className: classDeclaration.name,
1430
+ replacementSpan
1431
+ };
1419
1432
  });
1420
1433
  var createEffectGenCallExpression = fn("AST.createEffectGenCallExpression")(function* (effectModuleIdentifierName, node) {
1421
1434
  const ts = yield* service(TypeScriptApi);
@@ -1493,7 +1506,7 @@ var getSemanticDiagnosticsWithCodeFixes = fn(
1493
1506
  effectDiagnostics.push(
1494
1507
  ...pipe(
1495
1508
  result.value,
1496
- map2((_) => ({
1509
+ map3((_) => ({
1497
1510
  file: sourceFile,
1498
1511
  start: _.node.getStart(sourceFile),
1499
1512
  length: _.node.getEnd() - _.node.getStart(sourceFile),
@@ -1507,8 +1520,8 @@ var getSemanticDiagnosticsWithCodeFixes = fn(
1507
1520
  effectCodeFixes.push(
1508
1521
  ...pipe(
1509
1522
  result.value,
1510
- map2(
1511
- (_) => map2(
1523
+ map3(
1524
+ (_) => map3(
1512
1525
  _.fixes,
1513
1526
  (fix) => ({
1514
1527
  ...fix,
@@ -1647,7 +1660,9 @@ var contextSelfInClasses = createCompletion({
1647
1660
  name: "effect/contextSelfInClasses",
1648
1661
  apply: fn("contextSelfInClasses")(function* (sourceFile, position) {
1649
1662
  const ts = yield* service(TypeScriptApi);
1650
- const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
1663
+ const maybeInfos = yield* option(
1664
+ parseDataForExtendsClassCompletion(sourceFile, position)
1665
+ );
1651
1666
  if (isNone2(maybeInfos)) return [];
1652
1667
  const { accessedObject, className, replacementSpan } = maybeInfos.value;
1653
1668
  const contextName = yield* option(
@@ -1678,7 +1693,9 @@ var effectDataClasses = createCompletion({
1678
1693
  name: "effect/effectDataClasses",
1679
1694
  apply: fn("effectDataClasses")(function* (sourceFile, position) {
1680
1695
  const ts = yield* service(TypeScriptApi);
1681
- const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
1696
+ const maybeInfos = yield* option(
1697
+ parseDataForExtendsClassCompletion(sourceFile, position)
1698
+ );
1682
1699
  if (isNone2(maybeInfos)) return [];
1683
1700
  const { accessedObject, className, replacementSpan } = maybeInfos.value;
1684
1701
  const dataName = yield* option(
@@ -1715,7 +1732,9 @@ var effectSchemaSelfInClasses = createCompletion({
1715
1732
  name: "effect/effectSchemaSelfInClasses",
1716
1733
  apply: fn("effectSchemaSelfInClasses")(function* (sourceFile, position) {
1717
1734
  const ts = yield* service(TypeScriptApi);
1718
- const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
1735
+ const maybeInfos = yield* option(
1736
+ parseDataForExtendsClassCompletion(sourceFile, position)
1737
+ );
1719
1738
  if (isNone2(maybeInfos)) return [];
1720
1739
  const { accessedObject, className, replacementSpan } = maybeInfos.value;
1721
1740
  const effectSchemaName = yield* option(
@@ -1764,7 +1783,9 @@ var effectSelfInClasses = createCompletion({
1764
1783
  name: "effect/effectSelfInClasses",
1765
1784
  apply: fn("effectSelfInClasses")(function* (sourceFile, position) {
1766
1785
  const ts = yield* service(TypeScriptApi);
1767
- const maybeInfos = yield* parseDataForExtendsClassCompletion(sourceFile, position);
1786
+ const maybeInfos = yield* option(
1787
+ parseDataForExtendsClassCompletion(sourceFile, position)
1788
+ );
1768
1789
  if (isNone2(maybeInfos)) return [];
1769
1790
  const { accessedObject, className, replacementSpan } = maybeInfos.value;
1770
1791
  const effectName = yield* option(
@@ -1790,14 +1811,6 @@ var effectSelfInClasses = createCompletion({
1790
1811
  })
1791
1812
  });
1792
1813
 
1793
- // src/completions.ts
1794
- var completions = [
1795
- effectSchemaSelfInClasses,
1796
- effectSelfInClasses,
1797
- contextSelfInClasses,
1798
- effectDataClasses
1799
- ];
1800
-
1801
1814
  // src/core/TypeCheckerApi.ts
1802
1815
  var TypeCheckerApi = Tag("TypeChecker");
1803
1816
  var TypeCheckerApiCache = Tag("TypeCheckerApiCache");
@@ -2303,6 +2316,95 @@ var effectSchemaType = fn("TypeParser.effectSchemaType")(function* (type, atLoca
2303
2316
  return yield* typeParserIssue("Type has no schema variance struct", type, atLocation);
2304
2317
  });
2305
2318
 
2319
+ // src/completions/fnFunctionStar.ts
2320
+ var fnFunctionStar = createCompletion({
2321
+ name: "effect/fnFunctionStar",
2322
+ apply: fn("fnFunctionStar")(function* (sourceFile, position) {
2323
+ const ts = yield* service(TypeScriptApi);
2324
+ const maybeInfos = yield* option(
2325
+ parseAccessedExpressionForCompletion(sourceFile, position)
2326
+ );
2327
+ if (isNone2(maybeInfos)) return [];
2328
+ const { accessedObject } = maybeInfos.value;
2329
+ const isEffectModule = yield* option(importedEffectModule(accessedObject));
2330
+ if (isNone2(isEffectModule)) return [];
2331
+ const span = ts.createTextSpan(
2332
+ accessedObject.end + 1,
2333
+ Math.max(0, position - accessedObject.end - 1)
2334
+ );
2335
+ const maybeFnName = pipe(
2336
+ yield* getAncestorNodesInRange(sourceFile, toTextRange(accessedObject.pos)),
2337
+ filter(ts.isVariableDeclaration),
2338
+ map3((_) => _.name && ts.isIdentifier(_.name) ? _.name.text : ""),
2339
+ filter((_) => _.length > 0),
2340
+ head,
2341
+ map2((name) => [
2342
+ {
2343
+ name: `fn("${name}")`,
2344
+ kind: ts.ScriptElementKind.constElement,
2345
+ insertText: `fn("${name}")(function*(${"${1}"}){${"${0}"}})`,
2346
+ replacementSpan: span,
2347
+ isSnippet: true
2348
+ }
2349
+ ]),
2350
+ getOrElse2(() => [])
2351
+ );
2352
+ return maybeFnName.concat([{
2353
+ name: `fn(function*(){})`,
2354
+ kind: ts.ScriptElementKind.constElement,
2355
+ insertText: `fn(function*(${"${1}"}){${"${0}"}})`,
2356
+ replacementSpan: span,
2357
+ isSnippet: true
2358
+ }, {
2359
+ name: `fnUntraced(function*(){})`,
2360
+ kind: ts.ScriptElementKind.constElement,
2361
+ insertText: `fnUntraced(function*(${"${1}"}){${"${0}"}})`,
2362
+ replacementSpan: span,
2363
+ isSnippet: true
2364
+ }]);
2365
+ })
2366
+ });
2367
+
2368
+ // src/completions/genFunctionStar.ts
2369
+ var genFunctionStar = createCompletion({
2370
+ name: "effect/genFunctionStar",
2371
+ apply: fn("genFunctionStar")(function* (sourceFile, position) {
2372
+ const ts = yield* service(TypeScriptApi);
2373
+ const typeChecker = yield* service(TypeCheckerApi);
2374
+ const maybeInfos = yield* option(
2375
+ parseAccessedExpressionForCompletion(sourceFile, position)
2376
+ );
2377
+ if (isNone2(maybeInfos)) return [];
2378
+ const { accessedObject } = maybeInfos.value;
2379
+ const type = typeChecker.getTypeAtLocation(accessedObject);
2380
+ const genMemberSymbol = type.getProperty("gen");
2381
+ if (!genMemberSymbol) return [];
2382
+ const genType = typeChecker.getTypeOfSymbolAtLocation(genMemberSymbol, accessedObject);
2383
+ if (genType.getCallSignatures().length === 0) return [];
2384
+ const span = ts.createTextSpan(
2385
+ accessedObject.end + 1,
2386
+ Math.max(0, position - accessedObject.end - 1)
2387
+ );
2388
+ return [{
2389
+ name: `gen(function*(){})`,
2390
+ kind: ts.ScriptElementKind.constElement,
2391
+ insertText: `gen(function*(){${"${0}"}})`,
2392
+ replacementSpan: span,
2393
+ isSnippet: true
2394
+ }];
2395
+ })
2396
+ });
2397
+
2398
+ // src/completions.ts
2399
+ var completions = [
2400
+ effectSchemaSelfInClasses,
2401
+ effectSelfInClasses,
2402
+ contextSelfInClasses,
2403
+ genFunctionStar,
2404
+ fnFunctionStar,
2405
+ effectDataClasses
2406
+ ];
2407
+
2306
2408
  // src/diagnostics/floatingEffect.ts
2307
2409
  var floatingEffect = createDiagnostic({
2308
2410
  name: "effect/floatingEffect",
@@ -2737,7 +2839,7 @@ var asyncAwaitToGen = createRefactor({
2737
2839
  (node2) => pipe(
2738
2840
  importedEffectModule(node2),
2739
2841
  option,
2740
- map3(isSome2)
2842
+ map4(isSome2)
2741
2843
  )
2742
2844
  )
2743
2845
  ),
@@ -2809,7 +2911,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
2809
2911
  (node2) => pipe(
2810
2912
  importedEffectModule(node2),
2811
2913
  option,
2812
- map3(isSome2)
2914
+ map4(isSome2)
2813
2915
  )
2814
2916
  )
2815
2917
  ),
@@ -2920,7 +3022,7 @@ var effectGenToFn = createRefactor({
2920
3022
  });
2921
3023
  const maybeNode = yield* pipe(
2922
3024
  yield* getAncestorNodesInRange(sourceFile, textRange),
2923
- map2(parseEffectGenNode),
3025
+ map3(parseEffectGenNode),
2924
3026
  firstSuccessOf,
2925
3027
  option
2926
3028
  );
@@ -3055,7 +3157,7 @@ var _findSchemaVariableDeclaration = fn(
3055
3157
  );
3056
3158
  return yield* pipe(
3057
3159
  yield* getAncestorNodesInRange(sourceFile, textRange),
3058
- map2(findSchema),
3160
+ map3(findSchema),
3059
3161
  firstSuccessOf,
3060
3162
  option
3061
3163
  );
@@ -3348,7 +3450,7 @@ var pipeableToDatafirst = createRefactor({
3348
3450
  filter(
3349
3451
  (node2) => node2.arguments.length > 0
3350
3452
  ),
3351
- map2((node2) => {
3453
+ map3((node2) => {
3352
3454
  let newNode2 = node2.arguments[0];
3353
3455
  let didSomething = false;
3354
3456
  for (let i = 1; i < node2.arguments.length; i++) {
@@ -3375,7 +3477,7 @@ var pipeableToDatafirst = createRefactor({
3375
3477
  return didSomething ? some2([node2, newNode2]) : none2();
3376
3478
  }),
3377
3479
  filter(isSome2),
3378
- map2((_) => _.value),
3480
+ map3((_) => _.value),
3379
3481
  head
3380
3482
  );
3381
3483
  if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
@@ -4089,7 +4191,7 @@ var wrapWithEffectGen = createRefactor({
4089
4191
  );
4090
4192
  const maybeNode = yield* pipe(
4091
4193
  yield* getAncestorNodesInRange(sourceFile, textRange),
4092
- map2(findEffectToWrap),
4194
+ map3(findEffectToWrap),
4093
4195
  firstSuccessOf,
4094
4196
  option
4095
4197
  );
@@ -4123,7 +4225,7 @@ var getEffectModuleIdentifierName = fn("getEffectModuleIdentifierName")(
4123
4225
  (node) => pipe(
4124
4226
  importedEffectModule(node),
4125
4227
  option,
4126
- map3(isSome2)
4228
+ map4(isSome2)
4127
4229
  )
4128
4230
  )
4129
4231
  ),