@prisma/orm-toolchain 8.0.0-rc.13-dev.5 → 8.0.0-rc.13-dev.7
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/dist/cli-telemetry.mjs +1 -1
- package/dist/cli.mjs +3 -3
- package/dist/cli__control-api.mjs +1 -1
- package/dist/cli__migration-cli.mjs +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{exports-DKwrm64h.mjs → exports-Dc8WjBJI.mjs} +467 -274
- package/dist/exports-Dc8WjBJI.mjs.map +1 -0
- package/dist/{exports-C2kyulLb.mjs → exports-uIufkd50.mjs} +9 -2
- package/dist/exports-uIufkd50.mjs.map +1 -0
- package/dist/{ref-DZuzAvuD-BYpisYJp.mjs → ref-DZuzAvuD-RQwSwQwC.mjs} +2 -2
- package/dist/{ref-DZuzAvuD-BYpisYJp.mjs.map → ref-DZuzAvuD-RQwSwQwC.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +2 -2
- package/package.json +12 -12
- package/dist/exports-C2kyulLb.mjs.map +0 -1
- package/dist/exports-DKwrm64h.mjs.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { h as requireConfigSections, l as loadConfig, o as findNearestConfigPathForFile } from "./exports-
|
|
1
|
+
import { h as requireConfigSections, i as expandContractInputs, l as loadConfig, o as findNearestConfigPathForFile } from "./exports-uIufkd50.mjs";
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
3
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
4
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
4
5
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
@@ -42,13 +43,13 @@ const documentStartRange = {
|
|
|
42
43
|
character: 1
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
|
-
function
|
|
46
|
-
return
|
|
46
|
+
function mapInterpreterDiagnostic(diagnostic, sourceFile) {
|
|
47
|
+
return {
|
|
47
48
|
range: diagnostic.span === void 0 ? documentStartRange : sourceFile.pslSpanToRange(diagnostic.span),
|
|
48
49
|
message: diagnostic.message,
|
|
49
50
|
code: diagnostic.code,
|
|
50
51
|
severity: diagnostic.severity === "warning" ? ParseDiagnosticSeverity.Warning : ParseDiagnosticSeverity.Error
|
|
51
|
-
}
|
|
52
|
+
};
|
|
52
53
|
}
|
|
53
54
|
function locateAttributeSyntax(input) {
|
|
54
55
|
const offset = input.sourceFile.offsetAt(input.position);
|
|
@@ -1178,17 +1179,31 @@ function hasPslInputs(config) {
|
|
|
1178
1179
|
const source = config.contract?.source;
|
|
1179
1180
|
return source?.format === "psl" && source.inputs !== void 0;
|
|
1180
1181
|
}
|
|
1181
|
-
function resolveSchemaInputs(config) {
|
|
1182
|
-
const
|
|
1183
|
-
const
|
|
1182
|
+
async function resolveSchemaInputs(config, readText) {
|
|
1183
|
+
const patterns = (hasPslInputs(config) ? config.contract?.source.inputs : void 0)?.map(toExpandablePath);
|
|
1184
|
+
const expanded = await expandContractInputs(patterns);
|
|
1185
|
+
const windows = isWindowsPlatform();
|
|
1186
|
+
const candidates = expanded.map((path) => normalizeFileUri(pathToFileURL(path, { windows }).toString()));
|
|
1187
|
+
const identities = new Set(candidates.map(canonicalFileIdentity));
|
|
1188
|
+
function isMember(uri) {
|
|
1189
|
+
if (!identities.has(canonicalFileIdentity(uri))) return false;
|
|
1190
|
+
const text = readText(uri);
|
|
1191
|
+
return text !== void 0 && isPrismaNextSchema(text);
|
|
1192
|
+
}
|
|
1184
1193
|
return {
|
|
1185
|
-
includes:
|
|
1186
|
-
uris: () =>
|
|
1194
|
+
includes: isMember,
|
|
1195
|
+
uris: () => candidates.filter(isMember)
|
|
1187
1196
|
};
|
|
1188
1197
|
}
|
|
1189
|
-
function
|
|
1190
|
-
|
|
1191
|
-
|
|
1198
|
+
function toExpandablePath(input) {
|
|
1199
|
+
return isFileUri(input) ? fileURLToPath(new URL(input), { windows: isWindowsPlatform() }) : input;
|
|
1200
|
+
}
|
|
1201
|
+
function isWatcherCacheEligible(config) {
|
|
1202
|
+
const patterns = config.contract?.source.inputs;
|
|
1203
|
+
return hasPslInputs(config) && patterns !== void 0 && patterns.length > 0 && patterns.every((pattern) => /^[A-Za-z0-9_./: *?-]+$/.test(pattern) && !isFileUri(pattern) && pattern.split("/").every((segment) => !segment.includes("**") || segment === "**"));
|
|
1204
|
+
}
|
|
1205
|
+
function toWatcherGlobPattern(pattern) {
|
|
1206
|
+
return isWindowsPlatform() ? pattern.replaceAll("\\", "/") : pattern;
|
|
1192
1207
|
}
|
|
1193
1208
|
function isFileUri(input) {
|
|
1194
1209
|
try {
|
|
@@ -1213,24 +1228,30 @@ function canonicalFileIdentity(uri) {
|
|
|
1213
1228
|
return uri;
|
|
1214
1229
|
}
|
|
1215
1230
|
}
|
|
1231
|
+
function normalizeFileUri(uri) {
|
|
1232
|
+
const identity = canonicalFileIdentity(uri);
|
|
1233
|
+
return identity === uri ? uri : pathToFileURL(identity, { windows: isWindowsPlatform() }).toString();
|
|
1234
|
+
}
|
|
1216
1235
|
function isWindowsPlatform() {
|
|
1217
1236
|
return process.platform === "win32";
|
|
1218
1237
|
}
|
|
1219
1238
|
const CONFIG_FILENAME = "prisma.config.ts";
|
|
1220
|
-
const
|
|
1239
|
+
const emptyLspControlStack = {
|
|
1221
1240
|
scalarTypes: [],
|
|
1222
1241
|
pslBlockDescriptors: {}
|
|
1223
1242
|
};
|
|
1224
|
-
async function resolveConfigInputs(configPath) {
|
|
1243
|
+
async function resolveConfigInputs(configPath, readText) {
|
|
1225
1244
|
const loaded = await loadConfig(configPath);
|
|
1226
1245
|
if (!loaded.ok) throw loaded.failure;
|
|
1227
1246
|
const projectSections = requireConfigSections(loaded.value, ["contract", "formatter"]);
|
|
1228
1247
|
if (!projectSections.ok) throw projectSections.failure;
|
|
1229
1248
|
const config = projectSections.value;
|
|
1230
|
-
const inputs = resolveSchemaInputs(config);
|
|
1249
|
+
const inputs = await resolveSchemaInputs(config, readText);
|
|
1250
|
+
const schemaInputConfig = config.contract === void 0 ? {} : { contract: config.contract };
|
|
1231
1251
|
if (!hasPslInputs(config)) return {
|
|
1232
1252
|
inputs,
|
|
1233
|
-
|
|
1253
|
+
schemaInputConfig,
|
|
1254
|
+
controlStack: emptyLspControlStack,
|
|
1234
1255
|
...config.formatter === void 0 ? {} : { formatter: config.formatter }
|
|
1235
1256
|
};
|
|
1236
1257
|
const controlSections = requireConfigSections(loaded.value, [
|
|
@@ -1245,12 +1266,13 @@ async function resolveConfigInputs(configPath) {
|
|
|
1245
1266
|
const interpretation = resolveInterpretation(config, stack, inputs);
|
|
1246
1267
|
return {
|
|
1247
1268
|
inputs,
|
|
1248
|
-
|
|
1269
|
+
schemaInputConfig,
|
|
1270
|
+
controlStack: lspControlStackFromStack(stack),
|
|
1249
1271
|
...config.formatter === void 0 ? {} : { formatter: config.formatter },
|
|
1250
1272
|
...interpretation === void 0 ? {} : { interpretation }
|
|
1251
1273
|
};
|
|
1252
1274
|
}
|
|
1253
|
-
function
|
|
1275
|
+
function lspControlStackFromStack(stack) {
|
|
1254
1276
|
return {
|
|
1255
1277
|
scalarTypes: [...stack.scalarTypes],
|
|
1256
1278
|
pslBlockDescriptors: stack.authoringContributions.pslBlockDescriptors,
|
|
@@ -1275,30 +1297,123 @@ function resolveInterpretation(config, stack, inputs) {
|
|
|
1275
1297
|
}
|
|
1276
1298
|
};
|
|
1277
1299
|
}
|
|
1300
|
+
var DocumentSnapshot = class {
|
|
1301
|
+
uri;
|
|
1302
|
+
text;
|
|
1303
|
+
#parsed;
|
|
1304
|
+
constructor(uri, text) {
|
|
1305
|
+
this.uri = normalizeFileUri(uri);
|
|
1306
|
+
this.text = text;
|
|
1307
|
+
Object.freeze(this);
|
|
1308
|
+
}
|
|
1309
|
+
parse() {
|
|
1310
|
+
this.#parsed ??= parse(this.text, this.uri);
|
|
1311
|
+
return this.#parsed;
|
|
1312
|
+
}
|
|
1313
|
+
get sourceFile() {
|
|
1314
|
+
const { document, sources } = this.parse();
|
|
1315
|
+
return sources.sourceFileFor(document.syntax);
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
function statSafe(path) {
|
|
1319
|
+
try {
|
|
1320
|
+
const stats = statSync(path);
|
|
1321
|
+
return {
|
|
1322
|
+
mtime: stats.mtimeMs,
|
|
1323
|
+
size: stats.size
|
|
1324
|
+
};
|
|
1325
|
+
} catch {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
function readDiskEntry(path, uri) {
|
|
1330
|
+
const stats = statSafe(path);
|
|
1331
|
+
if (stats === void 0) return void 0;
|
|
1332
|
+
try {
|
|
1333
|
+
return {
|
|
1334
|
+
origin: "disk",
|
|
1335
|
+
snapshot: new DocumentSnapshot(uri, readFileSync(path, "utf8")),
|
|
1336
|
+
mtime: stats.mtime,
|
|
1337
|
+
size: stats.size
|
|
1338
|
+
};
|
|
1339
|
+
} catch {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1278
1343
|
var DocumentStore = class {
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1344
|
+
entries = /* @__PURE__ */ new Map();
|
|
1345
|
+
watchCoverage = /* @__PURE__ */ new Map();
|
|
1346
|
+
watchedIdentities = /* @__PURE__ */ new Set();
|
|
1347
|
+
setWatchCoverage(owner, uris) {
|
|
1348
|
+
const identities = new Set(Array.from(uris, canonicalFileIdentity));
|
|
1349
|
+
if (identities.size === 0) this.watchCoverage.delete(owner);
|
|
1350
|
+
else this.watchCoverage.set(owner, identities);
|
|
1351
|
+
const next = /* @__PURE__ */ new Set();
|
|
1352
|
+
for (const coverage of this.watchCoverage.values()) for (const identity of coverage) next.add(identity);
|
|
1353
|
+
for (const identity of this.watchedIdentities) if (!next.has(identity)) this.invalidate(identity);
|
|
1354
|
+
for (const identity of next) if (!this.watchedIdentities.has(identity)) this.invalidate(identity);
|
|
1355
|
+
this.watchedIdentities = next;
|
|
1356
|
+
}
|
|
1357
|
+
getOpenDocument = (uri) => {
|
|
1358
|
+
const entry = this.entries.get(canonicalFileIdentity(uri));
|
|
1359
|
+
return entry?.origin === "overlay" ? entry.document : void 0;
|
|
1360
|
+
};
|
|
1361
|
+
openDocuments() {
|
|
1362
|
+
const documents = [];
|
|
1363
|
+
for (const entry of this.entries.values()) if (entry.origin === "overlay") documents.push(entry.document);
|
|
1364
|
+
return documents;
|
|
1365
|
+
}
|
|
1366
|
+
text(uri) {
|
|
1367
|
+
return this.readSnapshot(uri)?.text;
|
|
1368
|
+
}
|
|
1369
|
+
readSnapshot = (uri) => {
|
|
1370
|
+
const identity = canonicalFileIdentity(uri);
|
|
1371
|
+
const entry = this.entries.get(identity);
|
|
1372
|
+
if (entry?.origin === "overlay") return entry.snapshot;
|
|
1373
|
+
if (entry?.origin === "disk") {
|
|
1374
|
+
if (this.watchedIdentities.has(identity)) return entry.snapshot;
|
|
1375
|
+
const stats = statSafe(identity);
|
|
1376
|
+
if (stats !== void 0 && stats.mtime === entry.mtime && stats.size === entry.size) return entry.snapshot;
|
|
1377
|
+
}
|
|
1378
|
+
const fresh = readDiskEntry(identity, normalizeFileUri(uri));
|
|
1379
|
+
if (fresh === void 0) {
|
|
1380
|
+
this.entries.delete(identity);
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
this.entries.set(identity, fresh);
|
|
1384
|
+
return fresh.snapshot;
|
|
1385
|
+
};
|
|
1386
|
+
invalidate(uri) {
|
|
1387
|
+
const identity = canonicalFileIdentity(uri);
|
|
1388
|
+
if (this.entries.get(identity)?.origin === "disk") this.entries.delete(identity);
|
|
1283
1389
|
}
|
|
1284
1390
|
open(item) {
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1391
|
+
const uri = normalizeFileUri(item.uri);
|
|
1392
|
+
const document = TextDocument.create(uri, item.languageId, item.version, item.text);
|
|
1393
|
+
this.entries.set(canonicalFileIdentity(item.uri), {
|
|
1394
|
+
origin: "overlay",
|
|
1395
|
+
document,
|
|
1396
|
+
snapshot: new DocumentSnapshot(uri, item.text)
|
|
1397
|
+
});
|
|
1287
1398
|
return document;
|
|
1288
1399
|
}
|
|
1289
1400
|
change(identifier, changes) {
|
|
1290
1401
|
if (changes.length === 0) return void 0;
|
|
1291
1402
|
const { uri, version } = identifier;
|
|
1292
1403
|
if (version === null || version === void 0) throw new InternalError(`Received document change event for ${uri} without valid version identifier`);
|
|
1293
|
-
const document = this.
|
|
1404
|
+
const document = this.getOpenDocument(uri);
|
|
1294
1405
|
if (document === void 0) return void 0;
|
|
1295
1406
|
const updated = TextDocument.update(document, changes, version);
|
|
1296
|
-
this.
|
|
1407
|
+
this.entries.set(canonicalFileIdentity(uri), {
|
|
1408
|
+
origin: "overlay",
|
|
1409
|
+
document: updated,
|
|
1410
|
+
snapshot: new DocumentSnapshot(updated.uri, updated.getText())
|
|
1411
|
+
});
|
|
1297
1412
|
return updated;
|
|
1298
1413
|
}
|
|
1299
1414
|
close(uri) {
|
|
1300
|
-
const document = this.
|
|
1301
|
-
this.
|
|
1415
|
+
const document = this.getOpenDocument(uri);
|
|
1416
|
+
this.entries.delete(canonicalFileIdentity(uri));
|
|
1302
1417
|
return document;
|
|
1303
1418
|
}
|
|
1304
1419
|
};
|
|
@@ -1405,152 +1520,151 @@ function whileConnected(send) {
|
|
|
1405
1520
|
function isThenable(value) {
|
|
1406
1521
|
return typeof value === "object" && value !== null && "then" in value && typeof Reflect.get(value, "then") === "function";
|
|
1407
1522
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1523
|
+
function schemaInputIdentities(inputs) {
|
|
1524
|
+
return new Set(Array.from(inputs.uris(), canonicalFileIdentity));
|
|
1525
|
+
}
|
|
1526
|
+
var ProjectArtifacts = class {
|
|
1527
|
+
#options;
|
|
1528
|
+
#readSnapshot;
|
|
1529
|
+
#interpretation;
|
|
1530
|
+
#inputs;
|
|
1531
|
+
#documents = /* @__PURE__ */ new Map();
|
|
1532
|
+
#symbolTableResult;
|
|
1533
|
+
#sources;
|
|
1534
|
+
#interpretMemo;
|
|
1535
|
+
constructor(options) {
|
|
1536
|
+
this.#options = options;
|
|
1537
|
+
this.#readSnapshot = options.readSnapshot;
|
|
1538
|
+
this.#interpretation = options.interpretation;
|
|
1539
|
+
this.#inputs = options.inputs;
|
|
1540
|
+
}
|
|
1541
|
+
get sources() {
|
|
1542
|
+
this.#sources ??= new PslSources(Array.from(this.#documents.values(), (snapshot) => [snapshot.parse().document.syntax, snapshot.sourceFile]));
|
|
1543
|
+
return this.#sources;
|
|
1544
|
+
}
|
|
1545
|
+
document = (uri) => this.#readDocument(uri);
|
|
1546
|
+
diagnostics = (uri, projectSymbolDiagnostics) => {
|
|
1547
|
+
const snapshot = this.#readDocument(uri);
|
|
1548
|
+
if (snapshot === void 0) return [];
|
|
1549
|
+
const symbolDiagnostics = (projectSymbolDiagnostics ?? this.symbolDiagnostics()).filter((diagnostic) => diagnostic.filename === snapshot.uri);
|
|
1550
|
+
return [
|
|
1551
|
+
...mapParseDiagnostics(snapshot.parse().diagnostics),
|
|
1552
|
+
...mapParseDiagnostics(symbolDiagnostics),
|
|
1553
|
+
...this.#interpretDiagnostics(snapshot.uri)
|
|
1554
|
+
];
|
|
1428
1555
|
};
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
document,
|
|
1443
|
-
sourceFile,
|
|
1444
|
-
symbolTable
|
|
1556
|
+
symbolTable = () => this.#readSymbolTable();
|
|
1557
|
+
symbolDiagnostics = () => this.#readSymbolTableResult().diagnostics;
|
|
1558
|
+
documentChanged = (uri) => this.#drop(uri);
|
|
1559
|
+
documentClosed = this.documentChanged;
|
|
1560
|
+
updateInputs = (next) => {
|
|
1561
|
+
this.#inputs = next;
|
|
1562
|
+
const validIdentities = schemaInputIdentities(next);
|
|
1563
|
+
let changed = false;
|
|
1564
|
+
for (const identity of this.#documents.keys()) if (!validIdentities.has(identity)) {
|
|
1565
|
+
this.#documents.delete(identity);
|
|
1566
|
+
changed = true;
|
|
1567
|
+
}
|
|
1568
|
+
if (changed) this.#refreshSources();
|
|
1445
1569
|
};
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
const
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
reportWarning: (diagnostic) => {
|
|
1471
|
-
warnings.push({
|
|
1472
|
-
...diagnostic,
|
|
1473
|
-
severity: "warning"
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1570
|
+
#refreshSources() {
|
|
1571
|
+
this.#sources = void 0;
|
|
1572
|
+
this.#symbolTableResult = void 0;
|
|
1573
|
+
this.#interpretMemo = void 0;
|
|
1574
|
+
}
|
|
1575
|
+
#projectInterpretDiagnostics() {
|
|
1576
|
+
if (this.#interpretation === void 0) return /* @__PURE__ */ new Map();
|
|
1577
|
+
this.#interpretMemo ??= this.#computeInterpretDistribution(this.#interpretation);
|
|
1578
|
+
return this.#interpretMemo;
|
|
1579
|
+
}
|
|
1580
|
+
#computeInterpretDistribution(activeInterpretation) {
|
|
1581
|
+
const currentSymbolTable = (this.#symbolTableResult ?? this.#readSymbolTableResult()).symbolTable;
|
|
1582
|
+
const allDocuments = Array.from(this.#documents.values(), (snapshot) => snapshot.parse().document);
|
|
1583
|
+
const warnings = [];
|
|
1584
|
+
const result = activeInterpretation.source.interpret({
|
|
1585
|
+
documents: allDocuments,
|
|
1586
|
+
sources: this.sources,
|
|
1587
|
+
symbolTable: currentSymbolTable
|
|
1588
|
+
}, {
|
|
1589
|
+
...activeInterpretation.context,
|
|
1590
|
+
reportWarning: (diagnostic) => {
|
|
1591
|
+
warnings.push({
|
|
1592
|
+
...diagnostic,
|
|
1593
|
+
severity: "warning"
|
|
1476
1594
|
});
|
|
1477
|
-
memo = mapInterpreterDiagnostics([...warnings, ...result.ok ? [] : result.failure.diagnostics].filter((diagnostic) => diagnostic.sourceId === sourceFile.filename), sourceFile);
|
|
1478
|
-
memoSources = sources;
|
|
1479
1595
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1596
|
+
});
|
|
1597
|
+
const diagnostics = [...warnings, ...result.ok ? [] : result.failure.diagnostics];
|
|
1598
|
+
if (diagnostics.length === 0) return /* @__PURE__ */ new Map();
|
|
1599
|
+
const sourceFileByFilename = /* @__PURE__ */ new Map();
|
|
1600
|
+
for (const snapshot of this.#documents.values()) sourceFileByFilename.set(snapshot.uri, snapshot.sourceFile);
|
|
1601
|
+
const bySourceId = /* @__PURE__ */ new Map();
|
|
1602
|
+
for (const diagnostic of diagnostics) {
|
|
1603
|
+
const sourceFile = sourceFileByFilename.get(diagnostic.sourceId);
|
|
1604
|
+
if (sourceFile === void 0) continue;
|
|
1605
|
+
const mapped = mapInterpreterDiagnostic(diagnostic, sourceFile);
|
|
1606
|
+
const group = bySourceId.get(diagnostic.sourceId);
|
|
1607
|
+
if (group === void 0) bySourceId.set(diagnostic.sourceId, [mapped]);
|
|
1608
|
+
else group.push(mapped);
|
|
1609
|
+
}
|
|
1610
|
+
return bySourceId;
|
|
1611
|
+
}
|
|
1612
|
+
#interpretDiagnostics(uri) {
|
|
1613
|
+
try {
|
|
1614
|
+
return this.#projectInterpretDiagnostics().get(uri) ?? [];
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
if (error instanceof ResponseError && (error.code === LSPErrorCodes.RequestCancelled || error.code === LSPErrorCodes.ServerCancelled || error.code === LSPErrorCodes.ContentModified)) throw error;
|
|
1617
|
+
this.#options.onInterpretationError(uri, error);
|
|
1618
|
+
return [{
|
|
1619
|
+
range: {
|
|
1620
|
+
start: {
|
|
1621
|
+
line: 0,
|
|
1622
|
+
character: 0
|
|
1498
1623
|
},
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1624
|
+
end: {
|
|
1625
|
+
line: 0,
|
|
1626
|
+
character: 1
|
|
1627
|
+
}
|
|
1628
|
+
},
|
|
1629
|
+
code: "PRISMA_NEXT_INTERPRETATION_FAILED",
|
|
1630
|
+
message: "Semantic diagnostics are unavailable because of an internal error. A subsequent diagnostic request or edit will retry.",
|
|
1631
|
+
severity: ParseDiagnosticSeverity.Error
|
|
1632
|
+
}];
|
|
1633
|
+
}
|
|
1505
1634
|
}
|
|
1506
|
-
|
|
1507
|
-
if (documents.delete(canonicalFileIdentity(uri))) refreshSources();
|
|
1635
|
+
#drop(uri) {
|
|
1636
|
+
if (this.#documents.delete(canonicalFileIdentity(uri))) this.#refreshSources();
|
|
1508
1637
|
}
|
|
1509
|
-
|
|
1638
|
+
#readDocument(uri) {
|
|
1510
1639
|
const identity = canonicalFileIdentity(uri);
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
};
|
|
1523
|
-
documents.set(identity, artifacts);
|
|
1524
|
-
refreshSources();
|
|
1525
|
-
return artifacts;
|
|
1640
|
+
const readSnapshot = this.#readSnapshot;
|
|
1641
|
+
const snapshot = readSnapshot(uri);
|
|
1642
|
+
if (snapshot === void 0 || !this.#inputs.includes(uri) || !isPrismaNextSchema(snapshot.text)) {
|
|
1643
|
+
if (this.#documents.delete(identity)) this.#refreshSources();
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
if (this.#documents.get(identity) !== snapshot) {
|
|
1647
|
+
this.#documents.set(identity, snapshot);
|
|
1648
|
+
this.#refreshSources();
|
|
1649
|
+
}
|
|
1650
|
+
return snapshot;
|
|
1526
1651
|
}
|
|
1527
|
-
|
|
1652
|
+
#readSymbolTableResult() {
|
|
1528
1653
|
const currentDocuments = [];
|
|
1529
|
-
for (const uri of inputs.uris()) {
|
|
1530
|
-
const
|
|
1531
|
-
if (
|
|
1654
|
+
for (const uri of this.#inputs.uris()) {
|
|
1655
|
+
const snapshot = this.#readDocument(uri);
|
|
1656
|
+
if (snapshot !== void 0) currentDocuments.push(snapshot.parse().document);
|
|
1532
1657
|
}
|
|
1533
|
-
|
|
1534
|
-
symbolTableResult ??= buildSymbolTable({
|
|
1658
|
+
this.#symbolTableResult ??= buildSymbolTable({
|
|
1535
1659
|
documents: currentDocuments,
|
|
1536
|
-
sources
|
|
1660
|
+
sources: this.sources
|
|
1537
1661
|
});
|
|
1538
|
-
return symbolTableResult;
|
|
1662
|
+
return this.#symbolTableResult;
|
|
1539
1663
|
}
|
|
1540
|
-
|
|
1541
|
-
return readSymbolTableResult().symbolTable;
|
|
1664
|
+
#readSymbolTable() {
|
|
1665
|
+
return this.#readSymbolTableResult().symbolTable;
|
|
1542
1666
|
}
|
|
1543
|
-
|
|
1544
|
-
get sources() {
|
|
1545
|
-
return sources;
|
|
1546
|
-
},
|
|
1547
|
-
document: readDocument,
|
|
1548
|
-
symbolTable: readSymbolTable,
|
|
1549
|
-
symbolDiagnostics: () => readSymbolTableResult().diagnostics,
|
|
1550
|
-
documentChanged: drop,
|
|
1551
|
-
documentClosed: drop
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1667
|
+
};
|
|
1554
1668
|
const semanticTokenTypes = [
|
|
1555
1669
|
SemanticTokenTypes.keyword,
|
|
1556
1670
|
SemanticTokenTypes.namespace,
|
|
@@ -2083,63 +2197,116 @@ function createServer(connection) {
|
|
|
2083
2197
|
}
|
|
2084
2198
|
function createServerOn(connection) {
|
|
2085
2199
|
const documents = new DocumentStore();
|
|
2086
|
-
const {
|
|
2200
|
+
const { getOpenDocument } = documents;
|
|
2087
2201
|
const managedProjects = /* @__PURE__ */ new Map();
|
|
2088
2202
|
const documentConfigPaths = /* @__PURE__ */ new Map();
|
|
2203
|
+
const publishedMembers = /* @__PURE__ */ new Map();
|
|
2204
|
+
const reportedRelatedMembers = /* @__PURE__ */ new Map();
|
|
2205
|
+
const schemaWatchRegistrations = /* @__PURE__ */ new Map();
|
|
2206
|
+
const schemaWatchGenerations = /* @__PURE__ */ new Map();
|
|
2207
|
+
const membershipGenerations = /* @__PURE__ */ new Map();
|
|
2208
|
+
let membershipGeneration = 0;
|
|
2089
2209
|
let rootPath = process.cwd();
|
|
2090
2210
|
let watchedConfigGlob = join(rootPath, "**", CONFIG_FILENAME);
|
|
2091
2211
|
let clientCapabilities = noClientCapabilities;
|
|
2092
2212
|
function sendDiagnostics(params) {
|
|
2093
|
-
connection.sendDiagnostics(
|
|
2213
|
+
connection.sendDiagnostics({
|
|
2214
|
+
...params,
|
|
2215
|
+
uri: normalizeFileUri(params.uri)
|
|
2216
|
+
});
|
|
2094
2217
|
}
|
|
2095
2218
|
function logWarn(message) {
|
|
2096
2219
|
connection.console.warn(message);
|
|
2097
2220
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
return;
|
|
2105
|
-
}
|
|
2106
|
-
const artifacts = project.artifacts.document(uri);
|
|
2107
|
-
if (artifacts === void 0) {
|
|
2221
|
+
function publishProjectMembers(project) {
|
|
2222
|
+
if (clientCapabilities.pullDiagnostics) return;
|
|
2223
|
+
const nextLedger = /* @__PURE__ */ new Set();
|
|
2224
|
+
const projectSymbolDiagnostics = project.artifacts.symbolDiagnostics();
|
|
2225
|
+
for (const candidateUri of project.inputs.uris()) {
|
|
2226
|
+
const uri = normalizeFileUri(candidateUri);
|
|
2108
2227
|
sendDiagnostics({
|
|
2109
|
-
uri
|
|
2228
|
+
uri,
|
|
2229
|
+
diagnostics: toDiagnostics(project.artifacts.diagnostics(uri, projectSymbolDiagnostics))
|
|
2230
|
+
});
|
|
2231
|
+
nextLedger.add(uri);
|
|
2232
|
+
}
|
|
2233
|
+
const previousLedger = publishedMembers.get(project.configPath);
|
|
2234
|
+
if (previousLedger !== void 0) {
|
|
2235
|
+
for (const uri of previousLedger) if (!nextLedger.has(uri)) sendDiagnostics({
|
|
2236
|
+
uri,
|
|
2110
2237
|
diagnostics: []
|
|
2111
2238
|
});
|
|
2112
|
-
return;
|
|
2113
2239
|
}
|
|
2114
|
-
|
|
2115
|
-
uri: document.uri,
|
|
2116
|
-
diagnostics: combinedDiagnostics(project.artifacts, artifacts)
|
|
2117
|
-
});
|
|
2118
|
-
}
|
|
2119
|
-
function combinedDiagnostics(project, artifacts) {
|
|
2120
|
-
const symbolDiagnostics = project.symbolDiagnostics().filter((diagnostic) => diagnostic.filename === artifacts.sourceFile.filename);
|
|
2121
|
-
return toDiagnostics([
|
|
2122
|
-
...artifacts.diagnostics,
|
|
2123
|
-
...mapParseDiagnostics(symbolDiagnostics),
|
|
2124
|
-
...artifacts.interpretDiagnostics()
|
|
2125
|
-
]);
|
|
2240
|
+
publishedMembers.set(project.configPath, nextLedger);
|
|
2126
2241
|
}
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2242
|
+
function clearPublishedMembers(configPath) {
|
|
2243
|
+
const ledger = publishedMembers.get(configPath);
|
|
2244
|
+
if (ledger === void 0) return;
|
|
2245
|
+
for (const uri of ledger) sendDiagnostics({
|
|
2246
|
+
uri,
|
|
2247
|
+
diagnostics: []
|
|
2248
|
+
});
|
|
2249
|
+
publishedMembers.delete(configPath);
|
|
2250
|
+
}
|
|
2251
|
+
function clearSchemaWatcher(configPath) {
|
|
2252
|
+
const generation = (schemaWatchGenerations.get(configPath) ?? 0) + 1;
|
|
2253
|
+
schemaWatchGenerations.set(configPath, generation);
|
|
2254
|
+
documents.setWatchCoverage(configPath, []);
|
|
2255
|
+
schemaWatchRegistrations.get(configPath)?.disposable.dispose();
|
|
2256
|
+
schemaWatchRegistrations.delete(configPath);
|
|
2257
|
+
return generation;
|
|
2258
|
+
}
|
|
2259
|
+
async function registerSchemaWatcher(project) {
|
|
2260
|
+
const configPath = project.configPath;
|
|
2261
|
+
const generation = clearSchemaWatcher(configPath);
|
|
2262
|
+
if (!clientCapabilities.watchedFilesRegistration) return;
|
|
2263
|
+
const patterns = project.schemaInputConfig.contract?.source.inputs ?? [];
|
|
2264
|
+
if (patterns.length === 0) return;
|
|
2265
|
+
try {
|
|
2266
|
+
const disposable = await connection.client.register(DidChangeWatchedFilesNotification.type, { watchers: patterns.map((pattern) => ({ globPattern: toWatcherGlobPattern(pattern) })) });
|
|
2267
|
+
if (disposable === void 0) return;
|
|
2268
|
+
if (schemaWatchGenerations.get(configPath) === generation) {
|
|
2269
|
+
schemaWatchRegistrations.set(configPath, {
|
|
2270
|
+
disposable,
|
|
2271
|
+
schemaInputConfig: project.schemaInputConfig
|
|
2272
|
+
});
|
|
2273
|
+
const current = currentProjectState(configPath);
|
|
2274
|
+
if (current?.schemaInputConfig === project.schemaInputConfig && isWatcherCacheEligible(project.schemaInputConfig)) documents.setWatchCoverage(configPath, current.inputs.uris());
|
|
2275
|
+
} else disposable.dispose();
|
|
2276
|
+
} catch {}
|
|
2277
|
+
}
|
|
2278
|
+
function onProjectLoaded(project) {
|
|
2279
|
+
registerSchemaWatcher(project);
|
|
2280
|
+
}
|
|
2281
|
+
function buildDocumentDiagnosticReport(project, requestedUri) {
|
|
2282
|
+
const uri = normalizeFileUri(requestedUri);
|
|
2283
|
+
const projectSymbolDiagnostics = project.artifacts.symbolDiagnostics();
|
|
2284
|
+
const reportFor = (memberUri) => ({
|
|
2134
2285
|
kind: DocumentDiagnosticReportKind.Full,
|
|
2135
|
-
items:
|
|
2286
|
+
items: toDiagnostics(project.artifacts.diagnostics(memberUri, projectSymbolDiagnostics))
|
|
2287
|
+
});
|
|
2288
|
+
const members = new Set(Array.from(project.inputs.uris(), normalizeFileUri));
|
|
2289
|
+
const previous = reportedRelatedMembers.get(project.configPath) ?? /* @__PURE__ */ new Set();
|
|
2290
|
+
const relatedDocuments = {};
|
|
2291
|
+
for (const memberUri of /* @__PURE__ */ new Set([...members, ...previous])) {
|
|
2292
|
+
if (memberUri === uri) continue;
|
|
2293
|
+
relatedDocuments[memberUri] = members.has(memberUri) ? reportFor(memberUri) : {
|
|
2294
|
+
kind: DocumentDiagnosticReportKind.Full,
|
|
2295
|
+
items: []
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
const report = reportFor(uri);
|
|
2299
|
+
if (previous.has(uri)) members.add(uri);
|
|
2300
|
+
reportedRelatedMembers.set(project.configPath, members);
|
|
2301
|
+
return {
|
|
2302
|
+
...report,
|
|
2303
|
+
...Object.keys(relatedDocuments).length > 0 ? { relatedDocuments } : {}
|
|
2136
2304
|
};
|
|
2137
2305
|
}
|
|
2138
2306
|
async function resolveProjectForDocument(uri) {
|
|
2139
2307
|
const project = await projectForNearestConfig(uri);
|
|
2140
2308
|
if (project === void 0 || project.inputs.includes(uri)) return project;
|
|
2141
2309
|
documentConfigPaths.delete(canonicalFileIdentity(uri));
|
|
2142
|
-
dropProjectWithoutManagedDocuments(project.configPath);
|
|
2143
2310
|
}
|
|
2144
2311
|
async function projectForNearestConfig(uri) {
|
|
2145
2312
|
const knownConfigPath = documentConfigPaths.get(canonicalFileIdentity(uri));
|
|
@@ -2172,34 +2339,36 @@ function createServerOn(connection) {
|
|
|
2172
2339
|
return startProjectLoad(configPath);
|
|
2173
2340
|
}
|
|
2174
2341
|
function startProjectLoad(configPath) {
|
|
2342
|
+
membershipGenerations.set(configPath, ++membershipGeneration);
|
|
2343
|
+
clearSchemaWatcher(configPath);
|
|
2175
2344
|
const existing = managedProjects.get(configPath);
|
|
2176
2345
|
const previousLoad = existing?.status === "loading" ? existing.load : void 0;
|
|
2177
2346
|
const lastGood = lastGoodProject(existing);
|
|
2178
2347
|
const load = (previousLoad ?? Promise.resolve(void 0)).catch(() => void 0).then(() => loadProject(configPath)).then((project) => {
|
|
2179
2348
|
if (isCurrentLoad(configPath, load)) {
|
|
2180
|
-
|
|
2349
|
+
managedProjects.set(configPath, {
|
|
2181
2350
|
status: "loaded",
|
|
2182
2351
|
project
|
|
2183
2352
|
});
|
|
2184
|
-
else managedProjects.delete(configPath);
|
|
2185
2353
|
clearConfigFailure(configPath);
|
|
2354
|
+
onProjectLoaded(project);
|
|
2186
2355
|
}
|
|
2187
2356
|
return project;
|
|
2188
2357
|
}, (error) => {
|
|
2189
|
-
if (isCurrentLoad(configPath, load))
|
|
2190
|
-
managedProjects.delete(configPath);
|
|
2191
|
-
clearConfigFailure(configPath);
|
|
2192
|
-
} else {
|
|
2358
|
+
if (isCurrentLoad(configPath, load)) {
|
|
2193
2359
|
publishConfigFailure(configPath, error);
|
|
2194
2360
|
if (lastGood !== void 0) {
|
|
2195
2361
|
managedProjects.set(configPath, {
|
|
2196
2362
|
status: "loaded",
|
|
2197
2363
|
project: lastGood
|
|
2198
2364
|
});
|
|
2365
|
+
onProjectLoaded(lastGood);
|
|
2199
2366
|
return lastGood;
|
|
2200
2367
|
}
|
|
2201
2368
|
managedProjects.set(configPath, { status: "failed" });
|
|
2202
2369
|
unmanageDocuments(configPath);
|
|
2370
|
+
clearSchemaWatcher(configPath);
|
|
2371
|
+
clearPublishedMembers(configPath);
|
|
2203
2372
|
}
|
|
2204
2373
|
throw error;
|
|
2205
2374
|
});
|
|
@@ -2246,10 +2415,11 @@ function createServerOn(connection) {
|
|
|
2246
2415
|
return entry?.status === "loading" && entry.load === load;
|
|
2247
2416
|
}
|
|
2248
2417
|
async function loadProject(configPath) {
|
|
2249
|
-
const
|
|
2250
|
-
const
|
|
2418
|
+
const readText = (uri) => documents.text(uri);
|
|
2419
|
+
const resolution = await resolveConfigInputs(configPath, readText);
|
|
2420
|
+
const artifacts = new ProjectArtifacts({
|
|
2251
2421
|
inputs: resolution.inputs,
|
|
2252
|
-
|
|
2422
|
+
readSnapshot: documents.readSnapshot,
|
|
2253
2423
|
onInterpretationError: (uri, error) => {
|
|
2254
2424
|
const detail = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
2255
2425
|
connection.console.error(`PSL interpretation failed for ${uri}: ${detail}`);
|
|
@@ -2259,6 +2429,7 @@ function createServerOn(connection) {
|
|
|
2259
2429
|
return {
|
|
2260
2430
|
configPath,
|
|
2261
2431
|
inputs: resolution.inputs,
|
|
2432
|
+
schemaInputConfig: resolution.schemaInputConfig,
|
|
2262
2433
|
controlStack: resolution.controlStack,
|
|
2263
2434
|
artifacts,
|
|
2264
2435
|
...resolution.formatter === void 0 ? {} : { formatter: resolution.formatter },
|
|
@@ -2266,36 +2437,20 @@ function createServerOn(connection) {
|
|
|
2266
2437
|
};
|
|
2267
2438
|
}
|
|
2268
2439
|
function unmanageDocuments(configPath) {
|
|
2269
|
-
for (const document of documents.
|
|
2270
|
-
}
|
|
2271
|
-
async function republishOpenDocumentsForConfig(configPath) {
|
|
2272
|
-
for (const document of documents.all()) {
|
|
2273
|
-
if (documentConfigPaths.get(canonicalFileIdentity(document.uri)) === configPath) {
|
|
2274
|
-
if (await resolveProjectForDocument(document.uri) === void 0) {
|
|
2275
|
-
sendDiagnostics({
|
|
2276
|
-
uri: document.uri,
|
|
2277
|
-
diagnostics: []
|
|
2278
|
-
});
|
|
2279
|
-
continue;
|
|
2280
|
-
}
|
|
2281
|
-
await publish(document.uri);
|
|
2282
|
-
continue;
|
|
2283
|
-
}
|
|
2284
|
-
const filePath = filePathFromUri(document.uri);
|
|
2285
|
-
if (filePath === void 0) continue;
|
|
2286
|
-
if (await findNearestConfigPathForFile(filePath) === configPath) {
|
|
2287
|
-
documentConfigPaths.set(canonicalFileIdentity(document.uri), configPath);
|
|
2288
|
-
await publish(document.uri);
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2440
|
+
for (const document of documents.openDocuments()) if (documentConfigPaths.get(canonicalFileIdentity(document.uri)) === configPath) documentConfigPaths.delete(canonicalFileIdentity(document.uri));
|
|
2291
2441
|
}
|
|
2292
|
-
function
|
|
2293
|
-
|
|
2442
|
+
async function publishForDocument(uri) {
|
|
2443
|
+
const project = await resolveProjectForDocument(uri);
|
|
2444
|
+
if (project === void 0) return;
|
|
2445
|
+
publishProjectMembers(project);
|
|
2446
|
+
}
|
|
2447
|
+
function publishForDocumentSafely(uri) {
|
|
2448
|
+
publishForDocument(uri).catch((error) => {
|
|
2294
2449
|
connection.console.error(error instanceof Error ? error.message : String(error));
|
|
2295
2450
|
});
|
|
2296
2451
|
}
|
|
2297
2452
|
async function formatDocument(uri) {
|
|
2298
|
-
const document =
|
|
2453
|
+
const document = getOpenDocument(uri);
|
|
2299
2454
|
if (document === void 0) return [];
|
|
2300
2455
|
const source = document.getText();
|
|
2301
2456
|
if (!isPrismaNextSchema(source)) return [];
|
|
@@ -2320,7 +2475,7 @@ function createServerOn(connection) {
|
|
|
2320
2475
|
}];
|
|
2321
2476
|
}
|
|
2322
2477
|
async function semanticTokensForDocument(uri, range) {
|
|
2323
|
-
const document =
|
|
2478
|
+
const document = getOpenDocument(uri);
|
|
2324
2479
|
if (document === void 0) return emptySemanticTokens();
|
|
2325
2480
|
if (document.getText().length > semanticTokenSourceLimit) return emptySemanticTokens();
|
|
2326
2481
|
const project = await resolveProjectForDocument(uri);
|
|
@@ -2328,14 +2483,14 @@ function createServerOn(connection) {
|
|
|
2328
2483
|
const artifacts = project.artifacts.document(uri);
|
|
2329
2484
|
if (artifacts === void 0) return emptySemanticTokens();
|
|
2330
2485
|
return buildSemanticTokens({
|
|
2331
|
-
document: artifacts.document,
|
|
2486
|
+
document: artifacts.parse().document,
|
|
2332
2487
|
sourceFile: artifacts.sourceFile,
|
|
2333
2488
|
symbolTable: project.artifacts.symbolTable(),
|
|
2334
2489
|
scalarTypes: project.controlStack.scalarTypes
|
|
2335
2490
|
}, range);
|
|
2336
2491
|
}
|
|
2337
2492
|
async function completeDocument(uri, position) {
|
|
2338
|
-
if (
|
|
2493
|
+
if (getOpenDocument(uri) === void 0) return [];
|
|
2339
2494
|
const project = await resolveProjectForDocument(uri);
|
|
2340
2495
|
if (project === void 0) return [];
|
|
2341
2496
|
const artifacts = project.artifacts.document(uri);
|
|
@@ -2343,7 +2498,7 @@ function createServerOn(connection) {
|
|
|
2343
2498
|
try {
|
|
2344
2499
|
return [...providePslCompletionItems({
|
|
2345
2500
|
context: classifyPslCompletionContext({
|
|
2346
|
-
document: artifacts.document,
|
|
2501
|
+
document: artifacts.parse().document,
|
|
2347
2502
|
sourceFile: artifacts.sourceFile,
|
|
2348
2503
|
position
|
|
2349
2504
|
}),
|
|
@@ -2364,7 +2519,7 @@ function createServerOn(connection) {
|
|
|
2364
2519
|
}
|
|
2365
2520
|
}
|
|
2366
2521
|
async function signatureHelpForDocument(uri, position) {
|
|
2367
|
-
if (
|
|
2522
|
+
if (getOpenDocument(uri) === void 0) return null;
|
|
2368
2523
|
const project = await resolveProjectForDocument(uri);
|
|
2369
2524
|
if (project === void 0) return null;
|
|
2370
2525
|
const artifacts = project.artifacts.document(uri);
|
|
@@ -2372,7 +2527,7 @@ function createServerOn(connection) {
|
|
|
2372
2527
|
try {
|
|
2373
2528
|
return providePslSignatureHelp({
|
|
2374
2529
|
clientSupportsLabelOffsets: clientCapabilities.signatureLabelOffsets,
|
|
2375
|
-
document: artifacts.document,
|
|
2530
|
+
document: artifacts.parse().document,
|
|
2376
2531
|
sourceFile: artifacts.sourceFile,
|
|
2377
2532
|
position,
|
|
2378
2533
|
candidates: {
|
|
@@ -2413,7 +2568,7 @@ function createServerOn(connection) {
|
|
|
2413
2568
|
] },
|
|
2414
2569
|
signatureHelpProvider: { triggerCharacters: ["(", ","] },
|
|
2415
2570
|
...clientCapabilities.pullDiagnostics ? { diagnosticProvider: {
|
|
2416
|
-
interFileDependencies:
|
|
2571
|
+
interFileDependencies: true,
|
|
2417
2572
|
workspaceDiagnostics: false
|
|
2418
2573
|
} } : {}
|
|
2419
2574
|
} };
|
|
@@ -2426,17 +2581,57 @@ function createServerOn(connection) {
|
|
|
2426
2581
|
}] });
|
|
2427
2582
|
else logWarn("Client does not support dynamic file-watcher registration; Prisma 8 config changes will not be picked up without a restart.");
|
|
2428
2583
|
});
|
|
2584
|
+
async function handleSchemaMemberChange(uri) {
|
|
2585
|
+
const generation = ++membershipGeneration;
|
|
2586
|
+
documents.invalidate(uri);
|
|
2587
|
+
const filePath = filePathFromUri(uri);
|
|
2588
|
+
if (filePath === void 0) return false;
|
|
2589
|
+
let configPath;
|
|
2590
|
+
try {
|
|
2591
|
+
configPath = await findNearestConfigPathForFile(filePath);
|
|
2592
|
+
} catch {
|
|
2593
|
+
return false;
|
|
2594
|
+
}
|
|
2595
|
+
if (configPath === void 0) return false;
|
|
2596
|
+
const entry = managedProjects.get(configPath);
|
|
2597
|
+
if (entry === void 0 || entry.status === "failed" || (membershipGenerations.get(configPath) ?? 0) > generation) return false;
|
|
2598
|
+
membershipGenerations.set(configPath, generation);
|
|
2599
|
+
currentProjectState(configPath)?.artifacts.documentChanged(uri);
|
|
2600
|
+
const project = entry.status === "loaded" ? entry.project : await entry.load.catch(() => void 0);
|
|
2601
|
+
const isCurrent = () => {
|
|
2602
|
+
const current = managedProjects.get(configPath);
|
|
2603
|
+
return current?.status === "loaded" && current.project === project && membershipGenerations.get(configPath) === generation;
|
|
2604
|
+
};
|
|
2605
|
+
if (project === void 0 || !isCurrent()) return false;
|
|
2606
|
+
const readText = (candidate) => documents.text(candidate);
|
|
2607
|
+
const nextInputs = await resolveSchemaInputs(project.schemaInputConfig, readText);
|
|
2608
|
+
if (!isCurrent()) return false;
|
|
2609
|
+
project.artifacts.updateInputs(nextInputs);
|
|
2610
|
+
const updated = {
|
|
2611
|
+
...project,
|
|
2612
|
+
inputs: nextInputs
|
|
2613
|
+
};
|
|
2614
|
+
managedProjects.set(configPath, {
|
|
2615
|
+
status: "loaded",
|
|
2616
|
+
project: updated
|
|
2617
|
+
});
|
|
2618
|
+
if (schemaWatchRegistrations.get(configPath)?.schemaInputConfig === project.schemaInputConfig && isWatcherCacheEligible(project.schemaInputConfig)) documents.setWatchCoverage(configPath, nextInputs.uris());
|
|
2619
|
+
publishProjectMembers(updated);
|
|
2620
|
+
return true;
|
|
2621
|
+
}
|
|
2429
2622
|
connection.onDidChangeWatchedFiles(async (params) => {
|
|
2430
|
-
const
|
|
2431
|
-
|
|
2623
|
+
const configChanges = [];
|
|
2624
|
+
const memberChanges = [];
|
|
2625
|
+
for (const change of params.changes) (filePathFromUri(change.uri)?.endsWith("prisma.config.ts") ? configChanges : memberChanges).push(change.uri);
|
|
2626
|
+
const changedConfigPaths = configPathsFromWatchedChanges(configChanges.map(filePathFromUri));
|
|
2627
|
+
const configRefreshes = Array.from(changedConfigPaths, async (configPath) => {
|
|
2432
2628
|
if (managedProjects.has(configPath)) try {
|
|
2433
|
-
await refreshProject(configPath);
|
|
2434
|
-
} catch {
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
if (clientCapabilities.pullDiagnostics && clientCapabilities.diagnosticsRefresh && changedConfigPaths.size > 0) connection.languages.diagnostics.refresh();
|
|
2629
|
+
publishProjectMembers(await refreshProject(configPath));
|
|
2630
|
+
} catch {}
|
|
2631
|
+
});
|
|
2632
|
+
const [, memberResults] = await Promise.all([Promise.all(configRefreshes), Promise.all(memberChanges.map(handleSchemaMemberChange))]);
|
|
2633
|
+
const handledMemberChange = memberResults.some(Boolean);
|
|
2634
|
+
if (clientCapabilities.pullDiagnostics && clientCapabilities.diagnosticsRefresh && (changedConfigPaths.size > 0 || handledMemberChange)) connection.languages.diagnostics.refresh();
|
|
2440
2635
|
});
|
|
2441
2636
|
connection.onDocumentFormatting((params) => formatDocument(params.textDocument.uri));
|
|
2442
2637
|
connection.onCompletion((params) => completeDocument(params.textDocument.uri, params.position));
|
|
@@ -2444,32 +2639,31 @@ function createServerOn(connection) {
|
|
|
2444
2639
|
connection.languages.semanticTokens.on((params) => semanticTokensForDocument(params.textDocument.uri));
|
|
2445
2640
|
connection.languages.semanticTokens.onRange((params) => semanticTokensForDocument(params.textDocument.uri, params.range));
|
|
2446
2641
|
connection.languages.diagnostics.on(async (params) => {
|
|
2447
|
-
|
|
2448
|
-
|
|
2642
|
+
if (!clientCapabilities.pullDiagnostics) return {
|
|
2643
|
+
kind: DocumentDiagnosticReportKind.Full,
|
|
2644
|
+
items: []
|
|
2645
|
+
};
|
|
2646
|
+
const uri = normalizeFileUri(params.textDocument.uri);
|
|
2647
|
+
const project = await projectForNearestConfig(uri);
|
|
2648
|
+
if (project === void 0 || !project.inputs.includes(uri) && !reportedRelatedMembers.get(project.configPath)?.has(uri)) return {
|
|
2449
2649
|
kind: DocumentDiagnosticReportKind.Full,
|
|
2450
2650
|
items: []
|
|
2451
2651
|
};
|
|
2452
|
-
return buildDocumentDiagnosticReport(project,
|
|
2652
|
+
return buildDocumentDiagnosticReport(project, uri);
|
|
2453
2653
|
});
|
|
2454
2654
|
connection.onFoldingRanges(async (params) => {
|
|
2455
2655
|
const project = await resolveProjectForDocument(params.textDocument.uri);
|
|
2456
2656
|
if (project === void 0) return [];
|
|
2457
2657
|
const artifacts = project.artifacts.document(params.textDocument.uri);
|
|
2458
2658
|
if (artifacts === void 0) return [];
|
|
2459
|
-
return computeFoldingRanges(artifacts.document, project.artifacts.sources);
|
|
2659
|
+
return computeFoldingRanges(artifacts.parse().document, project.artifacts.sources);
|
|
2460
2660
|
});
|
|
2461
2661
|
function documentChanged(uri) {
|
|
2462
2662
|
artifactsForDocument(uri)?.documentChanged(uri);
|
|
2463
|
-
|
|
2663
|
+
publishForDocumentSafely(uri);
|
|
2464
2664
|
}
|
|
2465
2665
|
connection.onDidOpenTextDocument((event) => {
|
|
2466
|
-
|
|
2467
|
-
const document = documents.open(event.textDocument);
|
|
2468
|
-
if (previous !== void 0 && previous.uri !== document.uri && !clientCapabilities.pullDiagnostics) sendDiagnostics({
|
|
2469
|
-
uri: previous.uri,
|
|
2470
|
-
diagnostics: []
|
|
2471
|
-
});
|
|
2472
|
-
documentChanged(document.uri);
|
|
2666
|
+
documentChanged(documents.open(event.textDocument).uri);
|
|
2473
2667
|
});
|
|
2474
2668
|
connection.onDidChangeTextDocument((event) => {
|
|
2475
2669
|
const document = documents.change(event.textDocument, event.contentChanges);
|
|
@@ -2482,12 +2676,22 @@ function createServerOn(connection) {
|
|
|
2482
2676
|
const configPath = documentConfigPaths.get(canonicalFileIdentity(uri));
|
|
2483
2677
|
artifactsForDocument(uri)?.documentClosed(uri);
|
|
2484
2678
|
documentConfigPaths.delete(canonicalFileIdentity(uri));
|
|
2485
|
-
|
|
2486
|
-
if (
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2679
|
+
const project = currentProjectState(configPath);
|
|
2680
|
+
if (project === void 0) {
|
|
2681
|
+
if (!clientCapabilities.pullDiagnostics) sendDiagnostics({
|
|
2682
|
+
uri,
|
|
2683
|
+
diagnostics: []
|
|
2684
|
+
});
|
|
2685
|
+
return;
|
|
2686
|
+
}
|
|
2687
|
+
publishProjectMembers(project);
|
|
2490
2688
|
});
|
|
2689
|
+
function currentProjectState(configPath) {
|
|
2690
|
+
if (configPath === void 0) return;
|
|
2691
|
+
const entry = managedProjects.get(configPath);
|
|
2692
|
+
if (entry === void 0 || entry.status === "failed") return;
|
|
2693
|
+
return entry.status === "loaded" ? entry.project : entry.lastGood;
|
|
2694
|
+
}
|
|
2491
2695
|
connection.listen();
|
|
2492
2696
|
function artifactsForDocument(uri) {
|
|
2493
2697
|
const configPath = documentConfigPaths.get(canonicalFileIdentity(uri));
|
|
@@ -2496,17 +2700,6 @@ function createServerOn(connection) {
|
|
|
2496
2700
|
if (entry?.status === "loaded") return entry.project.artifacts;
|
|
2497
2701
|
return entry?.status === "loading" ? entry.lastGood?.artifacts : void 0;
|
|
2498
2702
|
}
|
|
2499
|
-
function hasManagedDocuments(configPath) {
|
|
2500
|
-
for (const managedConfigPath of documentConfigPaths.values()) if (managedConfigPath === configPath) return true;
|
|
2501
|
-
return false;
|
|
2502
|
-
}
|
|
2503
|
-
function dropProjectWithoutManagedDocuments(configPath) {
|
|
2504
|
-
if (hasManagedDocuments(configPath)) return;
|
|
2505
|
-
const entry = managedProjects.get(configPath);
|
|
2506
|
-
if (entry === void 0 || entry.status === "loading") return;
|
|
2507
|
-
managedProjects.delete(configPath);
|
|
2508
|
-
clearConfigFailure(configPath);
|
|
2509
|
-
}
|
|
2510
2703
|
return {
|
|
2511
2704
|
dispose: () => connection.dispose(),
|
|
2512
2705
|
getDocumentAst: (uri) => artifactsForDocument(uri)?.document(uri),
|
|
@@ -2553,7 +2746,7 @@ function resolveClientCapabilities(params) {
|
|
|
2553
2746
|
signatureLabelOffsets: params.capabilities.textDocument?.signatureHelp?.signatureInformation?.parameterInformation?.labelOffsetSupport === true,
|
|
2554
2747
|
completionTriggerSuggestCommand: supportsCompletionCommand(params.initializationOptions, "supportsTriggerSuggestCommand"),
|
|
2555
2748
|
completionTriggerParameterHintsCommand: supportsCompletionCommand(params.initializationOptions, "supportsTriggerParameterHintsCommand"),
|
|
2556
|
-
pullDiagnostics: params.capabilities.textDocument?.diagnostic
|
|
2749
|
+
pullDiagnostics: params.capabilities.textDocument?.diagnostic?.relatedDocumentSupport === true,
|
|
2557
2750
|
diagnosticsRefresh: params.capabilities.workspace?.diagnostics?.refreshSupport === true
|
|
2558
2751
|
};
|
|
2559
2752
|
}
|
|
@@ -2825,4 +3018,4 @@ function startServer(streams) {
|
|
|
2825
3018
|
//#endregion
|
|
2826
3019
|
export { startServer };
|
|
2827
3020
|
|
|
2828
|
-
//# sourceMappingURL=exports-
|
|
3021
|
+
//# sourceMappingURL=exports-Dc8WjBJI.mjs.map
|