@effect/language-service 0.42.0 → 0.43.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 +52 -1
- package/effect-lsp-patch-utils.js +144 -3
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +421 -275
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +144 -3
- package/transform.js.map +1 -1
package/package.json
CHANGED
package/transform.js
CHANGED
|
@@ -1189,8 +1189,25 @@ var defaults = {
|
|
|
1189
1189
|
barrelImportPackages: [],
|
|
1190
1190
|
importAliases: {},
|
|
1191
1191
|
renames: true,
|
|
1192
|
-
noExternal: false
|
|
1192
|
+
noExternal: false,
|
|
1193
|
+
keyPatterns: [{
|
|
1194
|
+
target: "service",
|
|
1195
|
+
pattern: "default",
|
|
1196
|
+
skipLeadingPath: ["src/"]
|
|
1197
|
+
}]
|
|
1193
1198
|
};
|
|
1199
|
+
function parseKeyPatterns(patterns) {
|
|
1200
|
+
const result = [];
|
|
1201
|
+
for (const entry of patterns) {
|
|
1202
|
+
if (!isObject(entry)) continue;
|
|
1203
|
+
result.push({
|
|
1204
|
+
target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
|
|
1205
|
+
pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
|
|
1206
|
+
skipLeadingPath: hasProperty(entry, "skipLeadingPath") && isArray(entry.skipLeadingPath) && entry.skipLeadingPath.every(isString) ? entry.skipLeadingPath : ["src/"]
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
return result;
|
|
1210
|
+
}
|
|
1194
1211
|
function parse(config) {
|
|
1195
1212
|
return {
|
|
1196
1213
|
refactors: isObject(config) && hasProperty(config, "refactors") && isBoolean(config.refactors) ? config.refactors : defaults.refactors,
|
|
@@ -1208,7 +1225,8 @@ function parse(config) {
|
|
|
1208
1225
|
importAliases: isObject(config) && hasProperty(config, "importAliases") && isRecord(config.importAliases) ? map2(config.importAliases, (value) => String(value)) : defaults.importAliases,
|
|
1209
1226
|
topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
|
|
1210
1227
|
renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames,
|
|
1211
|
-
noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal
|
|
1228
|
+
noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal,
|
|
1229
|
+
keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns
|
|
1212
1230
|
};
|
|
1213
1231
|
}
|
|
1214
1232
|
|
|
@@ -3462,6 +3480,128 @@ var classSelfMismatch = createDiagnostic({
|
|
|
3462
3480
|
})
|
|
3463
3481
|
});
|
|
3464
3482
|
|
|
3483
|
+
// src/core/KeyBuilder.ts
|
|
3484
|
+
var makeKeyBuilder = fn("KeyBuilder")(
|
|
3485
|
+
function* (sourceFile) {
|
|
3486
|
+
const ts = yield* service(TypeScriptApi);
|
|
3487
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
3488
|
+
const program = yield* service(TypeScriptProgram);
|
|
3489
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
3490
|
+
const packageInfo = tsUtils.resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
|
|
3491
|
+
function createString2(classNameText, kind) {
|
|
3492
|
+
if (!packageInfo) return;
|
|
3493
|
+
for (const keyPattern of options.keyPatterns) {
|
|
3494
|
+
if (keyPattern.target !== kind) continue;
|
|
3495
|
+
const lastIndex = sourceFile.fileName.lastIndexOf("/");
|
|
3496
|
+
let onlyFileName = lastIndex === -1 ? "" : sourceFile.fileName.slice(lastIndex + 1);
|
|
3497
|
+
const lastExtensionIndex = onlyFileName.lastIndexOf(".");
|
|
3498
|
+
if (lastExtensionIndex !== -1) onlyFileName = onlyFileName.slice(0, lastExtensionIndex);
|
|
3499
|
+
if (onlyFileName.toLowerCase().endsWith("/index")) onlyFileName = onlyFileName.slice(0, -6);
|
|
3500
|
+
if (onlyFileName.startsWith("/")) onlyFileName = onlyFileName.slice(1);
|
|
3501
|
+
let subDirectory = getDirectoryPath(ts, sourceFile.fileName);
|
|
3502
|
+
if (!subDirectory.startsWith(packageInfo.packageDirectory)) continue;
|
|
3503
|
+
subDirectory = subDirectory.slice(packageInfo.packageDirectory.length);
|
|
3504
|
+
if (!subDirectory.endsWith("/")) subDirectory = subDirectory + "/";
|
|
3505
|
+
if (subDirectory.startsWith("/")) subDirectory = subDirectory.slice(1);
|
|
3506
|
+
for (const prefix of keyPattern.skipLeadingPath) {
|
|
3507
|
+
if (subDirectory.startsWith(prefix)) {
|
|
3508
|
+
subDirectory = subDirectory.slice(prefix.length);
|
|
3509
|
+
break;
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
let parts = [packageInfo.name, subDirectory, onlyFileName].concat(
|
|
3513
|
+
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
3514
|
+
);
|
|
3515
|
+
if (keyPattern.pattern === "package-identifier") {
|
|
3516
|
+
parts = [packageInfo.name, onlyFileName].concat(
|
|
3517
|
+
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
3518
|
+
);
|
|
3519
|
+
}
|
|
3520
|
+
parts = parts.map((part) => part.startsWith("/") ? part.slice(1) : part).map(
|
|
3521
|
+
(part) => part.endsWith("/") ? part.slice(0, -1) : part
|
|
3522
|
+
);
|
|
3523
|
+
return parts.filter((_) => String(_).trim().length > 0).join("/");
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
return {
|
|
3527
|
+
createString: createString2
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
);
|
|
3531
|
+
var keyBuilderCache = /* @__PURE__ */ new Map();
|
|
3532
|
+
var getOrMakeKeyBuilder = fn("getOrMakeKeyBuilder")(function* (sourceFile) {
|
|
3533
|
+
const keyBuilder = keyBuilderCache.get(sourceFile.fileName) || (yield* makeKeyBuilder(sourceFile));
|
|
3534
|
+
keyBuilderCache.set(sourceFile.fileName, keyBuilder);
|
|
3535
|
+
return keyBuilder;
|
|
3536
|
+
});
|
|
3537
|
+
function createString(sourceFile, identifier, kind) {
|
|
3538
|
+
return map4(
|
|
3539
|
+
getOrMakeKeyBuilder(sourceFile),
|
|
3540
|
+
(identifierBuilder) => identifierBuilder.createString(identifier, kind)
|
|
3541
|
+
);
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
// src/diagnostics/deterministicKeys.ts
|
|
3545
|
+
var deterministicKeys = createDiagnostic({
|
|
3546
|
+
name: "deterministicKeys",
|
|
3547
|
+
code: 25,
|
|
3548
|
+
severity: "off",
|
|
3549
|
+
apply: fn("deterministicKeys.apply")(function* (sourceFile, report) {
|
|
3550
|
+
const ts = yield* service(TypeScriptApi);
|
|
3551
|
+
const typeParser = yield* service(TypeParser);
|
|
3552
|
+
const nodeToVisit = [];
|
|
3553
|
+
const appendNodeToVisit = (node) => {
|
|
3554
|
+
nodeToVisit.push(node);
|
|
3555
|
+
return void 0;
|
|
3556
|
+
};
|
|
3557
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
3558
|
+
while (nodeToVisit.length > 0) {
|
|
3559
|
+
const node = nodeToVisit.shift();
|
|
3560
|
+
if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
3561
|
+
const result = yield* pipe(
|
|
3562
|
+
pipe(
|
|
3563
|
+
typeParser.extendsEffectService(node),
|
|
3564
|
+
orElse2(() => typeParser.extendsContextTag(node)),
|
|
3565
|
+
orElse2(() => typeParser.extendsEffectTag(node)),
|
|
3566
|
+
map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "service" }))
|
|
3567
|
+
),
|
|
3568
|
+
orElse2(
|
|
3569
|
+
() => pipe(
|
|
3570
|
+
typeParser.extendsDataTaggedError(node),
|
|
3571
|
+
orElse2(() => typeParser.extendsSchemaTaggedError(node)),
|
|
3572
|
+
map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "error" }))
|
|
3573
|
+
)
|
|
3574
|
+
),
|
|
3575
|
+
orElse2(() => void_)
|
|
3576
|
+
);
|
|
3577
|
+
if (result && result.keyStringLiteral) {
|
|
3578
|
+
const { className, keyStringLiteral } = result;
|
|
3579
|
+
const classNameText = ts.idText(className);
|
|
3580
|
+
const expectedKey = yield* createString(sourceFile, classNameText, result.target);
|
|
3581
|
+
if (!expectedKey) return;
|
|
3582
|
+
const actualIdentifier = keyStringLiteral.text;
|
|
3583
|
+
if (actualIdentifier !== expectedKey) {
|
|
3584
|
+
report({
|
|
3585
|
+
location: keyStringLiteral,
|
|
3586
|
+
messageText: `Key should be '${expectedKey}'`,
|
|
3587
|
+
fixes: [{
|
|
3588
|
+
fixName: "deterministicKeys_fix",
|
|
3589
|
+
description: `Replace '${actualIdentifier}' with '${expectedKey}'`,
|
|
3590
|
+
apply: gen(function* () {
|
|
3591
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
3592
|
+
const newStringLiteral = ts.factory.createStringLiteral(expectedKey);
|
|
3593
|
+
changeTracker.replaceNode(sourceFile, keyStringLiteral, newStringLiteral);
|
|
3594
|
+
})
|
|
3595
|
+
}]
|
|
3596
|
+
});
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
3601
|
+
}
|
|
3602
|
+
})
|
|
3603
|
+
});
|
|
3604
|
+
|
|
3465
3605
|
// src/diagnostics/duplicatePackage.ts
|
|
3466
3606
|
var checkedPackagesCache = /* @__PURE__ */ new Map();
|
|
3467
3607
|
var programResolvedCacheSize = /* @__PURE__ */ new Map();
|
|
@@ -5471,7 +5611,8 @@ var diagnostics = [
|
|
|
5471
5611
|
outdatedEffectCodegen,
|
|
5472
5612
|
overriddenSchemaConstructor,
|
|
5473
5613
|
unsupportedServiceAccessors,
|
|
5474
|
-
nonObjectEffectServiceType
|
|
5614
|
+
nonObjectEffectServiceType,
|
|
5615
|
+
deterministicKeys
|
|
5475
5616
|
];
|
|
5476
5617
|
|
|
5477
5618
|
// src/transform.ts
|