@effect/language-service 0.38.1 → 0.38.3
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/cli.js +15 -4
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +82 -17
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +123 -23
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +82 -17
- package/transform.js.map +1 -1
package/package.json
CHANGED
package/transform.js
CHANGED
|
@@ -1058,7 +1058,7 @@ var match = (fa, opts) => {
|
|
|
1058
1058
|
var orElse2 = (f) => (fa) => {
|
|
1059
1059
|
const nano = Object.create(MatchProto);
|
|
1060
1060
|
nano[args] = fa;
|
|
1061
|
-
nano[contE] = f;
|
|
1061
|
+
nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : f(_);
|
|
1062
1062
|
return nano;
|
|
1063
1063
|
};
|
|
1064
1064
|
var firstSuccessOf = (arr) => arr.slice(1).reduce((arr2, fa) => orElse2(() => fa)(arr2), arr[0]);
|
|
@@ -1229,10 +1229,10 @@ function makeTypeScriptUtils(ts) {
|
|
|
1229
1229
|
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
1230
1230
|
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
1231
1231
|
if (!hasProperty(packageJsonContent, "name")) return;
|
|
1232
|
-
if (!hasProperty(packageJsonContent, "version")) return;
|
|
1233
1232
|
if (!hasProperty(packageJsonScope, "packageDirectory")) return;
|
|
1234
1233
|
if (!isString(packageJsonScope.packageDirectory)) return;
|
|
1235
|
-
const { name
|
|
1234
|
+
const { name } = packageJsonContent;
|
|
1235
|
+
const version = hasProperty(packageJsonScope, "version") ? packageJsonScope.version : "";
|
|
1236
1236
|
if (!isString(name)) return;
|
|
1237
1237
|
if (!isString(version)) return;
|
|
1238
1238
|
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
@@ -1254,9 +1254,20 @@ function makeTypeScriptUtils(ts) {
|
|
|
1254
1254
|
exportsKeys
|
|
1255
1255
|
};
|
|
1256
1256
|
}
|
|
1257
|
-
function resolveModulePattern(sourceFile, pattern) {
|
|
1257
|
+
function resolveModulePattern(program, sourceFile, pattern) {
|
|
1258
1258
|
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1259
|
-
|
|
1259
|
+
let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1260
|
+
if (!packageJsonScope && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath) && hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState) && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
|
|
1261
|
+
const temporaryModuleResolutionState = ts.getTemporaryModuleResolutionState(
|
|
1262
|
+
void 0,
|
|
1263
|
+
program,
|
|
1264
|
+
program.getCompilerOptions()
|
|
1265
|
+
);
|
|
1266
|
+
packageJsonScope = parsePackageContentNameAndVersionFromScope({
|
|
1267
|
+
...sourceFile,
|
|
1268
|
+
packageJsonScope: ts.getPackageScopeForPath(sourceFile.fileName, temporaryModuleResolutionState)
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1260
1271
|
const referencedPackages = [];
|
|
1261
1272
|
for (const statement of sourceFile.statements) {
|
|
1262
1273
|
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
@@ -1729,18 +1740,21 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
|
|
|
1729
1740
|
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
1730
1741
|
const effectRefactors = [];
|
|
1731
1742
|
for (const refactor of refactors) {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
description: refactor.description,
|
|
1737
|
-
actions: [{
|
|
1743
|
+
yield* pipe(
|
|
1744
|
+
refactor.apply(sourceFile, textRange),
|
|
1745
|
+
map4(
|
|
1746
|
+
(result) => effectRefactors.push({
|
|
1738
1747
|
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1739
|
-
description:
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1748
|
+
description: refactor.description,
|
|
1749
|
+
actions: [{
|
|
1750
|
+
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1751
|
+
description: result.description,
|
|
1752
|
+
kind: result.kind
|
|
1753
|
+
}]
|
|
1754
|
+
})
|
|
1755
|
+
),
|
|
1756
|
+
ignore
|
|
1757
|
+
);
|
|
1744
1758
|
}
|
|
1745
1759
|
return effectRefactors;
|
|
1746
1760
|
});
|
|
@@ -3140,6 +3154,55 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3140
3154
|
"TypeParser.extendsContextTag",
|
|
3141
3155
|
(atLocation) => atLocation
|
|
3142
3156
|
);
|
|
3157
|
+
const extendsEffectTag = cachedBy(
|
|
3158
|
+
fn("TypeParser.extendsEffectTag")(function* (atLocation) {
|
|
3159
|
+
if (!atLocation.name) {
|
|
3160
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3161
|
+
}
|
|
3162
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
3163
|
+
if (!heritageClauses) {
|
|
3164
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
3165
|
+
}
|
|
3166
|
+
for (const heritageClause of heritageClauses) {
|
|
3167
|
+
for (const typeX of heritageClause.types) {
|
|
3168
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
3169
|
+
const wholeCall = typeX.expression;
|
|
3170
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
3171
|
+
const effectTagCall = wholeCall.expression;
|
|
3172
|
+
if (ts.isCallExpression(effectTagCall) && wholeCall.typeArguments && wholeCall.typeArguments.length > 0) {
|
|
3173
|
+
const effectTagIdentifier = effectTagCall.expression;
|
|
3174
|
+
const selfTypeNode = wholeCall.typeArguments[0];
|
|
3175
|
+
if (ts.isPropertyAccessExpression(effectTagIdentifier) && ts.isIdentifier(effectTagIdentifier.name) && ts.idText(effectTagIdentifier.name) === "Tag") {
|
|
3176
|
+
const parsedEffectModule = yield* pipe(
|
|
3177
|
+
importedEffectModule(effectTagIdentifier.expression),
|
|
3178
|
+
option
|
|
3179
|
+
);
|
|
3180
|
+
if (isSome2(parsedEffectModule)) {
|
|
3181
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3182
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3183
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3184
|
+
const tagType = yield* contextTag(type, atLocation);
|
|
3185
|
+
return {
|
|
3186
|
+
className: atLocation.name,
|
|
3187
|
+
selfTypeNode,
|
|
3188
|
+
keyStringLiteral: ts.isStringLiteral(effectTagCall.arguments[0]) ? effectTagCall.arguments[0] : void 0,
|
|
3189
|
+
args: effectTagCall.arguments,
|
|
3190
|
+
Identifier: tagType.Identifier,
|
|
3191
|
+
Service: tagType.Service,
|
|
3192
|
+
Tag: parsedEffectModule.value
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
return yield* typeParserIssue("Class does not extend Effect.Tag", void 0, atLocation);
|
|
3202
|
+
}),
|
|
3203
|
+
"TypeParser.extendsEffectTag",
|
|
3204
|
+
(atLocation) => atLocation
|
|
3205
|
+
);
|
|
3143
3206
|
const extendsEffectService = cachedBy(
|
|
3144
3207
|
fn("TypeParser.extendsEffectService")(function* (atLocation) {
|
|
3145
3208
|
if (!atLocation.name) {
|
|
@@ -3222,6 +3285,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3222
3285
|
pipeCall,
|
|
3223
3286
|
scopeType,
|
|
3224
3287
|
promiseLike,
|
|
3288
|
+
extendsEffectTag,
|
|
3225
3289
|
extendsEffectService,
|
|
3226
3290
|
extendsContextTag,
|
|
3227
3291
|
extendsSchemaClass,
|
|
@@ -3501,7 +3565,7 @@ var importFromBarrel = createDiagnostic({
|
|
|
3501
3565
|
const program = yield* service(TypeScriptProgram);
|
|
3502
3566
|
const packageNamesToCheck = flatten(
|
|
3503
3567
|
languageServicePluginOptions.namespaceImportPackages.map(
|
|
3504
|
-
(packageName) => tsUtils.resolveModulePattern(sourceFile, packageName)
|
|
3568
|
+
(packageName) => tsUtils.resolveModulePattern(program, sourceFile, packageName)
|
|
3505
3569
|
)
|
|
3506
3570
|
);
|
|
3507
3571
|
const isImportedFromBarrelExport = (element) => {
|
|
@@ -4464,6 +4528,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
4464
4528
|
if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
|
|
4465
4529
|
const { Service, accessors: accessors2, className } = yield* pipe(
|
|
4466
4530
|
typeParser.extendsEffectService(node),
|
|
4531
|
+
orElse2(() => map4(typeParser.extendsEffectTag(node), (_) => ({ accessors: true, ..._ }))),
|
|
4467
4532
|
orElse2(() => fail("not a class extending Effect.Service call"))
|
|
4468
4533
|
);
|
|
4469
4534
|
if (accessors2 !== true) return yield* fail("accessors are not enabled in the Effect.Service call");
|