@effect/language-service 0.44.1 → 0.45.0
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 +21 -0
- package/effect-lsp-patch-utils.js +68 -5
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +94 -5
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +68 -5
- package/transform.js.map +1 -1
package/package.json
CHANGED
package/transform.js
CHANGED
|
@@ -1195,14 +1195,19 @@ var defaults = {
|
|
|
1195
1195
|
target: "service",
|
|
1196
1196
|
pattern: "default",
|
|
1197
1197
|
skipLeadingPath: ["src/"]
|
|
1198
|
-
}
|
|
1198
|
+
}, {
|
|
1199
|
+
target: "custom",
|
|
1200
|
+
pattern: "default",
|
|
1201
|
+
skipLeadingPath: ["src/"]
|
|
1202
|
+
}],
|
|
1203
|
+
extendedKeyDetection: false
|
|
1199
1204
|
};
|
|
1200
1205
|
function parseKeyPatterns(patterns) {
|
|
1201
1206
|
const result = [];
|
|
1202
1207
|
for (const entry of patterns) {
|
|
1203
1208
|
if (!isObject(entry)) continue;
|
|
1204
1209
|
result.push({
|
|
1205
|
-
target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
|
|
1210
|
+
target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error", "custom"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
|
|
1206
1211
|
pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
|
|
1207
1212
|
skipLeadingPath: hasProperty(entry, "skipLeadingPath") && isArray(entry.skipLeadingPath) && entry.skipLeadingPath.every(isString) ? entry.skipLeadingPath : ["src/"]
|
|
1208
1213
|
});
|
|
@@ -1228,7 +1233,8 @@ function parse(config) {
|
|
|
1228
1233
|
topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
|
|
1229
1234
|
renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames,
|
|
1230
1235
|
noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal,
|
|
1231
|
-
keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns
|
|
1236
|
+
keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
|
|
1237
|
+
extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection
|
|
1232
1238
|
};
|
|
1233
1239
|
}
|
|
1234
1240
|
|
|
@@ -3551,6 +3557,62 @@ var deterministicKeys = createDiagnostic({
|
|
|
3551
3557
|
apply: fn("deterministicKeys.apply")(function* (sourceFile, report) {
|
|
3552
3558
|
const ts = yield* service(TypeScriptApi);
|
|
3553
3559
|
const typeParser = yield* service(TypeParser);
|
|
3560
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3561
|
+
const typeScriptUtils = yield* service(TypeScriptUtils);
|
|
3562
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
3563
|
+
const parseExtendsCustom = cachedBy(
|
|
3564
|
+
fn("parseExtendsCustom")(function* (classDeclaration) {
|
|
3565
|
+
if (!options.extendedKeyDetection) {
|
|
3566
|
+
return yield* typeParserIssue("Extended key detection is disabled", void 0, classDeclaration);
|
|
3567
|
+
}
|
|
3568
|
+
if (!classDeclaration.name) {
|
|
3569
|
+
return yield* typeParserIssue("Class has no name", void 0, classDeclaration);
|
|
3570
|
+
}
|
|
3571
|
+
if (!ts.isIdentifier(classDeclaration.name)) {
|
|
3572
|
+
return yield* typeParserIssue("Class name is not an identifier", void 0, classDeclaration);
|
|
3573
|
+
}
|
|
3574
|
+
const heritageClauses = classDeclaration.heritageClauses;
|
|
3575
|
+
if (!heritageClauses) {
|
|
3576
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, classDeclaration);
|
|
3577
|
+
}
|
|
3578
|
+
const nodeToVisit2 = [...classDeclaration.heritageClauses];
|
|
3579
|
+
const appendNodeToVisit2 = (node) => {
|
|
3580
|
+
nodeToVisit2.push(node);
|
|
3581
|
+
return void 0;
|
|
3582
|
+
};
|
|
3583
|
+
while (nodeToVisit2.length > 0) {
|
|
3584
|
+
const node = nodeToVisit2.shift();
|
|
3585
|
+
if (ts.isCallExpression(node)) {
|
|
3586
|
+
for (let i = 0; i < node.arguments.length; i++) {
|
|
3587
|
+
const arg = node.arguments[i];
|
|
3588
|
+
if (!ts.isStringLiteral(arg)) continue;
|
|
3589
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
3590
|
+
if (resolvedSignature) {
|
|
3591
|
+
const parameter = resolvedSignature.parameters[i];
|
|
3592
|
+
if (!parameter) continue;
|
|
3593
|
+
if (parameter.declarations) {
|
|
3594
|
+
for (const declaration of parameter.declarations) {
|
|
3595
|
+
const parameterSourceFile = typeScriptUtils.getSourceFileOfNode(declaration);
|
|
3596
|
+
const paramText = parameterSourceFile.text.substring(declaration.pos, declaration.end);
|
|
3597
|
+
if (paramText.toLowerCase().includes("@effect-identifier")) {
|
|
3598
|
+
return { className: classDeclaration.name, keyStringLiteral: arg, target: "custom" };
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
ts.forEachChild(node, appendNodeToVisit2);
|
|
3606
|
+
}
|
|
3607
|
+
return yield* typeParserIssue(
|
|
3608
|
+
"Class does not extend any custom pattern",
|
|
3609
|
+
void 0,
|
|
3610
|
+
classDeclaration
|
|
3611
|
+
);
|
|
3612
|
+
}),
|
|
3613
|
+
"deterministicKeys.parseExtendsCustom",
|
|
3614
|
+
(classDeclaration) => classDeclaration
|
|
3615
|
+
);
|
|
3554
3616
|
const nodeToVisit = [];
|
|
3555
3617
|
const appendNodeToVisit = (node) => {
|
|
3556
3618
|
nodeToVisit.push(node);
|
|
@@ -3574,12 +3636,13 @@ var deterministicKeys = createDiagnostic({
|
|
|
3574
3636
|
map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "error" }))
|
|
3575
3637
|
)
|
|
3576
3638
|
),
|
|
3639
|
+
orElse2(() => parseExtendsCustom(node)),
|
|
3577
3640
|
orElse2(() => void_)
|
|
3578
3641
|
);
|
|
3579
3642
|
if (result && result.keyStringLiteral) {
|
|
3580
|
-
const { className, keyStringLiteral } = result;
|
|
3643
|
+
const { className, keyStringLiteral, target } = result;
|
|
3581
3644
|
const classNameText = ts.idText(className);
|
|
3582
|
-
const expectedKey = yield* createString(sourceFile, classNameText,
|
|
3645
|
+
const expectedKey = yield* createString(sourceFile, classNameText, target);
|
|
3583
3646
|
if (!expectedKey) continue;
|
|
3584
3647
|
const actualIdentifier = keyStringLiteral.text;
|
|
3585
3648
|
if (actualIdentifier !== expectedKey) {
|