@effect/language-service 0.39.0 → 0.40.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
@@ -55,6 +55,7 @@ And you're done! You'll now be able to use a set of refactors and diagnostics th
55
55
  - Warn on subsequent `Effect.provide` anti-pattern
56
56
  - Detect wrong `Self` type parameter for APIs like `Effect.Service` or `Schema.TaggedError` and similar 
57
57
  - Unnecessary usages of `Effect.gen` or `pipe()`
58
+ - Warn when using `Effect.gen` with the old generator adapter pattern
58
59
  - Warn when importing from a barrel file instead of from the module directly
59
60
  - Warn on usage of try/catch inside `Effect.gen` and family
60
61
  - Detect unnecessary pipe chains like `X.pipe(Y).pipe(Z)`
@@ -116,7 +117,8 @@ Few options can be provided alongside the initialization of the Language Service
116
117
  "barrelImportPackages": [], // package names that should be preferred as imported from the top level barrel file (default: [])
117
118
  "namespaceImportPackages": [], // package names that should be preferred as imported with namespace imports e.g. ["effect", "@effect/*"] (default: [])
118
119
  "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")
119
- "importAliases": { "Array": "Arr" } // allows to chose some different names for import name aliases (only when not chosing to import the whole module) (default: {})
120
+ "importAliases": { "Array": "Arr" }, // allows to chose some different names for import name aliases (only when not chosing to import the whole module) (default: {})
121
+ "noExternal": false // disables features that provides links to external websites (such as links to mermaidchart.com) (default: false)
120
122
  }
121
123
  ]
122
124
  }
package/cli.js CHANGED
@@ -29664,10 +29664,20 @@ var getTypeScriptApisUtils = fn("getTypeScriptApisFile")(
29664
29664
  function* (dirPath4) {
29665
29665
  const filePath = yield* getModuleFilePath(dirPath4, "typescript");
29666
29666
  const sourceFile = yield* getUnpatchedSourceFile(filePath);
29667
- const patchWithWrappingFunction = `var effectLspTypeScriptApis = (function(module){
29668
- ${sourceFile.text}
29667
+ const bodyWithoutBundlerComment = yield* omitBundlerSourceFileComment(
29668
+ sourceFile.text.split("\n").map((line4) => ` ${line4}`).join("\n")
29669
+ );
29670
+ const patchWithWrappingFunction = `
29671
+ var _effectLspTypeScriptApis = undefined;
29672
+ function effectLspTypeScriptApis(){
29673
+ if(!_effectLspTypeScriptApis){
29674
+ _effectLspTypeScriptApis = (function(module){
29675
+ ${bodyWithoutBundlerComment}
29669
29676
  return ts
29670
- })(effectLspTypeScriptApis);`;
29677
+ })(effectLspTypeScriptApis);
29678
+ }
29679
+ return _effectLspTypeScriptApis;
29680
+ }`;
29671
29681
  return patchWithWrappingFunction;
29672
29682
  }
29673
29683
  );
@@ -29676,10 +29686,20 @@ var getEffectLspPatchUtils = fn("getEffectLspPatchUtils")(function* () {
29676
29686
  const fs = yield* FileSystem;
29677
29687
  const effectLspPatchUtilsPath = path2.resolve(__dirname, "effect-lsp-patch-utils.js");
29678
29688
  const effectLspPatchUtilsContent = yield* fs.readFileString(effectLspPatchUtilsPath);
29679
- const patchWithWrappingFunction = `var effectLspPatchUtils = (function(module){
29680
- ${effectLspPatchUtilsContent}
29689
+ const bodyWithoutBundlerComment = yield* omitBundlerSourceFileComment(
29690
+ effectLspPatchUtilsContent.split("\n").map((line4) => ` ${line4}`).join("\n")
29691
+ );
29692
+ const patchWithWrappingFunction = `
29693
+ var _effectLspPatchUtils = undefined;
29694
+ function effectLspPatchUtils(){
29695
+ if(!_effectLspPatchUtils){
29696
+ _effectLspPatchUtils = (function(module){
29697
+ ${bodyWithoutBundlerComment}
29681
29698
  return module
29682
- })(effectLspPatchUtils || {});`;
29699
+ })({});
29700
+ }
29701
+ return _effectLspPatchUtils.exports;
29702
+ }`;
29683
29703
  return patchWithWrappingFunction;
29684
29704
  });
29685
29705
  var AppliedPatchMetadata = compose3(
@@ -29774,6 +29794,30 @@ var getUnpatchedSourceFile = fn("getUnpatchedSourceFile")(function* (filePath) {
29774
29794
  );
29775
29795
  return newSourceFile;
29776
29796
  });
29797
+ var omitBundlerSourceFileComment = fn("omitBundlerSourceFileComment")(
29798
+ function* (originalSourceText) {
29799
+ const deleteChanges = [];
29800
+ const sourceFile = ts.createSourceFile(
29801
+ "file.ts",
29802
+ originalSourceText,
29803
+ ts.ScriptTarget.ES2022,
29804
+ true
29805
+ );
29806
+ const lineStarts = sourceFile.getLineStarts();
29807
+ const regex = /^\s*\/\/\s*src\//gmid;
29808
+ for (let i = 0; i < lineStarts.length; i++) {
29809
+ const pos = lineStarts[i];
29810
+ const end5 = i >= lineStarts.length ? sourceFile.text.length : lineStarts[i + 1];
29811
+ if (sourceFile.text.substring(pos, end5).match(regex)) {
29812
+ deleteChanges.push({
29813
+ span: { start: pos, length: end5 - 1 - pos },
29814
+ newText: ""
29815
+ });
29816
+ }
29817
+ }
29818
+ return yield* applyTextChanges(sourceFile.text, deleteChanges);
29819
+ }
29820
+ );
29777
29821
 
29778
29822
  // src/cli/check.ts
29779
29823
  var LOCAL_TYPESCRIPT_DIR = "./node_modules/typescript";
@@ -29831,7 +29875,6 @@ var moduleNames = choice3("module", [
29831
29875
  var getPatchesForModule = fn("getPatchesForModule")(
29832
29876
  function* (moduleName, dirPath4, version, sourceFile) {
29833
29877
  const patches = [];
29834
- const insertUtilsPosition = some2({ position: 0 });
29835
29878
  let insertClearSourceFileEffectMetadataPosition = none2();
29836
29879
  let insertCheckSourceFilePosition = none2();
29837
29880
  let insertSkipPrecedingCommentDirectivePosition = none2();
@@ -29904,31 +29947,6 @@ var getPatchesForModule = fn("getPatchesForModule")(
29904
29947
  return void 0;
29905
29948
  });
29906
29949
  }
29907
- if (isNone2(insertUtilsPosition)) {
29908
- return yield* fail7(new UnableToFindPositionToPatchError({ positionToFind: "effect lsp utils insertion" }));
29909
- }
29910
- if (moduleName !== "typescript") {
29911
- patches.push(
29912
- yield* makeEffectLspPatchChange(
29913
- sourceFile.text,
29914
- insertUtilsPosition.value.position,
29915
- insertUtilsPosition.value.position,
29916
- "\n" + (yield* getTypeScriptApisUtils(dirPath4)) + "\n",
29917
- "",
29918
- version
29919
- )
29920
- );
29921
- }
29922
- patches.push(
29923
- yield* makeEffectLspPatchChange(
29924
- sourceFile.text,
29925
- insertUtilsPosition.value.position,
29926
- insertUtilsPosition.value.position,
29927
- "\n" + (yield* getEffectLspPatchUtils()) + "\n",
29928
- "",
29929
- version
29930
- )
29931
- );
29932
29950
  if (isNone2(insertClearSourceFileEffectMetadataPosition)) {
29933
29951
  return yield* fail7(
29934
29952
  new UnableToFindPositionToPatchError({ positionToFind: "clearSourceFileEffectMetadata" })
@@ -29939,7 +29957,7 @@ var getPatchesForModule = fn("getPatchesForModule")(
29939
29957
  sourceFile.text,
29940
29958
  insertClearSourceFileEffectMetadataPosition.value.position,
29941
29959
  insertClearSourceFileEffectMetadataPosition.value.position,
29942
- `effectLspPatchUtils.exports.clearSourceFileEffectMetadata(node)
29960
+ `effectLspPatchUtils().clearSourceFileEffectMetadata(node)
29943
29961
  `,
29944
29962
  "\n",
29945
29963
  version
@@ -29953,7 +29971,7 @@ var getPatchesForModule = fn("getPatchesForModule")(
29953
29971
  sourceFile.text,
29954
29972
  insertCheckSourceFilePosition.value.position,
29955
29973
  insertCheckSourceFilePosition.value.position,
29956
- `effectLspPatchUtils.exports.checkSourceFileWorker(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis"}, host, node, compilerOptions, diagnostics.add)
29974
+ `effectLspPatchUtils().checkSourceFileWorker(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis()"}, host, node, compilerOptions, diagnostics.add)
29957
29975
  `,
29958
29976
  "\n",
29959
29977
  version
@@ -29970,7 +29988,7 @@ var getPatchesForModule = fn("getPatchesForModule")(
29970
29988
  sourceFile.text,
29971
29989
  insertAppendMetadataRelationErrorPosition.value.position,
29972
29990
  insertAppendMetadataRelationErrorPosition.value.position,
29973
- `effectLspPatchUtils.exports.appendMetadataRelationError(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis"}, errorNode, ${sourceIdentifier}, ${targetIdentifier})
29991
+ `effectLspPatchUtils().appendMetadataRelationError(${moduleName === "typescript" ? "module.exports" : "effectLspTypeScriptApis()"}, errorNode, ${sourceIdentifier}, ${targetIdentifier})
29974
29992
  `,
29975
29993
  "\n",
29976
29994
  version
@@ -29991,6 +30009,30 @@ var getPatchesForModule = fn("getPatchesForModule")(
29991
30009
  version
29992
30010
  )
29993
30011
  );
30012
+ let eofPos = sourceFile.text.lastIndexOf("// src/") - 1;
30013
+ if (eofPos < 0) eofPos = sourceFile.text.length;
30014
+ if (moduleName !== "typescript") {
30015
+ patches.push(
30016
+ yield* makeEffectLspPatchChange(
30017
+ sourceFile.text,
30018
+ eofPos,
30019
+ eofPos,
30020
+ yield* getTypeScriptApisUtils(dirPath4),
30021
+ "\n\n// src/@effect/language-service/effect-lsp-patch-utils.ts\n",
30022
+ version
30023
+ )
30024
+ );
30025
+ }
30026
+ patches.push(
30027
+ yield* makeEffectLspPatchChange(
30028
+ sourceFile.text,
30029
+ eofPos,
30030
+ eofPos,
30031
+ yield* getEffectLspPatchUtils(),
30032
+ "\n\n// src/@effect/language-service/embedded-typescript-copy.ts\n",
30033
+ version
30034
+ )
30035
+ );
29994
30036
  return patches;
29995
30037
  }
29996
30038
  );