@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
|
@@ -1053,7 +1053,7 @@ var match = (fa, opts) => {
|
|
|
1053
1053
|
var orElse2 = (f) => (fa) => {
|
|
1054
1054
|
const nano = Object.create(MatchProto);
|
|
1055
1055
|
nano[args] = fa;
|
|
1056
|
-
nano[contE] = f;
|
|
1056
|
+
nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : f(_);
|
|
1057
1057
|
return nano;
|
|
1058
1058
|
};
|
|
1059
1059
|
var firstSuccessOf = (arr) => arr.slice(1).reduce((arr2, fa) => orElse2(() => fa)(arr2), arr[0]);
|
|
@@ -1224,10 +1224,10 @@ function makeTypeScriptUtils(ts) {
|
|
|
1224
1224
|
if (!hasProperty(packageJsonScope.contents, "packageJsonContent")) return;
|
|
1225
1225
|
const packageJsonContent = packageJsonScope.contents.packageJsonContent;
|
|
1226
1226
|
if (!hasProperty(packageJsonContent, "name")) return;
|
|
1227
|
-
if (!hasProperty(packageJsonContent, "version")) return;
|
|
1228
1227
|
if (!hasProperty(packageJsonScope, "packageDirectory")) return;
|
|
1229
1228
|
if (!isString(packageJsonScope.packageDirectory)) return;
|
|
1230
|
-
const { name
|
|
1229
|
+
const { name } = packageJsonContent;
|
|
1230
|
+
const version = hasProperty(packageJsonScope, "version") ? packageJsonScope.version : "";
|
|
1231
1231
|
if (!isString(name)) return;
|
|
1232
1232
|
if (!isString(version)) return;
|
|
1233
1233
|
const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
|
|
@@ -1249,9 +1249,20 @@ function makeTypeScriptUtils(ts) {
|
|
|
1249
1249
|
exportsKeys
|
|
1250
1250
|
};
|
|
1251
1251
|
}
|
|
1252
|
-
function resolveModulePattern(sourceFile, pattern) {
|
|
1252
|
+
function resolveModulePattern(program, sourceFile, pattern) {
|
|
1253
1253
|
if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
|
|
1254
|
-
|
|
1254
|
+
let packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
|
|
1255
|
+
if (!packageJsonScope && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath) && hasProperty(ts, "getTemporaryModuleResolutionState") && isFunction2(ts.getTemporaryModuleResolutionState) && hasProperty(ts, "getPackageScopeForPath") && isFunction2(ts.getPackageScopeForPath)) {
|
|
1256
|
+
const temporaryModuleResolutionState = ts.getTemporaryModuleResolutionState(
|
|
1257
|
+
void 0,
|
|
1258
|
+
program,
|
|
1259
|
+
program.getCompilerOptions()
|
|
1260
|
+
);
|
|
1261
|
+
packageJsonScope = parsePackageContentNameAndVersionFromScope({
|
|
1262
|
+
...sourceFile,
|
|
1263
|
+
packageJsonScope: ts.getPackageScopeForPath(sourceFile.fileName, temporaryModuleResolutionState)
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1255
1266
|
const referencedPackages = [];
|
|
1256
1267
|
for (const statement of sourceFile.statements) {
|
|
1257
1268
|
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
@@ -1724,18 +1735,21 @@ var getApplicableRefactors = fn("LSP.getApplicableRefactors")(function* (refacto
|
|
|
1724
1735
|
const textRange = typeof positionOrRange === "number" ? { pos: positionOrRange, end: positionOrRange } : positionOrRange;
|
|
1725
1736
|
const effectRefactors = [];
|
|
1726
1737
|
for (const refactor of refactors) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
description: refactor.description,
|
|
1732
|
-
actions: [{
|
|
1738
|
+
yield* pipe(
|
|
1739
|
+
refactor.apply(sourceFile, textRange),
|
|
1740
|
+
map4(
|
|
1741
|
+
(result) => effectRefactors.push({
|
|
1733
1742
|
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1734
|
-
description:
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1743
|
+
description: refactor.description,
|
|
1744
|
+
actions: [{
|
|
1745
|
+
name: refactorNameToFullyQualifiedName(refactor.name),
|
|
1746
|
+
description: result.description,
|
|
1747
|
+
kind: result.kind
|
|
1748
|
+
}]
|
|
1749
|
+
})
|
|
1750
|
+
),
|
|
1751
|
+
ignore
|
|
1752
|
+
);
|
|
1739
1753
|
}
|
|
1740
1754
|
return effectRefactors;
|
|
1741
1755
|
});
|
|
@@ -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");
|