@prisma/orm-toolchain 8.0.0-rc.11-dev.33 → 8.0.0-rc.11-dev.35

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.
@@ -1,2 +1,2 @@
1
- import { $ as listRefsByContractHash, B as executeContractEmit, Ct as resolveFromForPlan, Dt as runContractSpaceSeedPhase, G as executeMigrationNewCommand, H as executeDbUpdate, J as executeRefDeleteCommand, K as executeMigrationPlanCommand, Ot as runMigrationCheck, Q as hasMigrationPath, St as resolveContractRefToSnapshot, Tt as resolveToForPlan, U as executeDbVerify, V as executeDbInit, W as executeMigrateShowPlan, X as executeRefSetCommand, Y as executeRefListCommand, _ as enrichContract, _t as refusePackageCorruptionOnAggregate, a as appliedHashesFromLedger, at as mapContractAtError, c as buildReadAggregate, ct as migrationSpaceListEntriesFromAggregate, et as loadAggregateIntegrityViolations, ft as readMigrationRefs, g as disposeEmitQueue, gt as refuseMissingInvariantPath, h as deriveStatusEdgeAnnotations, ht as refuseMarkerOutsideGraph, i as appContractStandInFromIdentity, it as mapCaughtMigrationError, jt as statusForMigrationHash, kt as runMigrationList, l as buildRefAdvancementFields, lt as originHashForStatus, m as createControlClient, mt as refuseDeclaredExtensionTargetMismatch, n as NO_REF_ADVANCEMENT, nt as loadContractSpaceAggregateForCli, o as buildContractSpaceAggregate, ot as mapIntegrityViolations, p as computeRefAdvancementName, pt as refuseContractSpaceIntegrity, q as executeRefAdvancement, r as advanceRefSafely, s as buildMigrationSpaceGraphEntries, tt as loadContractRawSafely, u as checkSingleTarget, ut as preflightRefAdvancement, v as enumerateCheckSpaces, vt as refuseUnknownInvariants, wt as resolveMigrationRef, xt as resolveContractRef$1 } from "./ref-fSTPpdt3-DTb2_ACs.mjs";
1
+ import { $ as listRefsByContractHash, B as executeContractEmit, Ct as resolveFromForPlan, Dt as runContractSpaceSeedPhase, G as executeMigrationNewCommand, H as executeDbUpdate, J as executeRefDeleteCommand, K as executeMigrationPlanCommand, Ot as runMigrationCheck, Q as hasMigrationPath, St as resolveContractRefToSnapshot, Tt as resolveToForPlan, U as executeDbVerify, V as executeDbInit, W as executeMigrateShowPlan, X as executeRefSetCommand, Y as executeRefListCommand, _ as enrichContract, _t as refusePackageCorruptionOnAggregate, a as appliedHashesFromLedger, at as mapContractAtError, c as buildReadAggregate, ct as migrationSpaceListEntriesFromAggregate, et as loadAggregateIntegrityViolations, ft as readMigrationRefs, g as disposeEmitQueue, gt as refuseMissingInvariantPath, h as deriveStatusEdgeAnnotations, ht as refuseMarkerOutsideGraph, i as appContractStandInFromIdentity, it as mapCaughtMigrationError, jt as statusForMigrationHash, kt as runMigrationList, l as buildRefAdvancementFields, lt as originHashForStatus, m as createControlClient, mt as refuseDeclaredExtensionTargetMismatch, n as NO_REF_ADVANCEMENT, nt as loadContractSpaceAggregateForCli, o as buildContractSpaceAggregate, ot as mapIntegrityViolations, p as computeRefAdvancementName, pt as refuseContractSpaceIntegrity, q as executeRefAdvancement, r as advanceRefSafely, s as buildMigrationSpaceGraphEntries, tt as loadContractRawSafely, u as checkSingleTarget, ut as preflightRefAdvancement, v as enumerateCheckSpaces, vt as refuseUnknownInvariants, wt as resolveMigrationRef, xt as resolveContractRef$1 } from "./ref-DlKsxbtg-DlwrVT2q.mjs";
2
2
  export { NO_REF_ADVANCEMENT, advanceRefSafely, appContractStandInFromIdentity, appliedHashesFromLedger, buildContractSpaceAggregate, buildMigrationSpaceGraphEntries, buildReadAggregate, buildRefAdvancementFields, checkSingleTarget, computeRefAdvancementName, createControlClient, deriveStatusEdgeAnnotations, disposeEmitQueue, enrichContract, enumerateCheckSpaces, executeContractEmit, executeDbInit, executeDbUpdate, executeDbVerify, executeMigrateShowPlan, executeMigrationNewCommand, executeMigrationPlanCommand, executeRefAdvancement, executeRefDeleteCommand, executeRefListCommand, executeRefSetCommand, hasMigrationPath, listRefsByContractHash, loadAggregateIntegrityViolations, loadContractRawSafely, loadContractSpaceAggregateForCli, mapCaughtMigrationError, mapContractAtError, mapIntegrityViolations, migrationSpaceListEntriesFromAggregate, originHashForStatus, preflightRefAdvancement, readMigrationRefs, refuseContractSpaceIntegrity, refuseDeclaredExtensionTargetMismatch, refuseMarkerOutsideGraph, refuseMissingInvariantPath, refusePackageCorruptionOnAggregate, refuseUnknownInvariants, resolveContractRef$1 as resolveContractRef, resolveContractRefToSnapshot, resolveFromForPlan, resolveMigrationRef, resolveToForPlan, runContractSpaceSeedPhase, runMigrationCheck, runMigrationList, statusForMigrationHash };
@@ -7,12 +7,12 @@ import { join } from "pathe";
7
7
  import { normalize as normalize$1 } from "node:path";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
9
  import { format } from "@prisma/orm-framework/psl-parser/format";
10
- import { CompletionItemKind, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, TextDocuments, createConnection } from "vscode-languageserver";
11
- import { TextDocument } from "vscode-languageserver-textdocument";
12
- import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, StringLiteralExprAst, SyntaxNode, TaggedLiteralExprAst, TypesBlockAst, any, filterChildren, findChildToken, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
10
+ import { CompletionItemKind, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, createConnection } from "vscode-languageserver";
11
+ import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PslSources, StringLiteralExprAst, SyntaxNode, TaggedLiteralExprAst, TypesBlockAst, any, filterChildren, findChildToken, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
13
12
  import { isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor } from "@prisma/orm-framework/components/authoring";
14
13
  import { assembleAttributeSpecs, buildSymbolTable, findBlockDescriptor } from "@prisma/orm-framework/psl-parser";
15
14
  import { hasPslInterpreter } from "@prisma/orm-framework/psl-parser/interpret";
15
+ import { TextDocument } from "vscode-languageserver-textdocument";
16
16
  import { ProposedFeatures as ProposedFeatures$1, StreamMessageReader, StreamMessageWriter, createConnection as createConnection$1, createProtocolConnection } from "vscode-languageserver/node";
17
17
  import { Console } from "node:console";
18
18
  import { Readable, Writable } from "node:stream";
@@ -44,18 +44,12 @@ const documentStartRange = {
44
44
  };
45
45
  function mapInterpreterDiagnostics(diagnostics, sourceFile) {
46
46
  return diagnostics.map((diagnostic) => ({
47
- range: diagnostic.span === void 0 ? documentStartRange : pslSpanToRange(diagnostic.span, sourceFile),
47
+ range: diagnostic.span === void 0 ? documentStartRange : sourceFile.pslSpanToRange(diagnostic.span),
48
48
  message: diagnostic.message,
49
49
  code: diagnostic.code,
50
50
  severity: ParseDiagnosticSeverity.Error
51
51
  }));
52
52
  }
53
- function pslSpanToRange(span, sourceFile) {
54
- return {
55
- start: sourceFile.positionAt(span.start.offset),
56
- end: sourceFile.positionAt(span.end.offset)
57
- };
58
- }
59
53
  function locateAttributeSyntax(input) {
60
54
  const offset = input.sourceFile.offsetAt(input.position);
61
55
  const at = input.document.syntax.tokenAtOffset(offset);
@@ -1248,6 +1242,33 @@ function resolveInterpretation(config, stack, inputs) {
1248
1242
  }
1249
1243
  };
1250
1244
  }
1245
+ var DocumentStore = class {
1246
+ documents = /* @__PURE__ */ new Map();
1247
+ getDocument = (uri) => this.documents.get(canonicalFileIdentity(uri));
1248
+ all() {
1249
+ return [...this.documents.values()];
1250
+ }
1251
+ open(item) {
1252
+ const document = TextDocument.create(item.uri, item.languageId, item.version, item.text);
1253
+ this.documents.set(canonicalFileIdentity(item.uri), document);
1254
+ return document;
1255
+ }
1256
+ change(identifier, changes) {
1257
+ if (changes.length === 0) return void 0;
1258
+ const { uri, version } = identifier;
1259
+ if (version === null || version === void 0) throw new InternalError(`Received document change event for ${uri} without valid version identifier`);
1260
+ const document = this.getDocument(uri);
1261
+ if (document === void 0) return void 0;
1262
+ const updated = TextDocument.update(document, changes, version);
1263
+ this.documents.set(canonicalFileIdentity(uri), updated);
1264
+ return updated;
1265
+ }
1266
+ close(uri) {
1267
+ const document = this.getDocument(uri);
1268
+ this.documents.delete(canonicalFileIdentity(uri));
1269
+ return document;
1270
+ }
1271
+ };
1251
1272
  /**
1252
1273
  * Computes folding ranges for block declarations in a PSL document.
1253
1274
  *
@@ -1260,22 +1281,23 @@ function resolveInterpretation(config, stack, inputs) {
1260
1281
  *
1261
1282
  * The range spans from the line containing `{` to the line containing `}`.
1262
1283
  */
1263
- function computeFoldingRanges(document, sourceFile) {
1284
+ function computeFoldingRanges(document, sources) {
1264
1285
  const ranges = [];
1265
- collectFoldingRanges(document, sourceFile, ranges);
1286
+ collectFoldingRanges(document, sources, ranges);
1266
1287
  return ranges;
1267
1288
  }
1268
- function collectFoldingRanges(document, sourceFile, ranges) {
1289
+ function collectFoldingRanges(document, sources, ranges) {
1269
1290
  for (const declaration of document.declarations()) {
1270
- addFoldingRange(declaration, sourceFile, ranges);
1291
+ addFoldingRange(declaration, sources, ranges);
1271
1292
  const namespace = NamespaceDeclarationAst.cast(declaration.syntax);
1272
- if (namespace !== void 0) for (const nested of namespace.declarations()) addFoldingRange(nested, sourceFile, ranges);
1293
+ if (namespace !== void 0) for (const nested of namespace.declarations()) addFoldingRange(nested, sources, ranges);
1273
1294
  }
1274
1295
  }
1275
- function addFoldingRange(declaration, sourceFile, ranges) {
1296
+ function addFoldingRange(declaration, sources, ranges) {
1276
1297
  const lbrace = declaration.lbrace();
1277
1298
  const rbrace = declaration.rbrace();
1278
1299
  if (lbrace === void 0 || rbrace === void 0) return;
1300
+ const sourceFile = sources.sourceFileFor(declaration.syntax);
1279
1301
  const startLine = sourceFile.positionAt(lbrace.offset).line;
1280
1302
  const endLine = sourceFile.positionAt(rbrace.offset).line;
1281
1303
  ranges.push({
@@ -1356,17 +1378,20 @@ function isThenable(value) {
1356
1378
  * of symbol-table diagnostics. Never throws on malformed input — `parse`
1357
1379
  * recovers and `buildSymbolTable` is documented not to throw.
1358
1380
  */
1359
- function runPipeline(text, inputs) {
1360
- const { document, sourceFile, diagnostics: parseDiagnostics } = parse(text);
1361
- const { table: symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({
1362
- document,
1363
- sourceFile,
1381
+ function runPipeline(filename, text, inputs) {
1382
+ const { document, sources, diagnostics: parseDiagnostics } = parse(text, filename);
1383
+ const sourceFile = sources.sourceFileFor(document.syntax);
1384
+ const { symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({
1385
+ documents: [document],
1386
+ sources,
1364
1387
  pslBlockDescriptors: inputs.pslBlockDescriptors
1365
1388
  });
1366
1389
  return {
1367
1390
  document,
1368
1391
  sourceFile,
1392
+ sources,
1369
1393
  symbolTable,
1394
+ parseDiagnostics: mapParseDiagnostics(parseDiagnostics),
1370
1395
  diagnostics: mapParseDiagnostics([...parseDiagnostics, ...symbolTableDiagnostics])
1371
1396
  };
1372
1397
  }
@@ -1387,30 +1412,38 @@ function renameLegacyDirective(text) {
1387
1412
  */
1388
1413
  function computeDocumentDiagnostics(uri, text, inputs, controlStack) {
1389
1414
  if (!inputs.includes(uri) || !isPrismaNextSchema(text)) return null;
1390
- const { document, sourceFile, symbolTable, diagnostics } = runPipeline(text, controlStack);
1415
+ const { document, sourceFile, symbolTable, diagnostics, parseDiagnostics } = runPipeline(uri, text, controlStack);
1391
1416
  return {
1392
1417
  diagnostics,
1418
+ parseDiagnostics,
1393
1419
  document,
1394
1420
  sourceFile,
1395
1421
  symbolTable
1396
1422
  };
1397
1423
  }
1398
1424
  function createProjectArtifacts(options) {
1399
- const { inputs, controlStack, getText, interpretation } = options;
1425
+ const { inputs, controlStack, getDocument, interpretation } = options;
1400
1426
  const documents = /* @__PURE__ */ new Map();
1401
- let symbolTable;
1402
- function createInterpretSlot(uri, computed) {
1427
+ let symbolTableResult;
1428
+ let sources = new PslSources([]);
1429
+ function refreshSources() {
1430
+ sources = new PslSources(Array.from(documents.values(), ({ document, sourceFile }) => [document.syntax, sourceFile]));
1431
+ symbolTableResult = void 0;
1432
+ }
1433
+ function createInterpretSlot(uri, document, sourceFile) {
1403
1434
  if (interpretation === void 0) return () => [];
1404
1435
  let memo;
1436
+ let memoSources;
1405
1437
  const interpretDiagnostics = () => {
1406
- if (memo === void 0) {
1438
+ const currentSymbolTable = readSymbolTable();
1439
+ if (memo === void 0 || memoSources !== sources) {
1407
1440
  const result = interpretation.source.interpret({
1408
- document: computed.document,
1409
- sourceFile: computed.sourceFile,
1410
- symbolTable: computed.symbolTable,
1411
- sourceId: uri
1441
+ document,
1442
+ sources,
1443
+ symbolTable: currentSymbolTable
1412
1444
  }, interpretation.context);
1413
- memo = mapInterpreterDiagnostics(result.ok ? [] : result.failure.diagnostics, computed.sourceFile);
1445
+ memo = mapInterpreterDiagnostics(result.ok ? [] : result.failure.diagnostics.filter((diagnostic) => diagnostic.sourceId === sourceFile.filename), sourceFile);
1446
+ memoSources = sources;
1414
1447
  }
1415
1448
  return memo;
1416
1449
  };
@@ -1439,41 +1472,50 @@ function createProjectArtifacts(options) {
1439
1472
  };
1440
1473
  }
1441
1474
  function drop(uri) {
1442
- if (documents.delete(uri)) symbolTable = void 0;
1475
+ if (documents.delete(canonicalFileIdentity(uri))) refreshSources();
1443
1476
  }
1444
1477
  function readDocument(uri) {
1445
- const existing = documents.get(uri);
1478
+ const identity = canonicalFileIdentity(uri);
1479
+ const existing = documents.get(identity);
1446
1480
  if (existing !== void 0) return existing;
1447
- const text = getText(uri);
1448
- if (text === void 0) return;
1449
- const computed = computeDocumentDiagnostics(uri, text, inputs, controlStack);
1481
+ const textDocument = getDocument(uri);
1482
+ if (textDocument === void 0) return;
1483
+ const computed = computeDocumentDiagnostics(textDocument.uri, textDocument.getText(), inputs, controlStack);
1450
1484
  if (computed === null) return;
1451
1485
  const artifacts = {
1452
1486
  document: computed.document,
1453
1487
  sourceFile: computed.sourceFile,
1454
- diagnostics: computed.diagnostics,
1455
- interpretDiagnostics: createInterpretSlot(uri, computed)
1488
+ diagnostics: computed.parseDiagnostics,
1489
+ interpretDiagnostics: createInterpretSlot(textDocument.uri, computed.document, computed.sourceFile)
1456
1490
  };
1457
- documents.set(uri, artifacts);
1458
- symbolTable = computed.symbolTable;
1491
+ documents.set(identity, artifacts);
1492
+ refreshSources();
1459
1493
  return artifacts;
1460
1494
  }
1495
+ function readSymbolTableResult() {
1496
+ const currentDocuments = [];
1497
+ for (const uri of inputs.uris()) {
1498
+ const artifacts = readDocument(uri);
1499
+ if (artifacts !== void 0) currentDocuments.push(artifacts.document);
1500
+ }
1501
+ if (currentDocuments.length === 0) throw new InternalError("invariant violated: project has no readable configured input — callers must check document artifacts first");
1502
+ symbolTableResult ??= buildSymbolTable({
1503
+ documents: currentDocuments,
1504
+ sources,
1505
+ pslBlockDescriptors: controlStack.pslBlockDescriptors
1506
+ });
1507
+ return symbolTableResult;
1508
+ }
1509
+ function readSymbolTable() {
1510
+ return readSymbolTableResult().symbolTable;
1511
+ }
1461
1512
  return {
1462
- document: readDocument,
1463
- symbolTable: () => {
1464
- if (symbolTable !== void 0) return symbolTable;
1465
- for (const uri of inputs.uris()) {
1466
- const artifacts = readDocument(uri);
1467
- if (artifacts === void 0) continue;
1468
- symbolTable ??= buildSymbolTable({
1469
- document: artifacts.document,
1470
- sourceFile: artifacts.sourceFile,
1471
- pslBlockDescriptors: controlStack.pslBlockDescriptors
1472
- }).table;
1473
- return symbolTable;
1474
- }
1475
- throw new InternalError("invariant violated: project has no readable configured input — callers must check document artifacts first");
1513
+ get sources() {
1514
+ return sources;
1476
1515
  },
1516
+ document: readDocument,
1517
+ symbolTable: readSymbolTable,
1518
+ symbolDiagnostics: () => readSymbolTableResult().diagnostics,
1477
1519
  documentChanged: drop,
1478
1520
  documentClosed: drop
1479
1521
  };
@@ -1725,30 +1767,30 @@ function collectTypeReference(name, source, tokens, namespace) {
1725
1767
  function classifyTypeReference(path, source, namespace) {
1726
1768
  const name = path[path.length - 1];
1727
1769
  if (name === void 0) return { tokenType: "type" };
1728
- const table = source.symbolTable;
1770
+ const symbols = source.symbolTable;
1729
1771
  const namespaceName = path.length > 1 ? path[path.length - 2] : namespace;
1730
- const namespaceScope = namespaceName !== void 0 ? table.topLevel.namespaces[namespaceName] : void 0;
1772
+ const namespaceScope = namespaceName !== void 0 ? symbols.topLevel.namespaces[namespaceName] : void 0;
1731
1773
  if (namespaceScope !== void 0) {
1732
1774
  if (Object.hasOwn(namespaceScope.models, name)) return { tokenType: "class" };
1733
1775
  if (Object.hasOwn(namespaceScope.compositeTypes, name)) return { tokenType: "struct" };
1734
1776
  if (Object.hasOwn(namespaceScope.blocks, name)) return { tokenType: "type" };
1735
1777
  }
1736
- if (Object.hasOwn(table.topLevel.models, name)) return { tokenType: "class" };
1737
- if (Object.hasOwn(table.topLevel.compositeTypes, name)) return { tokenType: "struct" };
1738
- const namedType = table.topLevel.namedTypes[name];
1778
+ if (Object.hasOwn(symbols.topLevel.models, name)) return { tokenType: "class" };
1779
+ if (Object.hasOwn(symbols.topLevel.compositeTypes, name)) return { tokenType: "struct" };
1780
+ const namedType = symbols.topLevel.namedTypes[name];
1739
1781
  if (namedType !== void 0) return refinesScalarType(namedType, source.scalarTypes) ? {
1740
1782
  tokenType: "type",
1741
1783
  modifierBitset: semanticTokenModifierBits.defaultLibrary
1742
1784
  } : { tokenType: "type" };
1743
- if (Object.hasOwn(table.topLevel.blocks, name)) return { tokenType: "type" };
1785
+ if (Object.hasOwn(symbols.topLevel.blocks, name)) return { tokenType: "type" };
1744
1786
  if (source.scalarTypes.includes(name)) return {
1745
1787
  tokenType: "type",
1746
1788
  modifierBitset: semanticTokenModifierBits.defaultLibrary
1747
1789
  };
1748
1790
  return { tokenType: "type" };
1749
1791
  }
1750
- function isKnownNamespace(name, table) {
1751
- return Object.hasOwn(table.topLevel.namespaces, name);
1792
+ function isKnownNamespace(name, symbols) {
1793
+ return Object.hasOwn(symbols.topLevel.namespaces, name);
1752
1794
  }
1753
1795
  function identifierSegments(name) {
1754
1796
  const segments = [];
@@ -2009,7 +2051,8 @@ function createServer(connection) {
2009
2051
  return createServerOn(guardedConnection(connection));
2010
2052
  }
2011
2053
  function createServerOn(connection) {
2012
- const documents = new TextDocuments(TextDocument);
2054
+ const documents = new DocumentStore();
2055
+ const { getDocument } = documents;
2013
2056
  const managedProjects = /* @__PURE__ */ new Map();
2014
2057
  const documentConfigPaths = /* @__PURE__ */ new Map();
2015
2058
  let rootPath = process.cwd();
@@ -2024,25 +2067,31 @@ function createServerOn(connection) {
2024
2067
  async function publish(uri) {
2025
2068
  const project = await resolveProjectForDocument(uri);
2026
2069
  if (project === void 0) return;
2027
- if (documents.get(uri) === void 0) {
2028
- documentConfigPaths.delete(uri);
2070
+ const document = getDocument(uri);
2071
+ if (document === void 0) {
2072
+ documentConfigPaths.delete(canonicalFileIdentity(uri));
2029
2073
  return;
2030
2074
  }
2031
2075
  const artifacts = project.artifacts.document(uri);
2032
2076
  if (artifacts === void 0) {
2033
2077
  sendDiagnostics({
2034
- uri,
2078
+ uri: document.uri,
2035
2079
  diagnostics: []
2036
2080
  });
2037
2081
  return;
2038
2082
  }
2039
2083
  sendDiagnostics({
2040
- uri,
2041
- diagnostics: combinedDiagnostics(artifacts)
2084
+ uri: document.uri,
2085
+ diagnostics: combinedDiagnostics(project.artifacts, artifacts)
2042
2086
  });
2043
2087
  }
2044
- function combinedDiagnostics(artifacts) {
2045
- return toDiagnostics([...artifacts.diagnostics, ...artifacts.interpretDiagnostics()]);
2088
+ function combinedDiagnostics(project, artifacts) {
2089
+ const symbolDiagnostics = project.symbolDiagnostics().filter((diagnostic) => diagnostic.filename === artifacts.sourceFile.filename);
2090
+ return toDiagnostics([
2091
+ ...artifacts.diagnostics,
2092
+ ...mapParseDiagnostics(symbolDiagnostics),
2093
+ ...artifacts.interpretDiagnostics()
2094
+ ]);
2046
2095
  }
2047
2096
  /**
2048
2097
  * Project-scoped so a future multi-input symbol table can attach
@@ -2052,17 +2101,17 @@ function createServerOn(connection) {
2052
2101
  const artifacts = project.artifacts.document(uri);
2053
2102
  return {
2054
2103
  kind: DocumentDiagnosticReportKind.Full,
2055
- items: artifacts === void 0 ? [] : combinedDiagnostics(artifacts)
2104
+ items: artifacts === void 0 ? [] : combinedDiagnostics(project.artifacts, artifacts)
2056
2105
  };
2057
2106
  }
2058
2107
  async function resolveProjectForDocument(uri) {
2059
2108
  const project = await projectForNearestConfig(uri);
2060
2109
  if (project === void 0 || project.inputs.includes(uri)) return project;
2061
- documentConfigPaths.delete(uri);
2110
+ documentConfigPaths.delete(canonicalFileIdentity(uri));
2062
2111
  dropProjectWithoutManagedDocuments(project.configPath);
2063
2112
  }
2064
2113
  async function projectForNearestConfig(uri) {
2065
- const knownConfigPath = documentConfigPaths.get(uri);
2114
+ const knownConfigPath = documentConfigPaths.get(canonicalFileIdentity(uri));
2066
2115
  if (knownConfigPath !== void 0) return resolveProjectIfLoadable(knownConfigPath);
2067
2116
  const filePath = filePathFromUri(uri);
2068
2117
  if (filePath === void 0) return;
@@ -2073,7 +2122,7 @@ function createServerOn(connection) {
2073
2122
  return;
2074
2123
  }
2075
2124
  if (configPath === void 0) return;
2076
- documentConfigPaths.set(uri, configPath);
2125
+ documentConfigPaths.set(canonicalFileIdentity(uri), configPath);
2077
2126
  return resolveProjectIfLoadable(configPath);
2078
2127
  }
2079
2128
  async function resolveProjectIfLoadable(configPath) {
@@ -2170,7 +2219,7 @@ function createServerOn(connection) {
2170
2219
  const artifacts = createProjectArtifacts({
2171
2220
  inputs: resolution.inputs,
2172
2221
  controlStack: resolution.controlStack,
2173
- getText: (uri) => documents.get(uri)?.getText(),
2222
+ getDocument,
2174
2223
  onInterpretationError: (uri, error) => {
2175
2224
  const detail = error instanceof Error ? error.stack ?? error.message : String(error);
2176
2225
  connection.console.error(`PSL interpretation failed for ${uri}: ${detail}`);
@@ -2187,11 +2236,11 @@ function createServerOn(connection) {
2187
2236
  };
2188
2237
  }
2189
2238
  function unmanageDocuments(configPath) {
2190
- for (const document of documents.all()) if (documentConfigPaths.get(document.uri) === configPath) documentConfigPaths.delete(document.uri);
2239
+ for (const document of documents.all()) if (documentConfigPaths.get(canonicalFileIdentity(document.uri)) === configPath) documentConfigPaths.delete(canonicalFileIdentity(document.uri));
2191
2240
  }
2192
2241
  async function republishOpenDocumentsForConfig(configPath) {
2193
2242
  for (const document of documents.all()) {
2194
- if (documentConfigPaths.get(document.uri) === configPath) {
2243
+ if (documentConfigPaths.get(canonicalFileIdentity(document.uri)) === configPath) {
2195
2244
  if (await resolveProjectForDocument(document.uri) === void 0) {
2196
2245
  sendDiagnostics({
2197
2246
  uri: document.uri,
@@ -2205,7 +2254,7 @@ function createServerOn(connection) {
2205
2254
  const filePath = filePathFromUri(document.uri);
2206
2255
  if (filePath === void 0) continue;
2207
2256
  if (await findNearestConfigPathForFile(filePath) === configPath) {
2208
- documentConfigPaths.set(document.uri, configPath);
2257
+ documentConfigPaths.set(canonicalFileIdentity(document.uri), configPath);
2209
2258
  await publish(document.uri);
2210
2259
  }
2211
2260
  }
@@ -2216,7 +2265,7 @@ function createServerOn(connection) {
2216
2265
  });
2217
2266
  }
2218
2267
  async function formatDocument(uri) {
2219
- const document = documents.get(uri);
2268
+ const document = getDocument(uri);
2220
2269
  if (document === void 0) return [];
2221
2270
  const source = document.getText();
2222
2271
  if (!isPrismaNextSchema(source)) return [];
@@ -2241,7 +2290,7 @@ function createServerOn(connection) {
2241
2290
  }];
2242
2291
  }
2243
2292
  async function semanticTokensForDocument(uri, range) {
2244
- const document = documents.get(uri);
2293
+ const document = getDocument(uri);
2245
2294
  if (document === void 0) return emptySemanticTokens();
2246
2295
  if (document.getText().length > semanticTokenSourceLimit) return emptySemanticTokens();
2247
2296
  const project = await resolveProjectForDocument(uri);
@@ -2256,7 +2305,7 @@ function createServerOn(connection) {
2256
2305
  }, range);
2257
2306
  }
2258
2307
  async function completeDocument(uri, position) {
2259
- if (documents.get(uri) === void 0) return [];
2308
+ if (getDocument(uri) === void 0) return [];
2260
2309
  const project = await resolveProjectForDocument(uri);
2261
2310
  if (project === void 0) return [];
2262
2311
  const artifacts = project.artifacts.document(uri);
@@ -2285,7 +2334,7 @@ function createServerOn(connection) {
2285
2334
  }
2286
2335
  }
2287
2336
  async function signatureHelpForDocument(uri, position) {
2288
- if (documents.get(uri) === void 0) return null;
2337
+ if (getDocument(uri) === void 0) return null;
2289
2338
  const project = await resolveProjectForDocument(uri);
2290
2339
  if (project === void 0) return null;
2291
2340
  const artifacts = project.artifacts.document(uri);
@@ -2312,7 +2361,10 @@ function createServerOn(connection) {
2312
2361
  watchedConfigGlob = join(rootPath, "**", CONFIG_FILENAME);
2313
2362
  clientCapabilities = resolveClientCapabilities(params);
2314
2363
  return { capabilities: {
2315
- textDocumentSync: TextDocumentSyncKind.Incremental,
2364
+ textDocumentSync: {
2365
+ openClose: true,
2366
+ change: TextDocumentSyncKind.Incremental
2367
+ },
2316
2368
  documentFormattingProvider: true,
2317
2369
  foldingRangeProvider: true,
2318
2370
  semanticTokensProvider: {
@@ -2374,36 +2426,45 @@ function createServerOn(connection) {
2374
2426
  if (project === void 0) return [];
2375
2427
  const artifacts = project.artifacts.document(params.textDocument.uri);
2376
2428
  if (artifacts === void 0) return [];
2377
- return computeFoldingRanges(artifacts.document, artifacts.sourceFile);
2429
+ return computeFoldingRanges(artifacts.document, project.artifacts.sources);
2378
2430
  });
2379
- documents.onDidOpen((event) => {
2380
- artifactsForDocument(event.document.uri)?.documentChanged(event.document.uri);
2381
- if (clientCapabilities.pullDiagnostics) return;
2382
- publishSafely(event.document.uri);
2431
+ function documentChanged(uri) {
2432
+ artifactsForDocument(uri)?.documentChanged(uri);
2433
+ if (!clientCapabilities.pullDiagnostics) publishSafely(uri);
2434
+ }
2435
+ connection.onDidOpenTextDocument((event) => {
2436
+ const previous = getDocument(event.textDocument.uri);
2437
+ const document = documents.open(event.textDocument);
2438
+ if (previous !== void 0 && previous.uri !== document.uri && !clientCapabilities.pullDiagnostics) sendDiagnostics({
2439
+ uri: previous.uri,
2440
+ diagnostics: []
2441
+ });
2442
+ documentChanged(document.uri);
2383
2443
  });
2384
- documents.onDidChangeContent((event) => {
2385
- artifactsForDocument(event.document.uri)?.documentChanged(event.document.uri);
2386
- if (clientCapabilities.pullDiagnostics) return;
2387
- publishSafely(event.document.uri);
2444
+ connection.onDidChangeTextDocument((event) => {
2445
+ const document = documents.change(event.textDocument, event.contentChanges);
2446
+ if (document !== void 0) documentChanged(document.uri);
2388
2447
  });
2389
- documents.onDidClose((event) => {
2390
- const uri = event.document.uri;
2391
- const configPath = documentConfigPaths.get(uri);
2448
+ connection.onDidCloseTextDocument((event) => {
2449
+ const document = documents.close(event.textDocument.uri);
2450
+ if (document === void 0) return;
2451
+ const uri = document.uri;
2452
+ const configPath = documentConfigPaths.get(canonicalFileIdentity(uri));
2392
2453
  artifactsForDocument(uri)?.documentClosed(uri);
2393
- documentConfigPaths.delete(uri);
2454
+ documentConfigPaths.delete(canonicalFileIdentity(uri));
2394
2455
  if (configPath !== void 0) dropProjectWithoutManagedDocuments(configPath);
2395
2456
  if (!clientCapabilities.pullDiagnostics) sendDiagnostics({
2396
2457
  uri,
2397
2458
  diagnostics: []
2398
2459
  });
2399
2460
  });
2400
- documents.listen(connection);
2401
2461
  connection.listen();
2402
2462
  function artifactsForDocument(uri) {
2403
- const configPath = documentConfigPaths.get(uri);
2463
+ const configPath = documentConfigPaths.get(canonicalFileIdentity(uri));
2404
2464
  if (configPath === void 0) return;
2405
2465
  const entry = managedProjects.get(configPath);
2406
- return entry?.status === "loaded" ? entry.project.artifacts : void 0;
2466
+ if (entry?.status === "loaded") return entry.project.artifacts;
2467
+ return entry?.status === "loading" ? entry.lastGood?.artifacts : void 0;
2407
2468
  }
2408
2469
  function hasManagedDocuments(configPath) {
2409
2470
  for (const managedConfigPath of documentConfigPaths.values()) if (managedConfigPath === configPath) return true;
@@ -2734,4 +2795,4 @@ function startServer(streams) {
2734
2795
  //#endregion
2735
2796
  export { startServer };
2736
2797
 
2737
- //# sourceMappingURL=exports-D3ZkBOTs.mjs.map
2798
+ //# sourceMappingURL=exports-DD54g3O_.mjs.map