@effect/language-service 0.47.3 → 0.48.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 +4 -0
- package/cli.js +12 -7
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +12 -7
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +78 -76
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +12 -7
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -1225,7 +1225,7 @@ function parseKeyPatterns(patterns) {
|
|
|
1225
1225
|
if (!isObject(entry)) continue;
|
|
1226
1226
|
result.push({
|
|
1227
1227
|
target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error", "custom"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
|
|
1228
|
-
pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
|
|
1228
|
+
pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default", "default-hashed"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
|
|
1229
1229
|
skipLeadingPath: hasProperty(entry, "skipLeadingPath") && isArray(entry.skipLeadingPath) && entry.skipLeadingPath.every(isString) ? entry.skipLeadingPath : ["src/"]
|
|
1230
1230
|
});
|
|
1231
1231
|
}
|
|
@@ -1811,71 +1811,6 @@ function makeTypeScriptUtils(ts) {
|
|
|
1811
1811
|
};
|
|
1812
1812
|
}
|
|
1813
1813
|
|
|
1814
|
-
// src/core/KeyBuilder.ts
|
|
1815
|
-
var makeKeyBuilder = fn("KeyBuilder")(
|
|
1816
|
-
function* (sourceFile) {
|
|
1817
|
-
const ts = yield* service(TypeScriptApi);
|
|
1818
|
-
const tsUtils = yield* service(TypeScriptUtils);
|
|
1819
|
-
const program = yield* service(TypeScriptProgram);
|
|
1820
|
-
const options = yield* service(LanguageServicePluginOptions);
|
|
1821
|
-
const packageInfo = tsUtils.resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
|
|
1822
|
-
function createString2(classNameText, kind) {
|
|
1823
|
-
if (!packageInfo) return;
|
|
1824
|
-
for (const keyPattern of options.keyPatterns) {
|
|
1825
|
-
if (keyPattern.target !== kind) continue;
|
|
1826
|
-
const lastIndex = sourceFile.fileName.lastIndexOf("/");
|
|
1827
|
-
let onlyFileName = lastIndex === -1 ? "" : sourceFile.fileName.slice(lastIndex + 1);
|
|
1828
|
-
const lastExtensionIndex = onlyFileName.lastIndexOf(".");
|
|
1829
|
-
if (lastExtensionIndex !== -1) onlyFileName = onlyFileName.slice(0, lastExtensionIndex);
|
|
1830
|
-
if (onlyFileName.toLowerCase().endsWith("/index")) onlyFileName = onlyFileName.slice(0, -6);
|
|
1831
|
-
if (onlyFileName.startsWith("/")) onlyFileName = onlyFileName.slice(1);
|
|
1832
|
-
let subDirectory = getDirectoryPath(ts, sourceFile.fileName);
|
|
1833
|
-
if (!subDirectory.startsWith(packageInfo.packageDirectory)) continue;
|
|
1834
|
-
subDirectory = subDirectory.slice(packageInfo.packageDirectory.length);
|
|
1835
|
-
if (!subDirectory.endsWith("/")) subDirectory = subDirectory + "/";
|
|
1836
|
-
if (subDirectory.startsWith("/")) subDirectory = subDirectory.slice(1);
|
|
1837
|
-
for (const prefix of keyPattern.skipLeadingPath) {
|
|
1838
|
-
if (subDirectory.startsWith(prefix)) {
|
|
1839
|
-
subDirectory = subDirectory.slice(prefix.length);
|
|
1840
|
-
break;
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
let parts = [packageInfo.name, subDirectory, onlyFileName].concat(
|
|
1844
|
-
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
1845
|
-
);
|
|
1846
|
-
if (keyPattern.pattern === "package-identifier") {
|
|
1847
|
-
parts = [packageInfo.name, onlyFileName].concat(
|
|
1848
|
-
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
1849
|
-
);
|
|
1850
|
-
}
|
|
1851
|
-
parts = parts.map((part) => part.startsWith("/") ? part.slice(1) : part).map(
|
|
1852
|
-
(part) => part.endsWith("/") ? part.slice(0, -1) : part
|
|
1853
|
-
);
|
|
1854
|
-
return parts.filter((_) => String(_).trim().length > 0).join("/");
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
return {
|
|
1858
|
-
createString: createString2
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1861
|
-
);
|
|
1862
|
-
var keyBuilderCache = /* @__PURE__ */ new Map();
|
|
1863
|
-
var getOrMakeKeyBuilder = fn("getOrMakeKeyBuilder")(function* (sourceFile) {
|
|
1864
|
-
while (keyBuilderCache.size > 5) {
|
|
1865
|
-
const oldest = keyBuilderCache.keys().next().value;
|
|
1866
|
-
if (oldest) keyBuilderCache.delete(oldest);
|
|
1867
|
-
}
|
|
1868
|
-
const keyBuilder = keyBuilderCache.get(sourceFile.fileName) || (yield* makeKeyBuilder(sourceFile));
|
|
1869
|
-
keyBuilderCache.set(sourceFile.fileName, keyBuilder);
|
|
1870
|
-
return keyBuilder;
|
|
1871
|
-
});
|
|
1872
|
-
function createString(sourceFile, identifier, kind) {
|
|
1873
|
-
return map5(
|
|
1874
|
-
getOrMakeKeyBuilder(sourceFile),
|
|
1875
|
-
(identifierBuilder) => identifierBuilder.createString(identifier, kind)
|
|
1876
|
-
);
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
1814
|
// src/core/LSP.ts
|
|
1880
1815
|
var RefactorNotApplicableError = class {
|
|
1881
1816
|
_tag = "@effect/language-service/RefactorNotApplicableError";
|
|
@@ -2207,6 +2142,72 @@ var getEffectLspPatchSourceFileMetadata = (sourceFile) => {
|
|
|
2207
2142
|
return sourceFile["@effect-lsp-patch/metadata"];
|
|
2208
2143
|
};
|
|
2209
2144
|
|
|
2145
|
+
// src/core/KeyBuilder.ts
|
|
2146
|
+
var makeKeyBuilder = fn("KeyBuilder")(
|
|
2147
|
+
function* (sourceFile) {
|
|
2148
|
+
const ts = yield* service(TypeScriptApi);
|
|
2149
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
2150
|
+
const program = yield* service(TypeScriptProgram);
|
|
2151
|
+
const options = yield* service(LanguageServicePluginOptions);
|
|
2152
|
+
const packageInfo = tsUtils.resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
|
|
2153
|
+
function createString2(classNameText, kind) {
|
|
2154
|
+
if (!packageInfo) return;
|
|
2155
|
+
for (const keyPattern of options.keyPatterns) {
|
|
2156
|
+
if (keyPattern.target !== kind) continue;
|
|
2157
|
+
const lastIndex = sourceFile.fileName.lastIndexOf("/");
|
|
2158
|
+
let onlyFileName = lastIndex === -1 ? "" : sourceFile.fileName.slice(lastIndex + 1);
|
|
2159
|
+
const lastExtensionIndex = onlyFileName.lastIndexOf(".");
|
|
2160
|
+
if (lastExtensionIndex !== -1) onlyFileName = onlyFileName.slice(0, lastExtensionIndex);
|
|
2161
|
+
if (onlyFileName.toLowerCase().endsWith("/index")) onlyFileName = onlyFileName.slice(0, -6);
|
|
2162
|
+
if (onlyFileName.startsWith("/")) onlyFileName = onlyFileName.slice(1);
|
|
2163
|
+
let subDirectory = getDirectoryPath(ts, sourceFile.fileName);
|
|
2164
|
+
if (!subDirectory.startsWith(packageInfo.packageDirectory)) continue;
|
|
2165
|
+
subDirectory = subDirectory.slice(packageInfo.packageDirectory.length);
|
|
2166
|
+
if (!subDirectory.endsWith("/")) subDirectory = subDirectory + "/";
|
|
2167
|
+
if (subDirectory.startsWith("/")) subDirectory = subDirectory.slice(1);
|
|
2168
|
+
for (const prefix of keyPattern.skipLeadingPath) {
|
|
2169
|
+
if (subDirectory.startsWith(prefix)) {
|
|
2170
|
+
subDirectory = subDirectory.slice(prefix.length);
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
let parts = [packageInfo.name, subDirectory, onlyFileName].concat(
|
|
2175
|
+
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
2176
|
+
);
|
|
2177
|
+
if (keyPattern.pattern === "package-identifier") {
|
|
2178
|
+
parts = [packageInfo.name, onlyFileName].concat(
|
|
2179
|
+
onlyFileName.toLowerCase() === classNameText.toLowerCase() ? [] : [classNameText]
|
|
2180
|
+
);
|
|
2181
|
+
}
|
|
2182
|
+
parts = parts.map((part) => part.startsWith("/") ? part.slice(1) : part).map(
|
|
2183
|
+
(part) => part.endsWith("/") ? part.slice(0, -1) : part
|
|
2184
|
+
);
|
|
2185
|
+
const fullKey = parts.filter((_) => String(_).trim().length > 0).join("/");
|
|
2186
|
+
return keyPattern.pattern === "default-hashed" ? cyrb53(fullKey) : fullKey;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return {
|
|
2190
|
+
createString: createString2
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
);
|
|
2194
|
+
var keyBuilderCache = /* @__PURE__ */ new Map();
|
|
2195
|
+
var getOrMakeKeyBuilder = fn("getOrMakeKeyBuilder")(function* (sourceFile) {
|
|
2196
|
+
while (keyBuilderCache.size > 5) {
|
|
2197
|
+
const oldest = keyBuilderCache.keys().next().value;
|
|
2198
|
+
if (oldest) keyBuilderCache.delete(oldest);
|
|
2199
|
+
}
|
|
2200
|
+
const keyBuilder = keyBuilderCache.get(sourceFile.fileName) || (yield* makeKeyBuilder(sourceFile));
|
|
2201
|
+
keyBuilderCache.set(sourceFile.fileName, keyBuilder);
|
|
2202
|
+
return keyBuilder;
|
|
2203
|
+
});
|
|
2204
|
+
function createString(sourceFile, identifier, kind) {
|
|
2205
|
+
return map5(
|
|
2206
|
+
getOrMakeKeyBuilder(sourceFile),
|
|
2207
|
+
(identifierBuilder) => identifierBuilder.createString(identifier, kind)
|
|
2208
|
+
);
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2210
2211
|
// src/completions/contextSelfInClasses.ts
|
|
2211
2212
|
var contextSelfInClasses = createCompletion({
|
|
2212
2213
|
name: "contextSelfInClasses",
|
|
@@ -2495,17 +2496,21 @@ function makeTypeCheckerUtils(ts, typeChecker, tsUtils) {
|
|
|
2495
2496
|
return result;
|
|
2496
2497
|
};
|
|
2497
2498
|
function typeToSimplifiedTypeNode(type, enclosingNode, flags) {
|
|
2499
|
+
return typeToSimplifiedTypeNodeWorker(type, enclosingNode, flags, 0);
|
|
2500
|
+
}
|
|
2501
|
+
function typeToSimplifiedTypeNodeWorker(type, enclosingNode, flags, depth) {
|
|
2498
2502
|
const fallbackStandard = () => {
|
|
2499
2503
|
const typeNode = typeChecker.typeToTypeNode(type, enclosingNode, flags);
|
|
2500
2504
|
if (!typeNode) return void 0;
|
|
2501
2505
|
return tsUtils.simplifyTypeNode(typeNode);
|
|
2502
2506
|
};
|
|
2507
|
+
if (depth > 20) return fallbackStandard();
|
|
2503
2508
|
const members = unrollUnionMembers(type);
|
|
2504
|
-
if (members.length > 1) {
|
|
2509
|
+
if (members.length > 1 && !(type.flags & ts.TypeFlags.Boolean)) {
|
|
2505
2510
|
const typeNodes = [];
|
|
2506
2511
|
members.sort(deterministicTypeOrder);
|
|
2507
2512
|
for (const member of members) {
|
|
2508
|
-
const memberNode =
|
|
2513
|
+
const memberNode = typeToSimplifiedTypeNodeWorker(member, enclosingNode, flags, depth + 1);
|
|
2509
2514
|
if (!memberNode) return fallbackStandard();
|
|
2510
2515
|
typeNodes.push(memberNode);
|
|
2511
2516
|
}
|
|
@@ -2515,7 +2520,7 @@ function makeTypeCheckerUtils(ts, typeChecker, tsUtils) {
|
|
|
2515
2520
|
const intersectionType = type;
|
|
2516
2521
|
const typeNodes = [];
|
|
2517
2522
|
for (const member of intersectionType.types) {
|
|
2518
|
-
const memberNode =
|
|
2523
|
+
const memberNode = typeToSimplifiedTypeNodeWorker(member, enclosingNode, flags, depth + 1);
|
|
2519
2524
|
if (!memberNode) return fallbackStandard();
|
|
2520
2525
|
typeNodes.push(memberNode);
|
|
2521
2526
|
}
|
|
@@ -2551,7 +2556,7 @@ function makeTypeCheckerUtils(ts, typeChecker, tsUtils) {
|
|
|
2551
2556
|
if (signatures.length !== 1) return standard2;
|
|
2552
2557
|
const returnType = typeChecker.getReturnTypeOfSignature(signatures[0]);
|
|
2553
2558
|
if (!returnType) return standard2;
|
|
2554
|
-
const returnTypeNode =
|
|
2559
|
+
const returnTypeNode = typeToSimplifiedTypeNodeWorker(returnType, enclosingNode, flags, depth + 1);
|
|
2555
2560
|
if (!returnTypeNode) return standard2;
|
|
2556
2561
|
return tsUtils.simplifyTypeNode(ts.factory.updateFunctionTypeNode(
|
|
2557
2562
|
standard2,
|
|
@@ -5769,7 +5774,7 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
5769
5774
|
while (nodeToVisit.length > 0) {
|
|
5770
5775
|
const node = nodeToVisit.shift();
|
|
5771
5776
|
ts.forEachChild(node, appendNodeToVisit);
|
|
5772
|
-
if (ts.isTryStatement(node)) {
|
|
5777
|
+
if (ts.isTryStatement(node) && node.catchClause) {
|
|
5773
5778
|
const generatorOrRegularFunction = ts.findAncestor(
|
|
5774
5779
|
node,
|
|
5775
5780
|
(_) => ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) || ts.isArrowFunction(_) || ts.isGetAccessor(_) || ts.isFunctionLike(_)
|
|
@@ -12429,11 +12434,8 @@ var layerMagic = createRefactor({
|
|
|
12429
12434
|
(node) => node
|
|
12430
12435
|
);
|
|
12431
12436
|
const adjustedNode = (node) => {
|
|
12432
|
-
if (ts.
|
|
12433
|
-
return
|
|
12434
|
-
}
|
|
12435
|
-
if (ts.isIdentifier(node) && ts.isPropertyDeclaration(node.parent) && node.parent.initializer) {
|
|
12436
|
-
return adjustedNode(node.parent.initializer);
|
|
12437
|
+
if (node.parent && (ts.isVariableDeclaration(node.parent) || ts.isPropertyDeclaration(node.parent)) && ts.isIdentifier(node) && node.parent.initializer && node.parent.name === node) {
|
|
12438
|
+
return node.parent.initializer;
|
|
12437
12439
|
}
|
|
12438
12440
|
return node;
|
|
12439
12441
|
};
|