@effect/tsgo 0.0.20 → 0.1.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
@@ -1,6 +1,6 @@
1
1
  # Effect Language Service (TypeScript-Go)
2
2
 
3
- A wrapper around [TypeScript-Go](https://github.com/nicolo-ribaudo/TypeScript-Go) that builds the Effect Language Service, providing Effect-TS diagnostics and quick fixes.
3
+ A wrapper around [TypeScript-Go](https://github.com/nicolo-ribaudo/TypeScript-Go) that builds the Effect Language Service, providing Effect-TS diagnostics and quick fixes.
4
4
  This project targets **Effect V4** (codename: "smol") primarily and also Effect V3.
5
5
 
6
6
  ## Currently in Alpha
@@ -21,6 +21,9 @@ This will guide you through the installation process, which includes:
21
21
  3. Adjusting plugin options to your preference.
22
22
  4. Hinting at any additional editor configuration needed to ensure the LSP is active.
23
23
 
24
+ > [!NOTE]
25
+ > At the moment, you still need the standard native TypeScript install (`@typescript/native-preview`) alongside `@effect/tsgo`.
26
+
24
27
  ## Diagnostic Status
25
28
 
26
29
  Some diagnostics are off by default or have a default severity of suggestion, but you can always enable them or change their default severity in the plugin options.
@@ -58,7 +61,7 @@ Some diagnostics are off by default or have a default severity of suggestion, bu
58
61
  <tr><td><code>leakingRequirements</code></td><td>💡</td><td></td><td>Detects implementation services leaked in service methods</td><td>✓</td><td>✓</td></tr>
59
62
  <tr><td><code>multipleEffectProvide</code></td><td>⚠️</td><td>🔧</td><td>Warns against chaining Effect.provide calls which can cause service lifecycle issues</td><td>✓</td><td>✓</td></tr>
60
63
  <tr><td><code>returnEffectInGen</code></td><td>💡</td><td>🔧</td><td>Warns when returning an Effect in a generator causes nested Effect&lt;Effect&lt;...&gt;&gt;</td><td>✓</td><td>✓</td></tr>
61
- <tr><td><code>runEffectInsideEffect</code></td><td>💡</td><td>🔧</td><td>Suggests using Runtime methods instead of Effect.run* inside Effect contexts</td><td>✓</td><td></td></tr>
64
+ <tr><td><code>runEffectInsideEffect</code></td><td>💡</td><td>🔧</td><td>Suggests using Runtime or Effect.run*With methods instead of Effect.run* inside Effect contexts</td><td>✓</td><td>✓</td></tr>
62
65
  <tr><td><code>schemaSyncInEffect</code></td><td>💡</td><td></td><td>Suggests using Effect-based Schema methods instead of sync methods inside Effect generators</td><td>✓</td><td></td></tr>
63
66
  <tr><td><code>scopeInLayerEffect</code></td><td>⚠️</td><td>🔧</td><td>Suggests using Layer.scoped instead of Layer.effect when Scope is in requirements</td><td>✓</td><td></td></tr>
64
67
  <tr><td><code>strictEffectProvide</code></td><td>➖</td><td></td><td>Warns when using Effect.provide with layers outside of application entry points</td><td>✓</td><td>✓</td></tr>
@@ -3910,6 +3910,39 @@ const getFailure$1 = getFailure$2;
3910
3910
  */
3911
3911
  const getOrElse$1 = /* @__PURE__ */ dual(2, (self, onNone) => isNone(self) ? onNone() : self.value);
3912
3912
  /**
3913
+ * Returns the fallback `Option` if `self` is `None`; otherwise returns `self`.
3914
+ *
3915
+ * **When to use**
3916
+ *
3917
+ * - Chaining fallback `Option` computations
3918
+ * - Building priority chains of optional values
3919
+ *
3920
+ * **Behavior**
3921
+ *
3922
+ * - `Some` → returns `self` unchanged
3923
+ * - `None` → evaluates and returns `that()`
3924
+ * - `that` is lazily evaluated
3925
+ *
3926
+ * **Example** (Providing a fallback Option)
3927
+ *
3928
+ * ```ts
3929
+ * import { Option } from "effect"
3930
+ *
3931
+ * console.log(Option.none().pipe(Option.orElse(() => Option.some("b"))))
3932
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }
3933
+ *
3934
+ * console.log(Option.some("a").pipe(Option.orElse(() => Option.some("b"))))
3935
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }
3936
+ * ```
3937
+ *
3938
+ * @see {@link orElseSome} to wrap the fallback value in `Some` automatically
3939
+ * @see {@link firstSomeOf} to pick the first `Some` from a collection
3940
+ *
3941
+ * @category Error handling
3942
+ * @since 2.0.0
3943
+ */
3944
+ const orElse = /* @__PURE__ */ dual(2, (self, that) => isNone(self) ? that() : self);
3945
+ /**
3913
3946
  * Converts a nullable value (`null` or `undefined`) into an `Option`.
3914
3947
  *
3915
3948
  * **When to use**
@@ -197344,14 +197377,16 @@ var FileReadError = class extends TaggedError("FileReadError") {
197344
197377
  //#endregion
197345
197378
  //#region package.json
197346
197379
  var name = "@effect/tsgo";
197347
- var version = "0.0.20";
197380
+ var version = "0.1.1";
197348
197381
 
197349
197382
  //#endregion
197350
197383
  //#region src/setup/consts.ts
197351
197384
  const LSP_PACKAGE_NAME = name;
197352
197385
  const LSP_PLUGIN_NAME = "@effect/language-service";
197386
+ const NATIVE_PREVIEW_PACKAGE_NAME = "@typescript/native-preview";
197353
197387
  const PATCH_COMMAND = "effect-tsgo patch";
197354
197388
  const DEFAULT_LSP_VERSION = version;
197389
+ const DEFAULT_NATIVE_PREVIEW_VERSION = "latest";
197355
197390
  const TSCONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/Effect-TS/tsgo/refs/heads/main/schema.json";
197356
197391
 
197357
197392
  //#endregion
@@ -197396,15 +197431,19 @@ const createAssessmentInput = (currentDir, tsconfigInput) => gen(function* () {
197396
197431
  const assessPackageJson = (input) => {
197397
197432
  const sourceFile = import_typescript.parseJsonText(input.fileName, input.text);
197398
197433
  const parsed = import_typescript.convertToObject(sourceFile, []);
197399
- let lspVersion = none$3();
197400
- if (LSP_PACKAGE_NAME in (parsed.devDependencies ?? {})) lspVersion = some({
197401
- dependencyType: "devDependencies",
197402
- version: parsed.devDependencies[LSP_PACKAGE_NAME]
197403
- });
197404
- else if (LSP_PACKAGE_NAME in (parsed.dependencies ?? {})) lspVersion = some({
197405
- dependencyType: "dependencies",
197406
- version: parsed.dependencies[LSP_PACKAGE_NAME]
197407
- });
197434
+ const assessDependency = (packageName) => {
197435
+ if (packageName in (parsed.devDependencies ?? {})) return some({
197436
+ dependencyType: "devDependencies",
197437
+ version: parsed.devDependencies[packageName]
197438
+ });
197439
+ if (packageName in (parsed.dependencies ?? {})) return some({
197440
+ dependencyType: "dependencies",
197441
+ version: parsed.dependencies[packageName]
197442
+ });
197443
+ return none$3();
197444
+ };
197445
+ const lspVersion = assessDependency(LSP_PACKAGE_NAME);
197446
+ const nativePreviewVersion = assessDependency(NATIVE_PREVIEW_PACKAGE_NAME);
197408
197447
  const prepareScript = "prepare" in (parsed.scripts ?? {}) ? some({
197409
197448
  script: parsed.scripts.prepare,
197410
197449
  hasPatch: parsed.scripts.prepare.toLowerCase().includes(PATCH_COMMAND)
@@ -197415,6 +197454,7 @@ const assessPackageJson = (input) => {
197415
197454
  parsed,
197416
197455
  text: input.text,
197417
197456
  lspVersion,
197457
+ nativePreviewVersion,
197418
197458
  prepareScript
197419
197459
  };
197420
197460
  };
@@ -197685,6 +197725,25 @@ function insertNodeAtEndOfList(tracker, sourceFile, nodeArray, newNode) {
197685
197725
  tracker.insertNodeAt(sourceFile, lastElement.end, newNode, { prefix: ",\n" });
197686
197726
  }
197687
197727
  }
197728
+ function findDependencyCollectionProperty(rootObj, dependencyType) {
197729
+ return findPropertyInObject(rootObj, dependencyType);
197730
+ }
197731
+ function upsertDependency(tracker, sourceFile, rootObj, dependencyName, dependency) {
197732
+ const depsProperty = findDependencyCollectionProperty(rootObj, dependency.dependencyType);
197733
+ if (!depsProperty) {
197734
+ const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(dependency.dependencyType), import_typescript.factory.createObjectLiteralExpression([import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(dependencyName), import_typescript.factory.createStringLiteral(dependency.version))], false));
197735
+ insertNodeAtEndOfList(tracker, sourceFile, rootObj.properties, newDepsProp);
197736
+ return;
197737
+ }
197738
+ if (!import_typescript.isObjectLiteralExpression(depsProperty.initializer)) return;
197739
+ const existingProperty = findPropertyInObject(depsProperty.initializer, dependencyName);
197740
+ if (!existingProperty) {
197741
+ const newDepProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(dependencyName), import_typescript.factory.createStringLiteral(dependency.version));
197742
+ insertNodeAtEndOfList(tracker, sourceFile, depsProperty.initializer.properties, newDepProp);
197743
+ return;
197744
+ }
197745
+ if (import_typescript.isStringLiteral(existingProperty.initializer) && existingProperty.initializer.text !== dependency.version) tracker.replaceNode(sourceFile, existingProperty.initializer, import_typescript.factory.createStringLiteral(dependency.version));
197746
+ }
197688
197747
  function createDiagnosticSeverityObject(severities) {
197689
197748
  const entries = Object.entries(severities).sort(([a], [b]) => a.localeCompare(b));
197690
197749
  return import_typescript.factory.createObjectLiteralExpression(entries.map(([name, severity]) => import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(name), import_typescript.factory.createStringLiteral(severity))), true);
@@ -197734,6 +197793,14 @@ const computePackageJsonChanges = (current, target) => {
197734
197793
  if (!rootObj) return emptyFileChangesResult();
197735
197794
  const ctx = createTrackerContext();
197736
197795
  const fileChange = tsInternal.textChanges.ChangeTracker.with(ctx, (tracker) => {
197796
+ const shouldAddNativePreviewWithDependencyType = (dependencyType) => isSome(target.nativePreviewVersion) && isNone(current.nativePreviewVersion) && target.nativePreviewVersion.value.dependencyType === dependencyType;
197797
+ const ensureNativePreviewDependency = () => {
197798
+ if (isNone(target.nativePreviewVersion) || isSome(current.nativePreviewVersion)) return;
197799
+ const targetNativePreview = target.nativePreviewVersion.value;
197800
+ if (!findDependencyCollectionProperty(rootObj, targetNativePreview.dependencyType) && isSome(target.lspVersion) && target.lspVersion.value.dependencyType === targetNativePreview.dependencyType) return;
197801
+ descriptions.push(`Add ${NATIVE_PREVIEW_PACKAGE_NAME}@${targetNativePreview.version} to ${targetNativePreview.dependencyType}`);
197802
+ upsertDependency(tracker, current.sourceFile, rootObj, NATIVE_PREVIEW_PACKAGE_NAME, targetNativePreview);
197803
+ };
197737
197804
  if (isSome(target.lspVersion)) {
197738
197805
  const targetDepType = target.lspVersion.value.dependencyType;
197739
197806
  const targetVersion = target.lspVersion.value.version;
@@ -197747,12 +197814,16 @@ const computePackageJsonChanges = (current, target) => {
197747
197814
  const lspProperty = findPropertyInObject(oldDepsProperty.initializer, LSP_PACKAGE_NAME);
197748
197815
  if (lspProperty) deleteNodeFromList(tracker, current.sourceFile, oldDepsProperty.initializer.properties, lspProperty);
197749
197816
  }
197750
- const newDepsProperty = findPropertyInObject(rootObj, targetDepType);
197751
- const newLspProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion));
197817
+ const newDepsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
197752
197818
  if (!newDepsProperty) {
197753
- const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression([newLspProp], false));
197819
+ const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
197820
+ if (shouldAddNativePreviewWithDependencyType(targetDepType)) {
197821
+ const targetNativePreview = target.nativePreviewVersion.pipe(getOrUndefined);
197822
+ if (targetNativePreview) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(NATIVE_PREVIEW_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetNativePreview.version)));
197823
+ }
197824
+ const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
197754
197825
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
197755
- } else if (import_typescript.isObjectLiteralExpression(newDepsProperty.initializer)) insertNodeAtEndOfList(tracker, current.sourceFile, newDepsProperty.initializer.properties, newLspProp);
197826
+ } else if (import_typescript.isObjectLiteralExpression(newDepsProperty.initializer)) insertNodeAtEndOfList(tracker, current.sourceFile, newDepsProperty.initializer.properties, import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion)));
197756
197827
  } else if (currentVersion !== targetVersion) {
197757
197828
  descriptions.push(`Update ${LSP_PACKAGE_NAME} from ${currentVersion} to ${targetVersion}`);
197758
197829
  const depsProperty = findPropertyInObject(rootObj, targetDepType);
@@ -197763,15 +197834,18 @@ const computePackageJsonChanges = (current, target) => {
197763
197834
  }
197764
197835
  } else {
197765
197836
  descriptions.push(`Add ${LSP_PACKAGE_NAME}@${targetVersion} to ${targetDepType}`);
197766
- const depsProperty = findPropertyInObject(rootObj, targetDepType);
197837
+ const depsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
197767
197838
  if (!depsProperty) {
197768
- const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression([import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))], false));
197839
+ const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
197840
+ if (shouldAddNativePreviewWithDependencyType(targetDepType)) {
197841
+ const targetNativePreview = target.nativePreviewVersion.pipe(getOrUndefined);
197842
+ if (targetNativePreview) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(NATIVE_PREVIEW_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetNativePreview.version)));
197843
+ }
197844
+ const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
197769
197845
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
197770
- } else if (import_typescript.isObjectLiteralExpression(depsProperty.initializer)) {
197771
- const newLspProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion));
197772
- insertNodeAtEndOfList(tracker, current.sourceFile, depsProperty.initializer.properties, newLspProp);
197773
- }
197846
+ } else if (import_typescript.isObjectLiteralExpression(depsProperty.initializer)) insertNodeAtEndOfList(tracker, current.sourceFile, depsProperty.initializer.properties, import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion)));
197774
197847
  }
197848
+ ensureNativePreviewDependency();
197775
197849
  } else if (isSome(current.lspVersion)) {
197776
197850
  descriptions.push(`Remove ${LSP_PACKAGE_NAME} from dependencies`);
197777
197851
  const currentDepType = current.lspVersion.value.dependencyType;
@@ -198594,17 +198668,21 @@ var rules = [
198594
198668
  {
198595
198669
  "name": "runEffectInsideEffect",
198596
198670
  "group": "antipattern",
198597
- "description": "Suggests using Runtime methods instead of Effect.run* inside Effect contexts",
198671
+ "description": "Suggests using Runtime or Effect.run*With methods instead of Effect.run* inside Effect contexts",
198598
198672
  "defaultSeverity": "suggestion",
198599
198673
  "fixable": true,
198600
- "supportedEffect": ["v3"],
198601
- "codes": [377024, 377025],
198674
+ "supportedEffect": ["v3", "v4"],
198675
+ "codes": [
198676
+ 377024,
198677
+ 377025,
198678
+ 377074
198679
+ ],
198602
198680
  "preview": {
198603
198681
  "sourceText": "import { Effect } from \"effect\"\n\nexport const preview = Effect.gen(function*() {\n const run = () => Effect.runSync(Effect.succeed(1))\n return run()\n})\n",
198604
198682
  "diagnostics": [{
198605
198683
  "start": 101,
198606
198684
  "end": 115,
198607
- "text": "Using Effect.runSync inside an Effect is not recommended. The same runtime should generally be used instead to run child effects.\nConsider extracting the Runtime by using for example Effect.runtime and then use Runtime.runSync with the extracted runtime instead. effect(runEffectInsideEffect)"
198685
+ "text": "Using Effect.runSync inside an Effect is not recommended. The same services should generally be used instead to run child effects.\nConsider extracting the current services by using for example Effect.services and then use Effect.runSyncWith with the extracted services instead. effect(runEffectInsideEffect)"
198608
198686
  }]
198609
198687
  }
198610
198688
  },
@@ -199608,6 +199686,7 @@ function createRulePrompt(rules, initialSeverities) {
199608
199686
  const fromAssessment = (inputState) => ({
199609
199687
  packageJson: {
199610
199688
  lspVersion: inputState.packageJson.lspVersion,
199689
+ nativePreviewVersion: inputState.packageJson.nativePreviewVersion,
199611
199690
  prepareScript: map$9(inputState.packageJson.prepareScript, (_) => _.hasPatch).pipe(getOrElse$1(() => false))
199612
199691
  },
199613
199692
  tsconfig: { diagnosticSeverities: inputState.tsconfig.currentDiagnosticSeverities },
@@ -199779,6 +199858,7 @@ const gatherTargetState = (assessment, context) => gen(function* () {
199779
199858
  if (lspDependencyType === "no") return {
199780
199859
  packageJson: {
199781
199860
  lspVersion: none$3(),
199861
+ nativePreviewVersion: assessment.packageJson.nativePreviewVersion,
199782
199862
  prepareScript: false
199783
199863
  },
199784
199864
  tsconfig: { diagnosticSeverities: none$3() },
@@ -199836,6 +199916,10 @@ const gatherTargetState = (assessment, context) => gen(function* () {
199836
199916
  dependencyType: lspDependencyType,
199837
199917
  version: context.defaultLspVersion
199838
199918
  }),
199919
+ nativePreviewVersion: orElse(assessment.packageJson.nativePreviewVersion, () => some({
199920
+ dependencyType: lspDependencyType,
199921
+ version: DEFAULT_NATIVE_PREVIEW_VERSION
199922
+ })),
199839
199923
  prepareScript: true
199840
199924
  },
199841
199925
  tsconfig: { diagnosticSeverities },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/tsgo",
3
- "version": "0.0.20",
3
+ "version": "0.1.1",
4
4
  "description": "Effect Language Service for TypeScript-Go — Effect-specific diagnostics and hover features.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,13 +22,13 @@
22
22
  "README.md"
23
23
  ],
24
24
  "optionalDependencies": {
25
- "@effect/tsgo-win32-x64": "0.0.20",
26
- "@effect/tsgo-win32-arm64": "0.0.20",
27
- "@effect/tsgo-linux-x64": "0.0.20",
28
- "@effect/tsgo-linux-arm64": "0.0.20",
29
- "@effect/tsgo-linux-arm": "0.0.20",
30
- "@effect/tsgo-darwin-x64": "0.0.20",
31
- "@effect/tsgo-darwin-arm64": "0.0.20"
25
+ "@effect/tsgo-win32-x64": "0.1.1",
26
+ "@effect/tsgo-win32-arm64": "0.1.1",
27
+ "@effect/tsgo-linux-x64": "0.1.1",
28
+ "@effect/tsgo-linux-arm64": "0.1.1",
29
+ "@effect/tsgo-linux-arm": "0.1.1",
30
+ "@effect/tsgo-darwin-x64": "0.1.1",
31
+ "@effect/tsgo-darwin-arm64": "0.1.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@effect/platform-node": "^4.0.0-beta.40",