@effect/language-service 0.36.0 → 0.37.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
@@ -88,6 +88,7 @@ And you're done! You'll now be able to use a set of refactors and diagnostics th
88
88
  - Toggle between pipe styles `X.pipe(Y)` and `pipe(X, Y)`
89
89
 
90
90
  ### Miscellaneous
91
+ - Renaming a class name, will rename the identifier as well for TaggedError, TaggedClass, etc...
91
92
  - "Go to definition" for RpcClient will resolve to the Rpc definition
92
93
 
93
94
  ## Options
@@ -113,7 +114,8 @@ Few options can be provided alongside the initialization of the Language Service
113
114
  "allowedDuplicatedPackages": [], // list of package names that have effect in peer dependencies and are allowed to be duplicated (default: [])
114
115
  "barrelImportPackages": [], // package names that should be preferred as imported from the top level barrel file (default: [])
115
116
  "namespaceImportPackages": [], // package names that should be preferred as imported with namespace imports e.g. ["effect", "@effect/*"] (default: [])
116
- "topLevelNamedReexports": "ignore" // for namespaceImportPackages, how should top level named re-exports (e.g. {pipe} from "effect") be treated? "ignore" will leave them as is, "follow" will rewrite them to the re-exported module (e.g. {pipe} from "effect/Function")
117
+ "topLevelNamedReexports": "ignore", // for namespaceImportPackages, how should top level named re-exports (e.g. {pipe} from "effect") be treated? "ignore" will leave them as is, "follow" will rewrite them to the re-exported module (e.g. {pipe} from "effect/Function")
118
+ "importAliases": { "Array": "Arr" } // allows to chose some different names for import name aliases (only when not chosing to import the whole module) (default: {})
117
119
  }
118
120
  ]
119
121
  }
package/cli.js CHANGED
@@ -28972,6 +28972,34 @@ var suspend11 = (fn3) => {
28972
28972
  nano[args2] = fn3;
28973
28973
  return nano;
28974
28974
  };
28975
+ var timings = {};
28976
+ var timingsCount = {};
28977
+ var WithSpanProto = {
28978
+ ...PrimitiveProto,
28979
+ [evaluate2](fiber) {
28980
+ const [fa, name] = this[args2];
28981
+ if (!fiber._perf) return fa;
28982
+ const start4 = performance.now();
28983
+ timingsCount[name] = (timingsCount[name] || 0) + 1;
28984
+ return match17(fa, {
28985
+ onSuccess: (_) => {
28986
+ const end5 = performance.now();
28987
+ timings[name] = (timings[name] || 0) + (end5 - start4);
28988
+ return succeed17(_);
28989
+ },
28990
+ onFailure: (_) => {
28991
+ const end5 = performance.now();
28992
+ timings[name] = (timings[name] || 0) + (end5 - start4);
28993
+ return fail18(_);
28994
+ }
28995
+ });
28996
+ }
28997
+ };
28998
+ var withSpan6 = (name) => (fa) => {
28999
+ const nano = Object.create(WithSpanProto);
29000
+ nano[args2] = [fa, name];
29001
+ return nano;
29002
+ };
28975
29003
  var OnSuccessProto2 = {
28976
29004
  ...PrimitiveProto,
28977
29005
  [evaluate2](fiber) {
@@ -29012,7 +29040,7 @@ var unsafeFromIterator = (iterator, initial) => {
29012
29040
  nano[args2] = [iterator, initial];
29013
29041
  return nano;
29014
29042
  };
29015
- var fn2 = (_) => (body) => (...args3) => suspend11(() => unsafeFromIterator(body(...args3)));
29043
+ var fn2 = (_) => (body) => (...args3) => withSpan6(_)(suspend11(() => unsafeFromIterator(body(...args3))));
29016
29044
  var MatchProto = {
29017
29045
  ...PrimitiveProto,
29018
29046
  [evaluate2](fiber) {
@@ -29264,7 +29292,7 @@ function makeTypeScriptUtils(ts4) {
29264
29292
  fnCall = ts4.factory.createCallExpression(
29265
29293
  fnCall,
29266
29294
  void 0,
29267
- [ts4.factory.createStringLiteral(fnName.text)]
29295
+ [ts4.factory.createStringLiteral(ts4.idText(fnName))]
29268
29296
  );
29269
29297
  }
29270
29298
  return tryPreserveDeclarationSemantics(
@@ -29336,7 +29364,7 @@ function makeTypeScriptUtils(ts4) {
29336
29364
  if (!namedBindings) continue;
29337
29365
  if (ts4.isNamespaceImport(namedBindings)) {
29338
29366
  if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
29339
- return namedBindings.name.text;
29367
+ return ts4.idText(namedBindings.name);
29340
29368
  }
29341
29369
  } else if (ts4.isNamedImports(namedBindings)) {
29342
29370
  for (const importSpecifier of namedBindings.elements) {
@@ -29344,7 +29372,7 @@ function makeTypeScriptUtils(ts4) {
29344
29372
  orElse(() => some2(importSpecifier.name))
29345
29373
  );
29346
29374
  if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
29347
- return importSpecifier.name.text;
29375
+ return ts4.idText(importSpecifier.name);
29348
29376
  }
29349
29377
  }
29350
29378
  }
@@ -29357,7 +29385,7 @@ function makeTypeScriptUtils(ts4) {
29357
29385
  if (isNone2(importProperty) && ts4.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
29358
29386
  return true;
29359
29387
  }
29360
- if (isSome2(importProperty) && ts4.isIdentifier(importProperty.value) && importProperty.value.text === moduleName && ts4.isStringLiteral(fromModule) && fromModule.text === packageName) {
29388
+ if (isSome2(importProperty) && ts4.isIdentifier(importProperty.value) && ts4.idText(importProperty.value) === moduleName && ts4.isStringLiteral(fromModule) && fromModule.text === packageName) {
29361
29389
  return true;
29362
29390
  }
29363
29391
  return false;
@@ -29791,9 +29819,11 @@ var moduleNames = choice3("module", [
29791
29819
  var getPatchesForModule = fn("getPatchesForModule")(
29792
29820
  function* (moduleName, dirPath4, version, sourceFile) {
29793
29821
  const patches = [];
29794
- let insertUtilsPosition = -1;
29795
- let insertCheckSourceFilePosition = -1;
29796
- let insertSkipPrecedingCommentDirectivePosition = -1;
29822
+ const insertUtilsPosition = some2({ position: 0 });
29823
+ let insertClearSourceFileEffectMetadataPosition = none2();
29824
+ let insertCheckSourceFilePosition = none2();
29825
+ let insertSkipPrecedingCommentDirectivePosition = none2();
29826
+ let insertAppendMetadataRelationErrorPosition = none2();
29797
29827
  const nodesToCheck = [];
29798
29828
  function findNodeAtPositionIncludingTrivia(sourceFile2, position) {
29799
29829
  function find3(node) {
@@ -29818,8 +29848,11 @@ var getPatchesForModule = fn("getPatchesForModule")(
29818
29848
  }
29819
29849
  return pushed;
29820
29850
  }
29821
- if (!pushFunctionDeclarationNode("checkSourceFileWorker")) nodesToCheck.push(sourceFile);
29822
- if (!pushFunctionDeclarationNode("markPrecedingCommentDirectiveLine")) nodesToCheck.push(sourceFile);
29851
+ let requiresFullScan = false;
29852
+ if (!pushFunctionDeclarationNode("checkSourceFileWorker")) requiresFullScan = true;
29853
+ if (!pushFunctionDeclarationNode("markPrecedingCommentDirectiveLine")) requiresFullScan = true;
29854
+ if (!pushFunctionDeclarationNode("reportRelationError")) requiresFullScan = true;
29855
+ if (requiresFullScan) nodesToCheck.push(sourceFile);
29823
29856
  while (nodesToCheck.length > 0) {
29824
29857
  const node = nodesToCheck.shift();
29825
29858
  if (!node) continue;
@@ -29829,12 +29862,29 @@ var getPatchesForModule = fn("getPatchesForModule")(
29829
29862
  const identifier2 = expression.expression;
29830
29863
  if (ts3.isIdentifier(identifier2) && ts3.idText(identifier2) === "checkGrammarSourceFile" && ts3.isBlock(node.parent) && node.parent.statements.length > 0) {
29831
29864
  const block = node.parent;
29832
- insertCheckSourceFilePosition = block.statements[block.statements.length - 1].end;
29865
+ const parentFunctionDeclaration = ts3.findAncestor(node, ts3.isFunctionDeclaration);
29866
+ if (parentFunctionDeclaration && parentFunctionDeclaration.name && ts3.isIdentifier(parentFunctionDeclaration.name) && ts3.idText(parentFunctionDeclaration.name) === "checkSourceFileWorker") {
29867
+ insertClearSourceFileEffectMetadataPosition = some2({ position: node.pos });
29868
+ insertCheckSourceFilePosition = some2({
29869
+ position: block.statements[block.statements.length - 1].end
29870
+ });
29871
+ }
29833
29872
  }
29834
29873
  }
29835
29874
  } else if (ts3.isFunctionDeclaration(node)) {
29836
29875
  if (node.name && ts3.isIdentifier(node.name) && ts3.idText(node.name) === "markPrecedingCommentDirectiveLine" && node.body && node.body.statements.length > 0) {
29837
- insertSkipPrecedingCommentDirectivePosition = node.body.statements[0].pos;
29876
+ insertSkipPrecedingCommentDirectivePosition = some2({ position: node.body.statements[0].pos });
29877
+ }
29878
+ if (node.name && ts3.isIdentifier(node.name) && ts3.idText(node.name) === "reportRelationError" && node.body && node.body.statements.length > 0 && node.parameters.length >= 3) {
29879
+ const sourceIdentifier2 = node.parameters[1] && ts3.isParameter(node.parameters[1]) && ts3.isIdentifier(node.parameters[1].name) ? ts3.idText(node.parameters[1].name) : void 0;
29880
+ const targetIdentifier2 = node.parameters[2] && ts3.isParameter(node.parameters[2]) && ts3.isIdentifier(node.parameters[2].name) ? ts3.idText(node.parameters[2].name) : void 0;
29881
+ if (sourceIdentifier2 && targetIdentifier2) {
29882
+ insertAppendMetadataRelationErrorPosition = some2({
29883
+ position: node.body.statements[0].pos,
29884
+ sourceIdentifier: sourceIdentifier2,
29885
+ targetIdentifier: targetIdentifier2
29886
+ });
29887
+ }
29838
29888
  }
29839
29889
  }
29840
29890
  ts3.forEachChild(node, (child) => {
@@ -29842,16 +29892,15 @@ var getPatchesForModule = fn("getPatchesForModule")(
29842
29892
  return void 0;
29843
29893
  });
29844
29894
  }
29845
- insertUtilsPosition = 0;
29846
- if (insertUtilsPosition === -1) {
29895
+ if (isNone2(insertUtilsPosition)) {
29847
29896
  return yield* fail7(new UnableToFindPositionToPatchError({ positionToFind: "effect lsp utils insertion" }));
29848
29897
  }
29849
29898
  if (moduleName !== "typescript") {
29850
29899
  patches.push(
29851
29900
  yield* makeEffectLspPatchChange(
29852
29901
  sourceFile.text,
29853
- insertUtilsPosition,
29854
- insertUtilsPosition,
29902
+ insertUtilsPosition.value.position,
29903
+ insertUtilsPosition.value.position,
29855
29904
  "\n" + (yield* getTypeScriptApisUtils(dirPath4)) + "\n",
29856
29905
  "",
29857
29906
  version
@@ -29861,28 +29910,61 @@ var getPatchesForModule = fn("getPatchesForModule")(
29861
29910
  patches.push(
29862
29911
  yield* makeEffectLspPatchChange(
29863
29912
  sourceFile.text,
29864
- insertUtilsPosition,
29865
- insertUtilsPosition,
29913
+ insertUtilsPosition.value.position,
29914
+ insertUtilsPosition.value.position,
29866
29915
  "\n" + (yield* getEffectLspPatchUtils()) + "\n",
29867
29916
  "",
29868
29917
  version
29869
29918
  )
29870
29919
  );
29871
- if (insertCheckSourceFilePosition === -1) {
29920
+ if (isNone2(insertClearSourceFileEffectMetadataPosition)) {
29921
+ return yield* fail7(
29922
+ new UnableToFindPositionToPatchError({ positionToFind: "clearSourceFileEffectMetadata" })
29923
+ );
29924
+ }
29925
+ patches.push(
29926
+ yield* makeEffectLspPatchChange(
29927
+ sourceFile.text,
29928
+ insertClearSourceFileEffectMetadataPosition.value.position,
29929
+ insertClearSourceFileEffectMetadataPosition.value.position,
29930
+ `effectLspPatchUtils.exports.clearSourceFileEffectMetadata(node)
29931
+ `,
29932
+ "\n",
29933
+ version
29934
+ )
29935
+ );
29936
+ if (isNone2(insertCheckSourceFilePosition)) {
29872
29937
  return yield* fail7(new UnableToFindPositionToPatchError({ positionToFind: "checkSourceFileWorker" }));
29873
29938
  }
29874
29939
  patches.push(
29875
29940
  yield* makeEffectLspPatchChange(
29876
29941
  sourceFile.text,
29877
- insertCheckSourceFilePosition,
29878
- insertCheckSourceFilePosition,
29942
+ insertCheckSourceFilePosition.value.position,
29943
+ insertCheckSourceFilePosition.value.position,
29879
29944
  `effectLspPatchUtils.exports.checkSourceFileWorker(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis"}, host, node, compilerOptions, diagnostics.add)
29880
29945
  `,
29881
29946
  "\n",
29882
29947
  version
29883
29948
  )
29884
29949
  );
29885
- if (insertSkipPrecedingCommentDirectivePosition === -1) {
29950
+ if (isNone2(insertAppendMetadataRelationErrorPosition)) {
29951
+ return yield* fail7(
29952
+ new UnableToFindPositionToPatchError({ positionToFind: "appendMetadataRelationError" })
29953
+ );
29954
+ }
29955
+ const { sourceIdentifier, targetIdentifier } = insertAppendMetadataRelationErrorPosition.value;
29956
+ patches.push(
29957
+ yield* makeEffectLspPatchChange(
29958
+ sourceFile.text,
29959
+ insertAppendMetadataRelationErrorPosition.value.position,
29960
+ insertAppendMetadataRelationErrorPosition.value.position,
29961
+ `effectLspPatchUtils.exports.appendMetadataRelationError(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis"}, errorNode, ${sourceIdentifier}, ${targetIdentifier})
29962
+ `,
29963
+ "\n",
29964
+ version
29965
+ )
29966
+ );
29967
+ if (isNone2(insertSkipPrecedingCommentDirectivePosition)) {
29886
29968
  return yield* fail7(
29887
29969
  new UnableToFindPositionToPatchError({ positionToFind: "skip preceding comment directive" })
29888
29970
  );
@@ -29890,8 +29972,8 @@ var getPatchesForModule = fn("getPatchesForModule")(
29890
29972
  patches.push(
29891
29973
  yield* makeEffectLspPatchChange(
29892
29974
  sourceFile.text,
29893
- insertSkipPrecedingCommentDirectivePosition,
29894
- insertSkipPrecedingCommentDirectivePosition,
29975
+ insertSkipPrecedingCommentDirectivePosition.value.position,
29976
+ insertSkipPrecedingCommentDirectivePosition.value.position,
29895
29977
  'if(diagnostic && diagnostic.source === "effect"){ return -1; }\n',
29896
29978
  "\n",
29897
29979
  version