@prisma/orm-toolchain 8.0.0-rc.2-dev.3 → 8.0.0-rc.20
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 +1 -5
- package/dist/{aggregate-DLUJLq5Y.d.mts → aggregate-BpcQdygS.d.mts} +83 -36
- package/dist/aggregate-BpcQdygS.d.mts.map +1 -0
- package/dist/{aggregate-CPZB020V.mjs → aggregate-T_HG6gq6.mjs} +118 -57
- package/dist/aggregate-T_HG6gq6.mjs.map +1 -0
- package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs +1026 -0
- package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs.map +1 -0
- package/dist/cli-telemetry.d.mts +9 -8
- package/dist/cli-telemetry.d.mts.map +1 -1
- package/dist/cli-telemetry.mjs +30 -27
- package/dist/cli-telemetry.mjs.map +1 -1
- package/dist/cli.d.mts +7 -14
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +3769 -1506
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +233 -93
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +3 -2
- package/dist/cli__control-api__testing.d.mts +5 -4
- package/dist/cli__control-api__testing.d.mts.map +1 -1
- package/dist/cli__control-api__testing.mjs +21 -16
- package/dist/cli__control-api__testing.mjs.map +1 -1
- package/dist/cli__init-output.d.mts +11 -1
- package/dist/cli__init-output.d.mts.map +1 -1
- package/dist/cli__init-output.mjs +1 -1
- package/dist/cli__migration-cli.d.mts +1 -1
- package/dist/cli__migration-cli.mjs +65 -19
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.d.mts +2 -2
- package/dist/config-loader.mjs +2 -2
- package/dist/{contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs → contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs} +44 -16
- package/dist/contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs.map +1 -0
- package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts +59 -0
- package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts.map +1 -0
- package/dist/contract-snapshot-store-DrIwu5pn.d.mts +2 -0
- package/dist/{db-verify-BwgNK50T-DGvKgFCK.d.mts → db-sign-gvrl0kFE-D-nTGx88.d.mts} +330 -230
- package/dist/db-sign-gvrl0kFE-D-nTGx88.d.mts.map +1 -0
- package/dist/{domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs → domain-type-generation-B4m774CV-WAjyhZHw.mjs} +144 -154
- package/dist/domain-type-generation-B4m774CV-WAjyhZHw.mjs.map +1 -0
- package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts +78 -0
- package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts.map +1 -0
- package/dist/emitter.d.mts +3 -3
- package/dist/emitter.mjs +3 -3
- package/dist/emitter__domain-type-generation.d.mts +2 -2
- package/dist/emitter__domain-type-generation.mjs +2 -2
- package/dist/{errors-D59OCpoI.d.mts → errors-CLwhWJiz.d.mts} +14 -3
- package/dist/errors-CLwhWJiz.d.mts.map +1 -0
- package/dist/{errors-CXbGUWGu-CstQHPh6.mjs → errors-DXha_4l--relAaiI4.mjs} +37 -42
- package/dist/errors-DXha_4l--relAaiI4.mjs.map +1 -0
- package/dist/exports-BCIlMjIW-DkUBVDzl.mjs +421 -0
- package/dist/exports-BCIlMjIW-DkUBVDzl.mjs.map +1 -0
- package/dist/exports-BlYTE3-J.mjs +539 -0
- package/dist/exports-BlYTE3-J.mjs.map +1 -0
- package/dist/exports-CKgwcXbp.mjs +3973 -0
- package/dist/exports-CKgwcXbp.mjs.map +1 -0
- package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs +19 -0
- package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs.map +1 -0
- package/dist/{hash-DH8hl5Rq-BpM2t3Nu.mjs → hash-BAZVWU4a-BQovI7hF.mjs} +24 -3
- package/dist/hash-BAZVWU4a-BQovI7hF.mjs.map +1 -0
- package/dist/hash-CwWGlFWV.d.mts +1 -0
- package/dist/{hash-XZYYKJ-i.d.mts → hash-DclMqd7S-WBvXJ_4C.d.mts} +17 -4
- package/dist/hash-DclMqd7S-WBvXJ_4C.d.mts.map +1 -0
- package/dist/{import-roots-CfoYgejL.d.mts → import-roots-ARK1wjzc.d.mts} +3 -3
- package/dist/{import-roots-CfoYgejL.d.mts.map → import-roots-ARK1wjzc.d.mts.map} +1 -1
- package/dist/{import-roots-CNFBPAT1.mjs → import-roots-BPn2s_fq.mjs} +6 -6
- package/dist/import-roots-BPn2s_fq.mjs.map +1 -0
- package/dist/index-CWPFeYyi.d.mts +204 -0
- package/dist/index-CWPFeYyi.d.mts.map +1 -0
- package/dist/{index-Dgwl8Tzs.d.mts → index-tAySVPvZ.d.mts} +16 -4
- package/dist/index-tAySVPvZ.d.mts.map +1 -0
- package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs → invariants-DrF9p5Gd-BF70vGl1.mjs} +3 -3
- package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs.map → invariants-DrF9p5Gd-BF70vGl1.mjs.map} +1 -1
- package/dist/{io-635GlNx1-D3zrw2qu.mjs → io-BNxFm3eg-DYD82QeZ.mjs} +8 -8
- package/dist/io-BNxFm3eg-DYD82QeZ.mjs.map +1 -0
- package/dist/io-D8Epu7iY.d.mts +1 -0
- package/dist/{io-sr4CO9_t-C3eV_kn-.d.mts → io-DZfMV51z-BKlH5Dhb.d.mts} +9 -2
- package/dist/io-DZfMV51z-BKlH5Dhb.d.mts.map +1 -0
- package/dist/{migration-B2ljMJim.d.mts → migration-Bjz05034.d.mts} +12 -5
- package/dist/migration-Bjz05034.d.mts.map +1 -0
- package/dist/{migration-hspPIEeV.mjs → migration-CWyjX9vz.mjs} +18 -6
- package/dist/migration-CWyjX9vz.mjs.map +1 -0
- package/dist/{migration-graph-_SJImD5V-BURyY1KM.mjs → migration-graph-BoiiZAaU-DLht12k7.mjs} +6 -89
- package/dist/migration-graph-BoiiZAaU-DLht12k7.mjs.map +1 -0
- package/dist/{migration-graph-tarTxJ99-BrGBANeE.d.mts → migration-graph-D8IuOkZb-pSI7-k4_.d.mts} +7 -29
- package/dist/migration-graph-D8IuOkZb-pSI7-k4_.d.mts.map +1 -0
- package/dist/migration-graph-Dra4CcyN.d.mts +14 -0
- package/dist/migration-graph-Dra4CcyN.d.mts.map +1 -0
- package/dist/migration-tools.d.mts +17 -15
- package/dist/migration-tools.mjs +15 -15
- package/dist/migration-tools__aggregate.d.mts +2 -2
- package/dist/migration-tools__aggregate.mjs +2 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +4 -2
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -2
- package/dist/migration-tools__errors.d.mts +2 -2
- package/dist/migration-tools__errors.mjs +1 -1
- package/dist/migration-tools__hash.d.mts +2 -1
- package/dist/migration-tools__hash.mjs +1 -1
- package/dist/migration-tools__invariants.mjs +1 -1
- package/dist/migration-tools__io.d.mts +2 -2
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.d.mts +3 -3
- package/dist/migration-tools__migration-graph.mjs +3 -3
- package/dist/migration-tools__migration-ts.d.mts +2 -2
- package/dist/migration-tools__migration-ts.mjs +2 -2
- package/dist/migration-tools__migration.d.mts +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.d.mts +2 -2
- package/dist/migration-tools__ref-resolution.mjs +2 -2
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.d.mts +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{migration-ts-DdVm0rws.mjs → migration-ts-DDgjsR1O.mjs} +6 -5
- package/dist/migration-ts-DDgjsR1O.mjs.map +1 -0
- package/dist/{migration-ts-CNaAtK8C.d.mts → migration-ts-SGer0PXq.d.mts} +4 -2
- package/dist/migration-ts-SGer0PXq.d.mts.map +1 -0
- package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs +23 -0
- package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs.map +1 -0
- package/dist/output-BcC8eB0h-C5bRd-aC.mjs +129 -0
- package/dist/output-BcC8eB0h-C5bRd-aC.mjs.map +1 -0
- package/dist/publish-surface.d.mts +1 -1
- package/dist/publish-surface.mjs +2 -2
- package/dist/publish-surface__import-roots.d.mts +1 -1
- package/dist/publish-surface__import-roots.mjs +1 -1
- package/dist/publish-surface__shells.mjs +1 -1
- package/dist/quick-reference-mongo.md +12 -12
- package/dist/quick-reference-postgres.md +10 -10
- package/dist/quick-reference-prisma7.md +80 -0
- package/dist/readme-mongo.md +6 -6
- package/dist/readme-postgres.md +6 -6
- package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs +6663 -0
- package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs.map +1 -0
- package/dist/{ref-resolution-COGOSL57.d.mts → ref-resolution-BPhR-kta.d.mts} +29 -11
- package/dist/ref-resolution-BPhR-kta.d.mts.map +1 -0
- package/dist/{ref-resolution-HeNBXW53.mjs → ref-resolution-Eo0QHp4f.mjs} +30 -6
- package/dist/ref-resolution-Eo0QHp4f.mjs.map +1 -0
- package/dist/{refs-WK86uYYp-gM8tvWQP.mjs → refs-DM3q3IZC-BC6H6P0X.mjs} +9 -9
- package/dist/refs-DM3q3IZC-BC6H6P0X.mjs.map +1 -0
- package/dist/{shells-C4HbRAr5.mjs → shells-w_yEDhe8.mjs} +98 -31
- package/dist/shells-w_yEDhe8.mjs.map +1 -0
- package/dist/{spaces-Dj65JrwZ.d.mts → spaces-BWULKO54.d.mts} +3 -3
- package/dist/{spaces-Dj65JrwZ.d.mts.map → spaces-BWULKO54.d.mts.map} +1 -1
- package/dist/{spaces-4qMOAYE9.mjs → spaces-c9xdiXW8.mjs} +14 -13
- package/dist/spaces-c9xdiXW8.mjs.map +1 -0
- package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs} +7 -7
- package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs.map → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.d.mts +1 -1
- package/dist/vite-plugin-contract-emit.mjs +10 -10
- package/dist/vite-plugin-contract-emit.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/aggregate-CPZB020V.mjs.map +0 -1
- package/dist/aggregate-DLUJLq5Y.d.mts.map +0 -1
- package/dist/contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs.map +0 -1
- package/dist/contract-snapshot-store-CbqynbtE.d.mts +0 -28
- package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +0 -1
- package/dist/db-verify-BwgNK50T-DGvKgFCK.d.mts.map +0 -1
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +0 -63
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +0 -1
- package/dist/domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs.map +0 -1
- package/dist/errors-CXbGUWGu-CstQHPh6.mjs.map +0 -1
- package/dist/errors-D59OCpoI.d.mts.map +0 -1
- package/dist/exports-8ZUN43ve.mjs +0 -1734
- package/dist/exports-8ZUN43ve.mjs.map +0 -1
- package/dist/exports-BCLg4CiV-05kuwcb0.mjs +0 -160
- package/dist/exports-BCLg4CiV-05kuwcb0.mjs.map +0 -1
- package/dist/exports-BZaG8_w_.mjs +0 -243
- package/dist/exports-BZaG8_w_.mjs.map +0 -1
- package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs +0 -14
- package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs.map +0 -1
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +0 -1
- package/dist/hash-XZYYKJ-i.d.mts.map +0 -1
- package/dist/import-roots-CNFBPAT1.mjs.map +0 -1
- package/dist/index-DRs7L6N0.d.mts +0 -57
- package/dist/index-DRs7L6N0.d.mts.map +0 -1
- package/dist/index-Dgwl8Tzs.d.mts.map +0 -1
- package/dist/io-635GlNx1-D3zrw2qu.mjs.map +0 -1
- package/dist/io-DYfeLJxR.d.mts +0 -1
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +0 -1
- package/dist/migration-B2ljMJim.d.mts.map +0 -1
- package/dist/migration-graph-Dqndu0i5.d.mts +0 -9
- package/dist/migration-graph-Dqndu0i5.d.mts.map +0 -1
- package/dist/migration-graph-_SJImD5V-BURyY1KM.mjs.map +0 -1
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +0 -1
- package/dist/migration-hspPIEeV.mjs.map +0 -1
- package/dist/migration-ts-CNaAtK8C.d.mts.map +0 -1
- package/dist/migration-ts-DdVm0rws.mjs.map +0 -1
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +0 -13
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +0 -1
- package/dist/output-CovTDY14-CUoAqLML.mjs +0 -77
- package/dist/output-CovTDY14-CUoAqLML.mjs.map +0 -1
- package/dist/ref-h6InR6dO-rGfl18Jv.mjs +0 -4686
- package/dist/ref-h6InR6dO-rGfl18Jv.mjs.map +0 -1
- package/dist/ref-resolution-COGOSL57.d.mts.map +0 -1
- package/dist/ref-resolution-HeNBXW53.mjs.map +0 -1
- package/dist/refs-WK86uYYp-gM8tvWQP.mjs.map +0 -1
- package/dist/shells-C4HbRAr5.mjs.map +0 -1
- package/dist/spaces-4qMOAYE9.mjs.map +0 -1
|
@@ -1,1734 +0,0 @@
|
|
|
1
|
-
import { n as findNearestConfigPathForFile, o as requireConfigSections, r as loadConfig } from "./exports-BZaG8_w_.mjs";
|
|
2
|
-
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
3
|
-
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
4
|
-
import { createControlStack } from "@prisma/orm-framework/components/control";
|
|
5
|
-
import { join } from "pathe";
|
|
6
|
-
import { format } from "@prisma/orm-framework/psl-parser/format";
|
|
7
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
-
import { CompletionItemKind, ConnectionError, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, ProposedFeatures, RegistrationRequest, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, TextDocuments, createConnection } from "vscode-languageserver";
|
|
9
|
-
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
10
|
-
import { ArrayLiteralAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, StringLiteralExprAst, TypesBlockAst, any, filterChildren, findChildToken, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
|
|
11
|
-
import { isAuthoringPslBlockDescriptor } from "@prisma/orm-framework/components/authoring";
|
|
12
|
-
import { buildSymbolTable, findBlockDescriptor } from "@prisma/orm-framework/psl-parser";
|
|
13
|
-
import { hasPslInterpreter } from "@prisma/orm-framework/psl-parser/interpret";
|
|
14
|
-
import { ProposedFeatures as ProposedFeatures$1, StreamMessageReader, StreamMessageWriter, createConnection as createConnection$1, createProtocolConnection } from "vscode-languageserver/node";
|
|
15
|
-
import { Console } from "node:console";
|
|
16
|
-
import { Readable, Writable } from "node:stream";
|
|
17
|
-
import { StringDecoder } from "node:string_decoder";
|
|
18
|
-
//#region ../../../1-framework/3-tooling/language-server/dist/exports/index.mjs
|
|
19
|
-
const ParseDiagnosticSeverity = {
|
|
20
|
-
Error: 1,
|
|
21
|
-
Warning: 2,
|
|
22
|
-
Information: 3,
|
|
23
|
-
Hint: 4
|
|
24
|
-
};
|
|
25
|
-
function mapParseDiagnostics(diagnostics) {
|
|
26
|
-
return diagnostics.map((diagnostic) => ({
|
|
27
|
-
range: diagnostic.range,
|
|
28
|
-
message: diagnostic.message,
|
|
29
|
-
code: diagnostic.code,
|
|
30
|
-
severity: ParseDiagnosticSeverity.Error
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
const documentStartRange = {
|
|
34
|
-
start: {
|
|
35
|
-
line: 0,
|
|
36
|
-
character: 0
|
|
37
|
-
},
|
|
38
|
-
end: {
|
|
39
|
-
line: 0,
|
|
40
|
-
character: 1
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function mapInterpreterDiagnostics(diagnostics, sourceFile) {
|
|
44
|
-
return diagnostics.map((diagnostic) => ({
|
|
45
|
-
range: diagnostic.span === void 0 ? documentStartRange : pslSpanToRange(diagnostic.span, sourceFile),
|
|
46
|
-
message: diagnostic.message,
|
|
47
|
-
code: diagnostic.code,
|
|
48
|
-
severity: ParseDiagnosticSeverity.Error
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
function pslSpanToRange(span, sourceFile) {
|
|
52
|
-
return {
|
|
53
|
-
start: sourceFile.positionAt(span.start.offset),
|
|
54
|
-
end: sourceFile.positionAt(span.end.offset)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const UNSUPPORTED = { kind: "unsupported" };
|
|
58
|
-
function classifyPslCompletionContext(input) {
|
|
59
|
-
const root = input.document.syntax;
|
|
60
|
-
const offset = input.sourceFile.offsetAt(input.position);
|
|
61
|
-
const at = root.tokenAtOffset(offset);
|
|
62
|
-
if (at.leftBiased()?.kind === "Comment") return UNSUPPORTED;
|
|
63
|
-
const edit = cursorIdentifier(at, offset);
|
|
64
|
-
const preceding = precedingToken(at, edit);
|
|
65
|
-
const precedingNode = preceding?.parent;
|
|
66
|
-
const replacementStartOffset = edit?.offset ?? offset;
|
|
67
|
-
const declarationKeywordContext = classifyDeclarationKeyword({
|
|
68
|
-
node: precedingNode,
|
|
69
|
-
offset,
|
|
70
|
-
replacementStartOffset
|
|
71
|
-
});
|
|
72
|
-
if (declarationKeywordContext !== void 0) return declarationKeywordContext;
|
|
73
|
-
const genericBlockContext = classifyGenericBlockParameter({
|
|
74
|
-
offset,
|
|
75
|
-
at,
|
|
76
|
-
precedingToken: preceding,
|
|
77
|
-
replacementStartOffset
|
|
78
|
-
});
|
|
79
|
-
if (genericBlockContext !== void 0) return genericBlockContext;
|
|
80
|
-
const field = fieldForTypeSlot(precedingNode);
|
|
81
|
-
if (field === void 0) return UNSUPPORTED;
|
|
82
|
-
if (field.syntax.findAncestor(any(ModelDeclarationAst.cast, CompositeTypeDeclarationAst.cast)) === void 0) return UNSUPPORTED;
|
|
83
|
-
return classifyModelFieldType({
|
|
84
|
-
field,
|
|
85
|
-
offset,
|
|
86
|
-
replacementStartOffset,
|
|
87
|
-
precedingToken: preceding
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Locates the field whose type position the cursor occupies. The preceding token
|
|
92
|
-
* climbs to the field whether the cursor sits inside a present type (the type
|
|
93
|
-
* identifier's predecessor still belongs to the field) or in the empty type slot
|
|
94
|
-
* of a typeless field (whose trailing trivia lives in the enclosing block, so
|
|
95
|
-
* the nearest significant token to the left is the field's own name).
|
|
96
|
-
*/
|
|
97
|
-
function fieldForTypeSlot(precedingNode) {
|
|
98
|
-
return precedingNode?.findAncestor(FieldDeclarationAst.cast);
|
|
99
|
-
}
|
|
100
|
-
function classifyModelFieldType(input) {
|
|
101
|
-
const fieldName = input.field.name();
|
|
102
|
-
if (fieldName === void 0) return UNSUPPORTED;
|
|
103
|
-
const fieldNameText = fieldName.name();
|
|
104
|
-
if (fieldNameText === void 0) return UNSUPPORTED;
|
|
105
|
-
if (fieldName.syntax.isInside(input.offset)) return UNSUPPORTED;
|
|
106
|
-
const typeAnnotation = input.field.typeAnnotation();
|
|
107
|
-
if (typeAnnotation === void 0) {
|
|
108
|
-
if (input.precedingToken !== void 0 && fieldName.syntax.isInside(input.precedingToken.offset)) return {
|
|
109
|
-
kind: "modelType",
|
|
110
|
-
offset: input.offset,
|
|
111
|
-
fieldName: fieldNameText,
|
|
112
|
-
replacementStartOffset: input.offset
|
|
113
|
-
};
|
|
114
|
-
return UNSUPPORTED;
|
|
115
|
-
}
|
|
116
|
-
if (typeAnnotation.syntax.isOutside(input.offset)) return UNSUPPORTED;
|
|
117
|
-
if (typeAnnotation.argList()?.syntax.isInside(input.offset)) return UNSUPPORTED;
|
|
118
|
-
const name = typeAnnotation.name();
|
|
119
|
-
if (name === void 0) return UNSUPPORTED;
|
|
120
|
-
if (name.syntax.isOutside(input.offset)) return UNSUPPORTED;
|
|
121
|
-
if (name.isOverQualified()) return UNSUPPORTED;
|
|
122
|
-
return classifyTypePosition(name, input.offset, fieldNameText, input.replacementStartOffset);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Builds the type-completion context for a qualified name. Roles are read
|
|
126
|
-
* straight off the separator-positional accessors: a populated namespace
|
|
127
|
-
* segment is a `.`-qualified name, a populated space segment is a `:`-qualified
|
|
128
|
-
* name, and the absence of both is a bare model type.
|
|
129
|
-
*
|
|
130
|
-
* Behaviour change: a `:`-qualified name with no `.` (e.g. `supabase:`,
|
|
131
|
-
* `supabase:U`) is a `spaceMember` position rather than falling through to bare
|
|
132
|
-
* model-type completions. A malformed leading-separator name (`:User`, `.User`)
|
|
133
|
-
* carries no populated segment and resolves to `modelType` rather than
|
|
134
|
-
* `unsupported`.
|
|
135
|
-
*/
|
|
136
|
-
function classifyTypePosition(name, offset, fieldName, replacementStartOffset) {
|
|
137
|
-
const namespace = name.namespace()?.name();
|
|
138
|
-
if (namespace !== void 0 && namespace.length > 0) {
|
|
139
|
-
const namespaceSpace = name.space()?.name();
|
|
140
|
-
return {
|
|
141
|
-
kind: "namespaceMember",
|
|
142
|
-
offset,
|
|
143
|
-
fieldName,
|
|
144
|
-
replacementStartOffset,
|
|
145
|
-
namespace,
|
|
146
|
-
...namespaceSpace !== void 0 && namespaceSpace.length > 0 ? { space: namespaceSpace } : {}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const space = name.space()?.name();
|
|
150
|
-
if (space !== void 0 && space.length > 0) return {
|
|
151
|
-
kind: "spaceMember",
|
|
152
|
-
offset,
|
|
153
|
-
fieldName,
|
|
154
|
-
replacementStartOffset,
|
|
155
|
-
space
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
kind: "modelType",
|
|
159
|
-
offset,
|
|
160
|
-
fieldName,
|
|
161
|
-
replacementStartOffset
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
const declarationCast = any(ModelDeclarationAst.cast, CompositeTypeDeclarationAst.cast, TypesBlockAst.cast, GenericBlockDeclarationAst.cast, NamespaceDeclarationAst.cast);
|
|
165
|
-
function classifyDeclarationKeyword(input) {
|
|
166
|
-
const precedingDeclaration = input.node?.findAncestor(declarationCast);
|
|
167
|
-
const namespace = input.node?.findAncestor(NamespaceDeclarationAst.cast);
|
|
168
|
-
const inNamespaceBody = blockBodyContainsOffset(namespace, input.offset);
|
|
169
|
-
if (precedingDeclaration !== void 0 && !canCompleteDeclaration(precedingDeclaration, input.offset, inNamespaceBody)) return;
|
|
170
|
-
return {
|
|
171
|
-
kind: "declarationKeyword",
|
|
172
|
-
offset: input.offset,
|
|
173
|
-
scope: inNamespaceBody ? "namespace" : "document",
|
|
174
|
-
replacementStartOffset: input.replacementStartOffset
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Whether a new declaration can begin at the cursor, given the nearest enclosing
|
|
179
|
-
* declaration. Allowed when that declaration is still nascent (only its keyword
|
|
180
|
-
* typed, no name or body yet), when it is a namespace whose body holds further
|
|
181
|
-
* declarations, or when the cursor sits past its closing `}`.
|
|
182
|
-
*/
|
|
183
|
-
function canCompleteDeclaration(precedingDeclaration, offset, inNamespaceBody) {
|
|
184
|
-
if (precedingDeclaration.lbrace() === void 0 && (precedingDeclaration instanceof TypesBlockAst || precedingDeclaration.name() === void 0)) return true;
|
|
185
|
-
if (precedingDeclaration instanceof NamespaceDeclarationAst && inNamespaceBody) return true;
|
|
186
|
-
const rbrace = precedingDeclaration.rbrace();
|
|
187
|
-
return rbrace !== void 0 && offset >= rbrace.endOffset;
|
|
188
|
-
}
|
|
189
|
-
function blockBodyContainsOffset(block, offset) {
|
|
190
|
-
if (block === void 0) return false;
|
|
191
|
-
const lbrace = block.lbrace();
|
|
192
|
-
if (lbrace === void 0) return false;
|
|
193
|
-
const bodyStart = lbrace.endOffset;
|
|
194
|
-
const bodyEnd = block.rbrace()?.offset ?? block.syntax.endOffset;
|
|
195
|
-
return offset >= bodyStart && offset <= bodyEnd;
|
|
196
|
-
}
|
|
197
|
-
function classifyGenericBlockParameter(input) {
|
|
198
|
-
const node = input.at.leftBiased()?.parent;
|
|
199
|
-
const block = node?.findAncestor(GenericBlockDeclarationAst.cast);
|
|
200
|
-
if (block === void 0) return;
|
|
201
|
-
if (hasUnsupportedAncestor(node)) return UNSUPPORTED;
|
|
202
|
-
if (!blockBodyContainsOffset(block, input.offset)) return UNSUPPORTED;
|
|
203
|
-
if ((node?.findAncestor(FieldDeclarationAst.cast))?.syntax.isInside(input.offset)) return UNSUPPORTED;
|
|
204
|
-
const keyword = block.keyword()?.text;
|
|
205
|
-
if (keyword === void 0 || keyword.length === 0) return UNSUPPORTED;
|
|
206
|
-
if (input.precedingToken?.kind === "Equals") return {
|
|
207
|
-
kind: "genericBlockValue",
|
|
208
|
-
offset: input.offset,
|
|
209
|
-
blockKeyword: keyword,
|
|
210
|
-
replacementStartOffset: input.replacementStartOffset
|
|
211
|
-
};
|
|
212
|
-
const activePair = activeKeyValuePair(node, input.offset);
|
|
213
|
-
if (activePair !== void 0 && isAfterEquals(activePair, input.offset)) return UNSUPPORTED;
|
|
214
|
-
return {
|
|
215
|
-
kind: "genericBlockKey",
|
|
216
|
-
offset: input.offset,
|
|
217
|
-
blockKeyword: keyword,
|
|
218
|
-
replacementStartOffset: input.replacementStartOffset,
|
|
219
|
-
block
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function activeKeyValuePair(node, offset) {
|
|
223
|
-
const pair = node?.findAncestor(KeyValuePairAst.cast);
|
|
224
|
-
if (pair === void 0 || pair.syntax.isOutside(offset)) return;
|
|
225
|
-
return pair;
|
|
226
|
-
}
|
|
227
|
-
function isAfterEquals(pair, offset) {
|
|
228
|
-
const equals = pair.equals();
|
|
229
|
-
return equals !== void 0 && offset > equals.offset;
|
|
230
|
-
}
|
|
231
|
-
function hasUnsupportedAncestor(node) {
|
|
232
|
-
return node?.findAncestor(any(AttributeArgListAst.cast, FieldAttributeAst.cast, ModelAttributeAst.cast)) !== void 0;
|
|
233
|
-
}
|
|
234
|
-
/** The significant token preceding the cursor — the in-progress edit identifier
|
|
235
|
-
* is skipped, so the result is the token the classifier anchors on. */
|
|
236
|
-
function precedingToken(at, edit) {
|
|
237
|
-
const start = edit !== void 0 ? edit.prevToken : at.leftBiased();
|
|
238
|
-
return start === void 0 ? void 0 : skipTriviaToken(start, "prev");
|
|
239
|
-
}
|
|
240
|
-
/** The identifier token the cursor is editing, if any. */
|
|
241
|
-
function cursorIdentifier(at, offset) {
|
|
242
|
-
const right = at.rightBiased();
|
|
243
|
-
if (right?.kind === "Ident" && offset < right.endOffset) return right;
|
|
244
|
-
const left = at.leftBiased();
|
|
245
|
-
if (left?.kind === "Ident" && left.endOffset === offset) return left;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Presentation-level classification of a `types {}` binding: a
|
|
249
|
-
* non-constructor binding whose base is a configured scalar type refines that
|
|
250
|
-
* scalar (rendered as a default-library type); everything else reads as a
|
|
251
|
-
* plain alias. The authoritative scalar-or-not pronouncement lives in the
|
|
252
|
-
* interpreter's named-type resolution — this mirrors it for display only.
|
|
253
|
-
*/
|
|
254
|
-
function refinesScalarType(symbol, scalarTypes) {
|
|
255
|
-
return !symbol.isConstructor && symbol.baseType !== void 0 && scalarTypes.includes(symbol.baseType);
|
|
256
|
-
}
|
|
257
|
-
const categoryOrder = {
|
|
258
|
-
configuredScalar: 0,
|
|
259
|
-
topLevelModel: 1,
|
|
260
|
-
topLevelCompositeType: 2,
|
|
261
|
-
scalar: 3,
|
|
262
|
-
typeAlias: 4,
|
|
263
|
-
namespace: 5,
|
|
264
|
-
namespaceModel: 6,
|
|
265
|
-
namespaceCompositeType: 7
|
|
266
|
-
};
|
|
267
|
-
const declarationKeywordCategoryOrder = {
|
|
268
|
-
native: 0,
|
|
269
|
-
genericBlock: 1
|
|
270
|
-
};
|
|
271
|
-
const nameSnippetPlaceholder = "${1:Name}";
|
|
272
|
-
const documentNativeDeclarationKeywords = [
|
|
273
|
-
nativeDeclarationKeyword("model", "model ", `model ${nameSnippetPlaceholder} {\n $0\n}`),
|
|
274
|
-
nativeDeclarationKeyword("type", "type ", `type ${nameSnippetPlaceholder} {\n $0\n}`),
|
|
275
|
-
nativeDeclarationKeyword("types", "types ", "types {\n $0\n}"),
|
|
276
|
-
nativeDeclarationKeyword("namespace", "namespace ", `namespace \${1:name} {\n $0\n}`)
|
|
277
|
-
];
|
|
278
|
-
const namespaceNativeDeclarationKeywords = [nativeDeclarationKeyword("model", "model ", `model ${nameSnippetPlaceholder} {\n $0\n}`), nativeDeclarationKeyword("type", "type ", `type ${nameSnippetPlaceholder} {\n $0\n}`)];
|
|
279
|
-
function providePslCompletionItems(input) {
|
|
280
|
-
const { context } = input;
|
|
281
|
-
switch (context.kind) {
|
|
282
|
-
case "unsupported": return [];
|
|
283
|
-
case "spaceMember": return [];
|
|
284
|
-
case "genericBlockValue": return [];
|
|
285
|
-
case "declarationKeyword": return provideDeclarationKeywordCompletionItems(context, input.sourceFile, input.candidates, input.clientSupportsSnippets);
|
|
286
|
-
case "genericBlockKey": return provideGenericBlockKeyCompletionItems(context, input.sourceFile, input.candidates);
|
|
287
|
-
case "modelType": return provideModelTypeCompletionItems(context, input.sourceFile, input.candidates);
|
|
288
|
-
case "namespaceMember": return provideNamespaceMemberCompletionItems(context, input.sourceFile, input.candidates);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function provideDeclarationKeywordCompletionItems(context, sourceFile, source, clientSupportsSnippets) {
|
|
292
|
-
const replacementRange = {
|
|
293
|
-
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
294
|
-
end: sourceFile.positionAt(context.offset)
|
|
295
|
-
};
|
|
296
|
-
return declarationKeywordCandidates(context.scope, source).map((candidate) => ({
|
|
297
|
-
label: candidate.label,
|
|
298
|
-
kind: candidate.kind,
|
|
299
|
-
detail: candidate.detail,
|
|
300
|
-
sortText: declarationKeywordSortText(candidate),
|
|
301
|
-
filterText: candidate.label,
|
|
302
|
-
...clientSupportsSnippets ? { insertTextFormat: InsertTextFormat.Snippet } : {},
|
|
303
|
-
textEdit: {
|
|
304
|
-
range: replacementRange,
|
|
305
|
-
newText: clientSupportsSnippets ? candidate.snippetText : candidate.insertText
|
|
306
|
-
}
|
|
307
|
-
}));
|
|
308
|
-
}
|
|
309
|
-
function declarationKeywordCandidates(scope, source) {
|
|
310
|
-
return [...scope === "namespace" ? namespaceNativeDeclarationKeywords : documentNativeDeclarationKeywords, ...genericBlockDeclarationKeywordCandidates(source.pslBlockDescriptors)];
|
|
311
|
-
}
|
|
312
|
-
function nativeDeclarationKeyword(label, insertText, snippetText) {
|
|
313
|
-
return {
|
|
314
|
-
category: "native",
|
|
315
|
-
label,
|
|
316
|
-
insertText,
|
|
317
|
-
snippetText,
|
|
318
|
-
detail: "PSL declaration keyword",
|
|
319
|
-
kind: CompletionItemKind.Keyword
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
function genericBlockDeclarationKeywordCandidates(descriptors) {
|
|
323
|
-
return descriptorBlockKeywords(descriptors).map((keyword) => ({
|
|
324
|
-
category: "genericBlock",
|
|
325
|
-
label: keyword,
|
|
326
|
-
insertText: `${keyword} `,
|
|
327
|
-
snippetText: `${keyword} ${nameSnippetPlaceholder} {\n $0\n}`,
|
|
328
|
-
detail: "Generic block keyword",
|
|
329
|
-
kind: CompletionItemKind.Keyword
|
|
330
|
-
}));
|
|
331
|
-
}
|
|
332
|
-
function descriptorBlockKeywords(descriptors) {
|
|
333
|
-
const keywords = [];
|
|
334
|
-
collectDescriptorBlockKeywords(descriptors, keywords);
|
|
335
|
-
return sortedUnique(keywords);
|
|
336
|
-
}
|
|
337
|
-
function collectDescriptorBlockKeywords(descriptors, keywords) {
|
|
338
|
-
for (const value of Object.values(descriptors)) {
|
|
339
|
-
if (isAuthoringPslBlockDescriptor(value)) {
|
|
340
|
-
keywords.push(value.keyword);
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
collectDescriptorBlockKeywords(value, keywords);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function declarationKeywordSortText(candidate) {
|
|
347
|
-
return `${declarationKeywordCategoryOrder[candidate.category]}:${candidate.label}`;
|
|
348
|
-
}
|
|
349
|
-
function provideGenericBlockKeyCompletionItems(context, sourceFile, source) {
|
|
350
|
-
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
351
|
-
if (descriptor === void 0) return [];
|
|
352
|
-
const existing = existingGenericBlockParameterNames(context.block, context.offset);
|
|
353
|
-
const replacementRange = {
|
|
354
|
-
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
355
|
-
end: sourceFile.positionAt(context.offset)
|
|
356
|
-
};
|
|
357
|
-
return Object.keys(descriptor.parameters).filter((parameterName) => !existing.has(parameterName)).map((parameterName, index) => ({
|
|
358
|
-
label: parameterName,
|
|
359
|
-
kind: CompletionItemKind.Property,
|
|
360
|
-
detail: "Generic block parameter",
|
|
361
|
-
sortText: genericBlockParameterSortText(index, parameterName),
|
|
362
|
-
filterText: parameterName,
|
|
363
|
-
textEdit: {
|
|
364
|
-
range: replacementRange,
|
|
365
|
-
newText: parameterName
|
|
366
|
-
}
|
|
367
|
-
}));
|
|
368
|
-
}
|
|
369
|
-
function existingGenericBlockParameterNames(block, cursorOffset) {
|
|
370
|
-
const names = /* @__PURE__ */ new Set();
|
|
371
|
-
for (const entry of block.entries()) {
|
|
372
|
-
if (!entry.syntax.isOutside(cursorOffset)) continue;
|
|
373
|
-
const name = entry.key()?.name();
|
|
374
|
-
if (name !== void 0) names.add(name);
|
|
375
|
-
}
|
|
376
|
-
return names;
|
|
377
|
-
}
|
|
378
|
-
function provideModelTypeCompletionItems(context, sourceFile, source) {
|
|
379
|
-
return modelTypeCompletionItems(context, sourceFile, [
|
|
380
|
-
...configuredScalarCandidates(source.scalarTypes),
|
|
381
|
-
...topLevelSymbolCandidates(source.symbolTable, source.scalarTypes),
|
|
382
|
-
...allNamespaceCandidates(source.symbolTable)
|
|
383
|
-
]);
|
|
384
|
-
}
|
|
385
|
-
function provideNamespaceMemberCompletionItems(context, sourceFile, source) {
|
|
386
|
-
if (context.space !== void 0) return [];
|
|
387
|
-
return modelTypeCompletionItems(context, sourceFile, namespaceCandidates(source.symbolTable.topLevel.namespaces[context.namespace]));
|
|
388
|
-
}
|
|
389
|
-
function modelTypeCompletionItems(context, sourceFile, candidates) {
|
|
390
|
-
const replacementRange = {
|
|
391
|
-
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
392
|
-
end: sourceFile.positionAt(context.offset)
|
|
393
|
-
};
|
|
394
|
-
return candidates.map((candidate) => ({
|
|
395
|
-
label: candidate.label,
|
|
396
|
-
kind: candidate.kind,
|
|
397
|
-
detail: candidate.detail,
|
|
398
|
-
sortText: sortText(candidate),
|
|
399
|
-
filterText: candidate.filterText,
|
|
400
|
-
textEdit: {
|
|
401
|
-
range: replacementRange,
|
|
402
|
-
newText: candidate.insertText
|
|
403
|
-
}
|
|
404
|
-
}));
|
|
405
|
-
}
|
|
406
|
-
function configuredScalarCandidates(scalarTypes) {
|
|
407
|
-
return sortedUnique(scalarTypes).map((name) => ({
|
|
408
|
-
category: "configuredScalar",
|
|
409
|
-
label: name,
|
|
410
|
-
insertText: name,
|
|
411
|
-
filterText: name,
|
|
412
|
-
detail: "Configured scalar type",
|
|
413
|
-
kind: CompletionItemKind.Keyword
|
|
414
|
-
}));
|
|
415
|
-
}
|
|
416
|
-
function topLevelSymbolCandidates(symbolTable, scalarTypes) {
|
|
417
|
-
const { topLevel } = symbolTable;
|
|
418
|
-
const namedTypes = Object.values(topLevel.namedTypes);
|
|
419
|
-
const scalarRefinementNames = namedTypes.filter((symbol) => refinesScalarType(symbol, scalarTypes)).map((symbol) => symbol.name).sort(compareNames);
|
|
420
|
-
const aliasNames = namedTypes.filter((symbol) => !refinesScalarType(symbol, scalarTypes)).map((symbol) => symbol.name).sort(compareNames);
|
|
421
|
-
return [
|
|
422
|
-
...symbolCandidates(recordNames(topLevel.models), "topLevelModel", "Model", CompletionItemKind.Class),
|
|
423
|
-
...symbolCandidates(recordNames(topLevel.compositeTypes), "topLevelCompositeType", "Composite type", CompletionItemKind.Struct),
|
|
424
|
-
...symbolCandidates(scalarRefinementNames, "scalar", "Scalar type", CompletionItemKind.Unit),
|
|
425
|
-
...symbolCandidates(aliasNames, "typeAlias", "Type alias", CompletionItemKind.Reference)
|
|
426
|
-
];
|
|
427
|
-
}
|
|
428
|
-
function allNamespaceCandidates(symbolTable) {
|
|
429
|
-
return Object.values(symbolTable.topLevel.namespaces).sort((left, right) => compareNames(left.name, right.name)).map(namespaceQualifierCandidate);
|
|
430
|
-
}
|
|
431
|
-
function namespaceCandidates(namespace) {
|
|
432
|
-
if (namespace === void 0) return [];
|
|
433
|
-
return [...symbolCandidates(recordNames(namespace.models), "namespaceModel", `Model in namespace ${namespace.name}`, CompletionItemKind.Class), ...symbolCandidates(recordNames(namespace.compositeTypes), "namespaceCompositeType", `Composite type in namespace ${namespace.name}`, CompletionItemKind.Struct)];
|
|
434
|
-
}
|
|
435
|
-
function namespaceQualifierCandidate(namespace) {
|
|
436
|
-
return {
|
|
437
|
-
category: "namespace",
|
|
438
|
-
label: namespace.name,
|
|
439
|
-
insertText: namespace.name,
|
|
440
|
-
filterText: namespace.name,
|
|
441
|
-
detail: "Namespace",
|
|
442
|
-
kind: CompletionItemKind.Module
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
function symbolCandidates(names, category, detail, kind) {
|
|
446
|
-
return names.map((name) => ({
|
|
447
|
-
category,
|
|
448
|
-
label: name,
|
|
449
|
-
insertText: name,
|
|
450
|
-
filterText: name,
|
|
451
|
-
detail,
|
|
452
|
-
kind
|
|
453
|
-
}));
|
|
454
|
-
}
|
|
455
|
-
function recordNames(record) {
|
|
456
|
-
return Object.values(record).map((symbol) => symbol.name).sort(compareNames);
|
|
457
|
-
}
|
|
458
|
-
function sortedUnique(names) {
|
|
459
|
-
return [...new Set(names)].sort(compareNames);
|
|
460
|
-
}
|
|
461
|
-
function sortText(candidate) {
|
|
462
|
-
return `${categoryOrder[candidate.category]}:${candidate.label}`;
|
|
463
|
-
}
|
|
464
|
-
function genericBlockParameterSortText(index, label) {
|
|
465
|
-
return `${index.toString().padStart(4, "0")}:${label}`;
|
|
466
|
-
}
|
|
467
|
-
function compareNames(left, right) {
|
|
468
|
-
if (left < right) return -1;
|
|
469
|
-
if (left > right) return 1;
|
|
470
|
-
return 0;
|
|
471
|
-
}
|
|
472
|
-
function hasPslInputs(config) {
|
|
473
|
-
const source = config.contract?.source;
|
|
474
|
-
return source?.format === "psl" && source.inputs !== void 0;
|
|
475
|
-
}
|
|
476
|
-
function resolveSchemaInputs(config) {
|
|
477
|
-
const inputs = hasPslInputs(config) ? config.contract?.source.inputs : void 0;
|
|
478
|
-
const uris = new Set(inputs?.map((input) => pathToFileURL(input).toString()));
|
|
479
|
-
return {
|
|
480
|
-
includes: (uri) => uris.has(uri),
|
|
481
|
-
uris: () => uris
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
const CONFIG_FILENAME = "prisma.config.ts";
|
|
485
|
-
const emptyPipelineInputs = {
|
|
486
|
-
scalarTypes: [],
|
|
487
|
-
pslBlockDescriptors: {}
|
|
488
|
-
};
|
|
489
|
-
async function resolveConfigInputs(configPath) {
|
|
490
|
-
const loaded = await loadConfig(configPath);
|
|
491
|
-
if (!loaded.ok) throw loaded.failure;
|
|
492
|
-
const projectSections = requireConfigSections(loaded.value, ["contract", "formatter"]);
|
|
493
|
-
if (!projectSections.ok) throw projectSections.failure;
|
|
494
|
-
const config = projectSections.value;
|
|
495
|
-
const inputs = resolveSchemaInputs(config);
|
|
496
|
-
if (!hasPslInputs(config)) return {
|
|
497
|
-
inputs,
|
|
498
|
-
controlStack: emptyPipelineInputs,
|
|
499
|
-
...config.formatter === void 0 ? {} : { formatter: config.formatter }
|
|
500
|
-
};
|
|
501
|
-
const controlSections = requireConfigSections(loaded.value, [
|
|
502
|
-
"family",
|
|
503
|
-
"target",
|
|
504
|
-
"adapter",
|
|
505
|
-
"driver",
|
|
506
|
-
"extensions"
|
|
507
|
-
]);
|
|
508
|
-
if (!controlSections.ok) throw controlSections.failure;
|
|
509
|
-
const stack = createControlStack(config);
|
|
510
|
-
const interpretation = resolveInterpretation(config, stack, inputs);
|
|
511
|
-
return {
|
|
512
|
-
inputs,
|
|
513
|
-
controlStack: pipelineInputsFromStack(stack),
|
|
514
|
-
...config.formatter === void 0 ? {} : { formatter: config.formatter },
|
|
515
|
-
...interpretation === void 0 ? {} : { interpretation }
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function pipelineInputsFromStack(stack) {
|
|
519
|
-
return {
|
|
520
|
-
scalarTypes: [...stack.scalarTypes],
|
|
521
|
-
pslBlockDescriptors: stack.authoringContributions.pslBlockDescriptors
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
function resolveInterpretation(config, stack, inputs) {
|
|
525
|
-
const source = config.contract?.source;
|
|
526
|
-
if (source === void 0 || !hasPslInterpreter(source)) return;
|
|
527
|
-
return {
|
|
528
|
-
source,
|
|
529
|
-
context: {
|
|
530
|
-
composedExtensions: stack.extensions.map((p) => p.id),
|
|
531
|
-
composedExtensionContracts: stack.extensionContracts,
|
|
532
|
-
authoringContributions: stack.authoringContributions,
|
|
533
|
-
codecLookup: stack.codecLookup,
|
|
534
|
-
controlMutationDefaults: stack.controlMutationDefaults,
|
|
535
|
-
resolvedInputs: [...inputs.uris()],
|
|
536
|
-
capabilities: stack.capabilities
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Computes folding ranges for block declarations in a PSL document.
|
|
542
|
-
*
|
|
543
|
-
* Block types that produce folding ranges:
|
|
544
|
-
* - model (e.g., `model User { ... }`)
|
|
545
|
-
* - composite type (e.g., `type Address { ... }`)
|
|
546
|
-
* - namespace (e.g., `namespace billing { ... }`)
|
|
547
|
-
* - generic blocks (generator, datasource, extension blocks)
|
|
548
|
-
* - types block (e.g., `types { ... }`)
|
|
549
|
-
*
|
|
550
|
-
* The range spans from the line containing `{` to the line containing `}`.
|
|
551
|
-
*/
|
|
552
|
-
function computeFoldingRanges(document, sourceFile) {
|
|
553
|
-
const ranges = [];
|
|
554
|
-
collectFoldingRanges(document, sourceFile, ranges);
|
|
555
|
-
return ranges;
|
|
556
|
-
}
|
|
557
|
-
function collectFoldingRanges(document, sourceFile, ranges) {
|
|
558
|
-
for (const declaration of document.declarations()) {
|
|
559
|
-
addFoldingRange(declaration, sourceFile, ranges);
|
|
560
|
-
const namespace = NamespaceDeclarationAst.cast(declaration.syntax);
|
|
561
|
-
if (namespace !== void 0) for (const nested of namespace.declarations()) addFoldingRange(nested, sourceFile, ranges);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
function addFoldingRange(declaration, sourceFile, ranges) {
|
|
565
|
-
const lbrace = declaration.lbrace();
|
|
566
|
-
const rbrace = declaration.rbrace();
|
|
567
|
-
if (lbrace === void 0 || rbrace === void 0) return;
|
|
568
|
-
const startLine = sourceFile.positionAt(lbrace.offset).line;
|
|
569
|
-
const endLine = sourceFile.positionAt(rbrace.offset).line;
|
|
570
|
-
ranges.push({
|
|
571
|
-
startLine,
|
|
572
|
-
endLine,
|
|
573
|
-
kind: FoldingRangeKind.Region
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Wraps a connection so that an outbound call the client is no longer there to
|
|
578
|
-
* receive does nothing, instead of throwing at whoever made it.
|
|
579
|
-
*
|
|
580
|
-
* `vscode-jsonrpc` marks the connection closed the moment the input stream
|
|
581
|
-
* ends, and every send after that throws synchronously. A throw that escapes a
|
|
582
|
-
* notification handler ends the process: jsonrpc reports it through its logger,
|
|
583
|
-
* which is the connection's own remote console, so the report is another send —
|
|
584
|
-
* it throws again inside a `.catch()`, and the unhandled rejection is fatal.
|
|
585
|
-
*
|
|
586
|
-
* The wrapper carries the check so no individual send site has to: reads walk
|
|
587
|
-
* the connection's features (`console`, `languages`, …) and hand back guarded
|
|
588
|
-
* functions, so a send added later is guarded by construction. Only the
|
|
589
|
-
* connection's departure is swallowed — any other synchronous failure is a bug
|
|
590
|
-
* in the caller and still reaches it.
|
|
591
|
-
*/
|
|
592
|
-
function guardedConnection(connection) {
|
|
593
|
-
return guardCalls(connection);
|
|
594
|
-
}
|
|
595
|
-
function guardCalls(target) {
|
|
596
|
-
const guarded = /* @__PURE__ */ new Map();
|
|
597
|
-
return new Proxy(target, { get: (source, property) => {
|
|
598
|
-
const cached = guarded.get(property);
|
|
599
|
-
if (cached !== void 0) return cached;
|
|
600
|
-
const value = Reflect.get(source, property);
|
|
601
|
-
if (typeof value === "function") {
|
|
602
|
-
const call = (...args) => whileConnected(() => Reflect.apply(value, source, args));
|
|
603
|
-
guarded.set(property, call);
|
|
604
|
-
return call;
|
|
605
|
-
}
|
|
606
|
-
if (typeof value === "object" && value !== null) {
|
|
607
|
-
const feature = guardCalls(value);
|
|
608
|
-
guarded.set(property, feature);
|
|
609
|
-
return feature;
|
|
610
|
-
}
|
|
611
|
-
return value;
|
|
612
|
-
} });
|
|
613
|
-
}
|
|
614
|
-
function whileConnected(send) {
|
|
615
|
-
let sent;
|
|
616
|
-
try {
|
|
617
|
-
sent = send();
|
|
618
|
-
} catch (error) {
|
|
619
|
-
if (error instanceof ConnectionError) return Promise.resolve(void 0);
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
622
|
-
return isThenable(sent) ? sent.then(void 0, () => void 0) : sent;
|
|
623
|
-
}
|
|
624
|
-
function isThenable(value) {
|
|
625
|
-
return typeof value === "object" && value !== null && "then" in value && typeof Reflect.get(value, "then") === "function";
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Composes the stages exactly as the contract-psl provider does, so the editor
|
|
629
|
-
* and the build agree: `parse` then `buildSymbolTable`, parse diagnostics ahead
|
|
630
|
-
* of symbol-table diagnostics. Never throws on malformed input — `parse`
|
|
631
|
-
* recovers and `buildSymbolTable` is documented not to throw.
|
|
632
|
-
*/
|
|
633
|
-
function runPipeline(text, inputs) {
|
|
634
|
-
const { document, sourceFile, diagnostics: parseDiagnostics } = parse(text);
|
|
635
|
-
const { table: symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({
|
|
636
|
-
document,
|
|
637
|
-
sourceFile,
|
|
638
|
-
pslBlockDescriptors: inputs.pslBlockDescriptors
|
|
639
|
-
});
|
|
640
|
-
return {
|
|
641
|
-
document,
|
|
642
|
-
sourceFile,
|
|
643
|
-
symbolTable,
|
|
644
|
-
diagnostics: mapParseDiagnostics([...parseDiagnostics, ...symbolTableDiagnostics])
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* `null` (not a configured input) is distinct from a `DocumentDiagnostics` whose
|
|
649
|
-
* `diagnostics` are `[]` (an input that parsed clean): the caller treats both as
|
|
650
|
-
* "publish no diagnostics", but only the latter is a document we own and keep
|
|
651
|
-
* diagnosing.
|
|
652
|
-
*/
|
|
653
|
-
function computeDocumentDiagnostics(uri, text, inputs, controlStack) {
|
|
654
|
-
if (!inputs.includes(uri)) return null;
|
|
655
|
-
const { document, sourceFile, symbolTable, diagnostics } = runPipeline(text, controlStack);
|
|
656
|
-
return {
|
|
657
|
-
diagnostics,
|
|
658
|
-
document,
|
|
659
|
-
sourceFile,
|
|
660
|
-
symbolTable
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
function createProjectArtifacts(options) {
|
|
664
|
-
const { inputs, controlStack, getText, interpretation } = options;
|
|
665
|
-
const documents = /* @__PURE__ */ new Map();
|
|
666
|
-
let symbolTable;
|
|
667
|
-
function createInterpretSlot(uri, computed) {
|
|
668
|
-
if (interpretation === void 0) return () => [];
|
|
669
|
-
let memo;
|
|
670
|
-
return () => {
|
|
671
|
-
if (memo === void 0) {
|
|
672
|
-
const result = interpretation.source.interpret({
|
|
673
|
-
document: computed.document,
|
|
674
|
-
sourceFile: computed.sourceFile,
|
|
675
|
-
symbolTable: computed.symbolTable,
|
|
676
|
-
sourceId: uri
|
|
677
|
-
}, interpretation.context);
|
|
678
|
-
memo = mapInterpreterDiagnostics(result.ok ? [] : result.failure.diagnostics, computed.sourceFile);
|
|
679
|
-
}
|
|
680
|
-
return memo;
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
function drop(uri) {
|
|
684
|
-
if (documents.delete(uri)) symbolTable = void 0;
|
|
685
|
-
}
|
|
686
|
-
function readDocument(uri) {
|
|
687
|
-
const existing = documents.get(uri);
|
|
688
|
-
if (existing !== void 0) return existing;
|
|
689
|
-
const text = getText(uri);
|
|
690
|
-
if (text === void 0) return;
|
|
691
|
-
const computed = computeDocumentDiagnostics(uri, text, inputs, controlStack);
|
|
692
|
-
if (computed === null) return;
|
|
693
|
-
const artifacts = {
|
|
694
|
-
document: computed.document,
|
|
695
|
-
sourceFile: computed.sourceFile,
|
|
696
|
-
diagnostics: computed.diagnostics,
|
|
697
|
-
interpretDiagnostics: createInterpretSlot(uri, computed)
|
|
698
|
-
};
|
|
699
|
-
documents.set(uri, artifacts);
|
|
700
|
-
symbolTable = computed.symbolTable;
|
|
701
|
-
return artifacts;
|
|
702
|
-
}
|
|
703
|
-
return {
|
|
704
|
-
document: readDocument,
|
|
705
|
-
symbolTable: () => {
|
|
706
|
-
if (symbolTable !== void 0) return symbolTable;
|
|
707
|
-
for (const uri of inputs.uris()) {
|
|
708
|
-
const artifacts = readDocument(uri);
|
|
709
|
-
if (artifacts === void 0) continue;
|
|
710
|
-
symbolTable ??= buildSymbolTable({
|
|
711
|
-
document: artifacts.document,
|
|
712
|
-
sourceFile: artifacts.sourceFile,
|
|
713
|
-
pslBlockDescriptors: controlStack.pslBlockDescriptors
|
|
714
|
-
}).table;
|
|
715
|
-
return symbolTable;
|
|
716
|
-
}
|
|
717
|
-
throw new InternalError("invariant violated: project has no open configured input — the server must drop such projects");
|
|
718
|
-
},
|
|
719
|
-
documentChanged: drop,
|
|
720
|
-
documentClosed: drop
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
const semanticTokenTypes = [
|
|
724
|
-
SemanticTokenTypes.keyword,
|
|
725
|
-
SemanticTokenTypes.namespace,
|
|
726
|
-
SemanticTokenTypes.class,
|
|
727
|
-
SemanticTokenTypes.struct,
|
|
728
|
-
SemanticTokenTypes.type,
|
|
729
|
-
SemanticTokenTypes.property,
|
|
730
|
-
SemanticTokenTypes.decorator,
|
|
731
|
-
SemanticTokenTypes.string,
|
|
732
|
-
SemanticTokenTypes.number,
|
|
733
|
-
SemanticTokenTypes.comment
|
|
734
|
-
];
|
|
735
|
-
const semanticTokenModifiers = [SemanticTokenModifiers.declaration, SemanticTokenModifiers.defaultLibrary];
|
|
736
|
-
const semanticTokenModifierIndexes = {
|
|
737
|
-
declaration: 0,
|
|
738
|
-
defaultLibrary: 1
|
|
739
|
-
};
|
|
740
|
-
const semanticTokenModifierBits = {
|
|
741
|
-
declaration: 1 << semanticTokenModifierIndexes.declaration,
|
|
742
|
-
defaultLibrary: 1 << semanticTokenModifierIndexes.defaultLibrary
|
|
743
|
-
};
|
|
744
|
-
const semanticTokensLegend = {
|
|
745
|
-
tokenTypes: [...semanticTokenTypes],
|
|
746
|
-
tokenModifiers: [...semanticTokenModifiers]
|
|
747
|
-
};
|
|
748
|
-
function buildSemanticTokens(source, range) {
|
|
749
|
-
const builder = new SemanticTokensBuilder(source.sourceFile, range);
|
|
750
|
-
for (const token of collectSemanticTokenEvents(source)) builder.add(token);
|
|
751
|
-
return builder.build();
|
|
752
|
-
}
|
|
753
|
-
function collectSemanticTokenEvents(source) {
|
|
754
|
-
const comments = collectCommentTokens(source.document);
|
|
755
|
-
const tokens = [];
|
|
756
|
-
collectDeclarations(source, tokens);
|
|
757
|
-
return mergeSourceOrderedTokens(comments, tokens);
|
|
758
|
-
}
|
|
759
|
-
var SemanticTokensBuilder = class {
|
|
760
|
-
#data = [];
|
|
761
|
-
#sourceFile;
|
|
762
|
-
#rangeOffsets;
|
|
763
|
-
#previousLine = 0;
|
|
764
|
-
#previousCharacter = 0;
|
|
765
|
-
#first = true;
|
|
766
|
-
constructor(sourceFile, range) {
|
|
767
|
-
this.#sourceFile = sourceFile;
|
|
768
|
-
if (range !== void 0) {
|
|
769
|
-
const startOffset = sourceFile.offsetAt(range.start);
|
|
770
|
-
const endOffset = sourceFile.offsetAt(range.end);
|
|
771
|
-
this.#rangeOffsets = {
|
|
772
|
-
lower: Math.min(startOffset, endOffset),
|
|
773
|
-
upper: Math.max(startOffset, endOffset)
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
add(token) {
|
|
778
|
-
if (!this.#intersectsRange(token.startOffset, token.endOffset)) return;
|
|
779
|
-
if (token.splitMultiline) {
|
|
780
|
-
this.#addMultilineSplitToken(token);
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
this.#encode(token.startOffset, token.endOffset, token.tokenTypeIndex, token.modifierBitset);
|
|
784
|
-
}
|
|
785
|
-
build() {
|
|
786
|
-
return { data: this.#data };
|
|
787
|
-
}
|
|
788
|
-
#intersectsRange(startOffset, endOffset) {
|
|
789
|
-
const rangeOffsets = this.#rangeOffsets;
|
|
790
|
-
return rangeOffsets === void 0 || startOffset < rangeOffsets.upper && endOffset > rangeOffsets.lower;
|
|
791
|
-
}
|
|
792
|
-
#addMultilineSplitToken(token) {
|
|
793
|
-
const start = this.#sourceFile.positionAt(token.startOffset);
|
|
794
|
-
const end = this.#sourceFile.positionAt(token.endOffset);
|
|
795
|
-
if (start.line === end.line) {
|
|
796
|
-
this.#encode(token.startOffset, token.endOffset, token.tokenTypeIndex, token.modifierBitset);
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
for (let line = start.line; line <= end.line; line++) {
|
|
800
|
-
const startOffset = line === start.line ? token.startOffset : this.#sourceFile.lineStartOffset(line);
|
|
801
|
-
const endOffset = line === end.line ? token.endOffset : this.#sourceFile.lineEndOffset(line);
|
|
802
|
-
if (endOffset > startOffset && this.#intersectsRange(startOffset, endOffset)) this.#encode(startOffset, endOffset, token.tokenTypeIndex, token.modifierBitset);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
#encode(startOffset, endOffset, tokenTypeIndex, modifierBitset) {
|
|
806
|
-
const start = this.#sourceFile.positionAt(startOffset);
|
|
807
|
-
const deltaLine = this.#first ? start.line : start.line - this.#previousLine;
|
|
808
|
-
const deltaStart = this.#first || deltaLine !== 0 ? start.character : start.character - this.#previousCharacter;
|
|
809
|
-
this.#data.push(deltaLine, deltaStart, endOffset - startOffset, tokenTypeIndex, modifierBitset);
|
|
810
|
-
this.#previousLine = start.line;
|
|
811
|
-
this.#previousCharacter = start.character;
|
|
812
|
-
this.#first = false;
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
function collectCommentTokens(document) {
|
|
816
|
-
const tokens = [];
|
|
817
|
-
for (const token of document.syntax.tokens()) if (token.kind === "Comment") tokens.push(pendingTokenForToken(token, "comment"));
|
|
818
|
-
return tokens;
|
|
819
|
-
}
|
|
820
|
-
function collectDeclarations(source, tokens) {
|
|
821
|
-
for (const declaration of source.document.declarations()) collectDeclaration(declaration, source, tokens, void 0);
|
|
822
|
-
}
|
|
823
|
-
function collectDeclaration(declaration, source, tokens, namespace) {
|
|
824
|
-
if (declaration instanceof ModelDeclarationAst) {
|
|
825
|
-
addToken(declaration.keyword(), "keyword", tokens);
|
|
826
|
-
addIdentifier(declaration.name(), "class", tokens, semanticTokenModifierBits.declaration);
|
|
827
|
-
collectBlockMembers(declaration.members(), source, tokens, namespace);
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
if (declaration instanceof CompositeTypeDeclarationAst) {
|
|
831
|
-
addToken(declaration.keyword(), "keyword", tokens);
|
|
832
|
-
addIdentifier(declaration.name(), "struct", tokens, semanticTokenModifierBits.declaration);
|
|
833
|
-
collectBlockMembers(declaration.members(), source, tokens, namespace);
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
if (declaration instanceof NamespaceDeclarationAst) {
|
|
837
|
-
addToken(declaration.keyword(), "keyword", tokens);
|
|
838
|
-
addIdentifier(declaration.name(), "namespace", tokens, semanticTokenModifierBits.declaration);
|
|
839
|
-
const nestedNamespace = declaration.name()?.name();
|
|
840
|
-
for (const nested of declaration.declarations()) collectDeclaration(nested, source, tokens, nestedNamespace);
|
|
841
|
-
return;
|
|
842
|
-
}
|
|
843
|
-
if (declaration instanceof TypesBlockAst) {
|
|
844
|
-
addToken(declaration.keyword(), "keyword", tokens);
|
|
845
|
-
for (const namedType of declaration.declarations()) collectNamedTypeDeclaration(namedType, source, tokens, namespace);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
addToken(declaration.keyword(), "keyword", tokens);
|
|
849
|
-
addIdentifier(declaration.name(), "type", tokens, semanticTokenModifierBits.declaration);
|
|
850
|
-
collectGenericBlockMembers(declaration.members(), source, tokens, namespace);
|
|
851
|
-
}
|
|
852
|
-
function collectNamedTypeDeclaration(declaration, source, tokens, namespace) {
|
|
853
|
-
addIdentifier(declaration.name(), "type", tokens, semanticTokenModifierBits.declaration);
|
|
854
|
-
collectTypeAnnotation(declaration.typeAnnotation(), source, tokens, namespace);
|
|
855
|
-
collectAttributes(declaration.attributes(), source, tokens, namespace);
|
|
856
|
-
}
|
|
857
|
-
function collectGenericBlockMembers(members, source, tokens, namespace) {
|
|
858
|
-
for (const member of members) {
|
|
859
|
-
if ("key" in member) {
|
|
860
|
-
addIdentifier(member.key(), "property", tokens);
|
|
861
|
-
collectExpression(member.value(), source, tokens, namespace);
|
|
862
|
-
continue;
|
|
863
|
-
}
|
|
864
|
-
collectAttribute(member, source, tokens, namespace);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
function collectBlockMembers(members, source, tokens, namespace) {
|
|
868
|
-
for (const member of members) {
|
|
869
|
-
if (member instanceof FieldDeclarationAst) {
|
|
870
|
-
collectField(member, source, tokens, namespace);
|
|
871
|
-
continue;
|
|
872
|
-
}
|
|
873
|
-
collectAttribute(member, source, tokens, namespace);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
function collectField(field, source, tokens, namespace) {
|
|
877
|
-
addIdentifier(field.name(), "property", tokens, semanticTokenModifierBits.declaration);
|
|
878
|
-
collectTypeAnnotation(field.typeAnnotation(), source, tokens, namespace);
|
|
879
|
-
collectAttributes(field.attributes(), source, tokens, namespace);
|
|
880
|
-
}
|
|
881
|
-
function collectTypeAnnotation(annotation, source, tokens, namespace) {
|
|
882
|
-
if (annotation === void 0) return;
|
|
883
|
-
collectTypeReference(annotation.name(), source, tokens, namespace);
|
|
884
|
-
collectAttributeArgList(annotation.argList(), source, tokens, namespace);
|
|
885
|
-
}
|
|
886
|
-
function collectAttributes(attributes, source, tokens, namespace) {
|
|
887
|
-
for (const attribute of attributes) collectAttribute(attribute, source, tokens, namespace);
|
|
888
|
-
}
|
|
889
|
-
function collectAttribute(attribute, source, tokens, namespace) {
|
|
890
|
-
const marker = findChildToken(attribute.syntax, "At") ?? findChildToken(attribute.syntax, "DoubleAt");
|
|
891
|
-
collectDecoratorName(attribute.name(), marker, tokens);
|
|
892
|
-
collectAttributeArgList(attribute.argList(), source, tokens, namespace);
|
|
893
|
-
}
|
|
894
|
-
function collectDecoratorName(name, marker, tokens) {
|
|
895
|
-
if (name === void 0) return;
|
|
896
|
-
const segments = identifierSegments(name);
|
|
897
|
-
for (const [index, segment] of segments.entries()) tokens.push(rangeForDecoratorIdentifier(segment.identifier, index === 0 ? marker : void 0));
|
|
898
|
-
}
|
|
899
|
-
function collectAttributeArgList(argList, source, tokens, namespace) {
|
|
900
|
-
if (argList === void 0) return;
|
|
901
|
-
for (const arg of argList.args()) collectAttributeArg(arg, source, tokens, namespace);
|
|
902
|
-
}
|
|
903
|
-
function collectAttributeArg(arg, source, tokens, namespace) {
|
|
904
|
-
const name = arg.name();
|
|
905
|
-
addIdentifier(name, "property", tokens);
|
|
906
|
-
collectExpression(arg.value(), source, tokens, namespace, expressionContextForAttributeArg(name));
|
|
907
|
-
}
|
|
908
|
-
function collectExpression(expression, source, tokens, namespace, context = {}) {
|
|
909
|
-
if (expression === void 0) return;
|
|
910
|
-
if (expression instanceof StringLiteralExprAst) {
|
|
911
|
-
addToken(expression.token(), "string", tokens);
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
if (expression instanceof NumberLiteralExprAst) {
|
|
915
|
-
addToken(expression.token(), "number", tokens);
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
if (expression instanceof BooleanLiteralExprAst) {
|
|
919
|
-
addToken(expression.token(), "keyword", tokens);
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
if (expression instanceof FunctionCallAst) {
|
|
923
|
-
collectTypeReference(expression.name(), source, tokens, namespace);
|
|
924
|
-
for (const arg of expression.args()) collectAttributeArg(arg, source, tokens, namespace);
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
if (expression instanceof ArrayLiteralAst) {
|
|
928
|
-
for (const element of expression.elements()) collectExpression(element, source, tokens, namespace, context);
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
if (expression instanceof ObjectLiteralExprAst) {
|
|
932
|
-
for (const field of expression.fields()) {
|
|
933
|
-
addIdentifier(field.key(), "property", tokens);
|
|
934
|
-
collectExpression(field.value(), source, tokens, namespace);
|
|
935
|
-
}
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
collectIdentifierExpression(expression, source, tokens, namespace, context);
|
|
939
|
-
}
|
|
940
|
-
function collectIdentifierExpression(identifier, source, tokens, namespace, context) {
|
|
941
|
-
const text = identifier.name();
|
|
942
|
-
if (text === void 0) return;
|
|
943
|
-
const bareIdentifierTokenType = context.bareIdentifierTokenType;
|
|
944
|
-
if (bareIdentifierTokenType !== void 0) {
|
|
945
|
-
tokens.push(rangeForIdentifier(identifier, bareIdentifierTokenType));
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
const classification = classifyTypeReference([text], source, namespace);
|
|
949
|
-
tokens.push(rangeForIdentifier(identifier, classification.tokenType, classification.modifierBitset));
|
|
950
|
-
}
|
|
951
|
-
function expressionContextForAttributeArg(name) {
|
|
952
|
-
const argName = name?.name();
|
|
953
|
-
return argName === "fields" || argName === "references" ? { bareIdentifierTokenType: "property" } : {};
|
|
954
|
-
}
|
|
955
|
-
function collectTypeReference(name, source, tokens, namespace) {
|
|
956
|
-
if (name === void 0) return;
|
|
957
|
-
const segments = identifierSegments(name);
|
|
958
|
-
if (segments.length === 0) return;
|
|
959
|
-
const path = segments.map((segment) => segment.text);
|
|
960
|
-
for (const segment of segments.slice(0, -1)) if (isKnownNamespace(segment.text, source.symbolTable)) tokens.push(rangeForIdentifier(segment.identifier, "namespace"));
|
|
961
|
-
const finalSegment = segments[segments.length - 1];
|
|
962
|
-
if (finalSegment === void 0) return;
|
|
963
|
-
const classification = classifyTypeReference(path, source, namespace);
|
|
964
|
-
tokens.push(rangeForIdentifier(finalSegment.identifier, classification.tokenType, classification.modifierBitset));
|
|
965
|
-
}
|
|
966
|
-
function classifyTypeReference(path, source, namespace) {
|
|
967
|
-
const name = path[path.length - 1];
|
|
968
|
-
if (name === void 0) return { tokenType: "type" };
|
|
969
|
-
const table = source.symbolTable;
|
|
970
|
-
const namespaceName = path.length > 1 ? path[path.length - 2] : namespace;
|
|
971
|
-
const namespaceScope = namespaceName !== void 0 ? table.topLevel.namespaces[namespaceName] : void 0;
|
|
972
|
-
if (namespaceScope !== void 0) {
|
|
973
|
-
if (Object.hasOwn(namespaceScope.models, name)) return { tokenType: "class" };
|
|
974
|
-
if (Object.hasOwn(namespaceScope.compositeTypes, name)) return { tokenType: "struct" };
|
|
975
|
-
if (Object.hasOwn(namespaceScope.blocks, name)) return { tokenType: "type" };
|
|
976
|
-
}
|
|
977
|
-
if (Object.hasOwn(table.topLevel.models, name)) return { tokenType: "class" };
|
|
978
|
-
if (Object.hasOwn(table.topLevel.compositeTypes, name)) return { tokenType: "struct" };
|
|
979
|
-
const namedType = table.topLevel.namedTypes[name];
|
|
980
|
-
if (namedType !== void 0) return refinesScalarType(namedType, source.scalarTypes) ? {
|
|
981
|
-
tokenType: "type",
|
|
982
|
-
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
983
|
-
} : { tokenType: "type" };
|
|
984
|
-
if (Object.hasOwn(table.topLevel.blocks, name)) return { tokenType: "type" };
|
|
985
|
-
if (source.scalarTypes.includes(name)) return {
|
|
986
|
-
tokenType: "type",
|
|
987
|
-
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
988
|
-
};
|
|
989
|
-
return { tokenType: "type" };
|
|
990
|
-
}
|
|
991
|
-
function isKnownNamespace(name, table) {
|
|
992
|
-
return Object.hasOwn(table.topLevel.namespaces, name);
|
|
993
|
-
}
|
|
994
|
-
function identifierSegments(name) {
|
|
995
|
-
const segments = [];
|
|
996
|
-
for (const identifier of filterChildren(name.syntax, IdentifierAst.cast)) {
|
|
997
|
-
const text = identifier.name();
|
|
998
|
-
if (text !== void 0) segments.push({
|
|
999
|
-
identifier,
|
|
1000
|
-
text
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
return segments;
|
|
1004
|
-
}
|
|
1005
|
-
function addIdentifier(identifier, tokenType, tokens, modifierBitset = 0) {
|
|
1006
|
-
if (identifier === void 0) return;
|
|
1007
|
-
tokens.push(rangeForIdentifier(identifier, tokenType, modifierBitset));
|
|
1008
|
-
}
|
|
1009
|
-
function addToken(token, tokenType, tokens, modifierBitset = 0) {
|
|
1010
|
-
if (token === void 0) return;
|
|
1011
|
-
tokens.push(pendingTokenForToken(token, tokenType, modifierBitset));
|
|
1012
|
-
}
|
|
1013
|
-
function rangeForIdentifier(identifier, tokenType, modifierBitset = 0) {
|
|
1014
|
-
const token = identifier.token();
|
|
1015
|
-
if (token === void 0) return createPendingSemanticToken(identifier.syntax.offset, identifier.syntax.offset, tokenType, modifierBitset);
|
|
1016
|
-
return pendingTokenForToken(token, tokenType, modifierBitset);
|
|
1017
|
-
}
|
|
1018
|
-
function rangeForDecoratorIdentifier(identifier, marker) {
|
|
1019
|
-
const range = rangeForIdentifier(identifier, "decorator");
|
|
1020
|
-
if (marker === void 0 || marker.offset >= range.startOffset) return range;
|
|
1021
|
-
return createPendingSemanticToken(marker.offset, range.endOffset, "decorator", range.modifierBitset);
|
|
1022
|
-
}
|
|
1023
|
-
function pendingTokenForToken(token, tokenType, modifierBitset = 0) {
|
|
1024
|
-
return createPendingSemanticToken(token.offset, token.offset + token.text.length, tokenType, modifierBitset);
|
|
1025
|
-
}
|
|
1026
|
-
function mergeSourceOrderedTokens(left, right) {
|
|
1027
|
-
const result = [];
|
|
1028
|
-
let leftIndex = 0;
|
|
1029
|
-
let rightIndex = 0;
|
|
1030
|
-
while (leftIndex < left.length || rightIndex < right.length) {
|
|
1031
|
-
const leftToken = left[leftIndex];
|
|
1032
|
-
const rightToken = right[rightIndex];
|
|
1033
|
-
if (leftToken !== void 0 && (rightToken === void 0 || leftToken.startOffset <= rightToken.startOffset)) {
|
|
1034
|
-
result.push(leftToken);
|
|
1035
|
-
leftIndex++;
|
|
1036
|
-
} else if (rightToken !== void 0) {
|
|
1037
|
-
result.push(rightToken);
|
|
1038
|
-
rightIndex++;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
return result;
|
|
1042
|
-
}
|
|
1043
|
-
function createPendingSemanticToken(startOffset, endOffset, tokenType, modifierBitset = 0) {
|
|
1044
|
-
return {
|
|
1045
|
-
startOffset,
|
|
1046
|
-
endOffset,
|
|
1047
|
-
tokenTypeIndex: tokenTypeIndex(tokenType),
|
|
1048
|
-
modifierBitset,
|
|
1049
|
-
splitMultiline: tokenType === "string" || tokenType === "comment"
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
function tokenTypeIndex(tokenType) {
|
|
1053
|
-
return semanticTokenTypes.indexOf(tokenType);
|
|
1054
|
-
}
|
|
1055
|
-
/** The project a new load of this config could fall back to. */
|
|
1056
|
-
function lastGoodProject(entry) {
|
|
1057
|
-
if (entry === void 0 || entry.status === "failed") return;
|
|
1058
|
-
return entry.status === "loaded" ? entry.project : entry.lastGood;
|
|
1059
|
-
}
|
|
1060
|
-
const CONFIG_LOAD_FAILED_CODE = "PRISMA_NEXT_CONFIG_LOAD_FAILED";
|
|
1061
|
-
const semanticTokenSourceLimit = 1e5;
|
|
1062
|
-
function createServer(connection) {
|
|
1063
|
-
return createServerOn(guardedConnection(connection));
|
|
1064
|
-
}
|
|
1065
|
-
function createServerOn(connection) {
|
|
1066
|
-
const documents = new TextDocuments(TextDocument);
|
|
1067
|
-
const managedProjects = /* @__PURE__ */ new Map();
|
|
1068
|
-
const documentConfigPaths = /* @__PURE__ */ new Map();
|
|
1069
|
-
let rootPath = process.cwd();
|
|
1070
|
-
let watchedConfigGlob = join(rootPath, "**", CONFIG_FILENAME);
|
|
1071
|
-
let clientCapabilities = noClientCapabilities;
|
|
1072
|
-
function sendDiagnostics(params) {
|
|
1073
|
-
connection.sendDiagnostics(params);
|
|
1074
|
-
}
|
|
1075
|
-
function logWarn(message) {
|
|
1076
|
-
connection.console.warn(message);
|
|
1077
|
-
}
|
|
1078
|
-
async function publish(uri) {
|
|
1079
|
-
const project = await resolveProjectForDocument(uri);
|
|
1080
|
-
if (project === void 0) return;
|
|
1081
|
-
if (documents.get(uri) === void 0) {
|
|
1082
|
-
documentConfigPaths.delete(uri);
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
const artifacts = project.artifacts.document(uri);
|
|
1086
|
-
if (artifacts === void 0) {
|
|
1087
|
-
sendDiagnostics({
|
|
1088
|
-
uri,
|
|
1089
|
-
diagnostics: []
|
|
1090
|
-
});
|
|
1091
|
-
return;
|
|
1092
|
-
}
|
|
1093
|
-
sendDiagnostics({
|
|
1094
|
-
uri,
|
|
1095
|
-
diagnostics: combinedDiagnostics(artifacts)
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
function combinedDiagnostics(artifacts) {
|
|
1099
|
-
return toDiagnostics([...artifacts.diagnostics, ...artifacts.interpretDiagnostics()]);
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Project-scoped so a future multi-input symbol table can attach
|
|
1103
|
-
* `relatedDocuments` for cross-file effects.
|
|
1104
|
-
*/
|
|
1105
|
-
function buildDocumentDiagnosticReport(project, uri) {
|
|
1106
|
-
const artifacts = project.artifacts.document(uri);
|
|
1107
|
-
return {
|
|
1108
|
-
kind: DocumentDiagnosticReportKind.Full,
|
|
1109
|
-
items: artifacts === void 0 ? [] : combinedDiagnostics(artifacts)
|
|
1110
|
-
};
|
|
1111
|
-
}
|
|
1112
|
-
async function resolveProjectForDocument(uri) {
|
|
1113
|
-
const project = await projectForNearestConfig(uri);
|
|
1114
|
-
if (project === void 0 || project.inputs.includes(uri)) return project;
|
|
1115
|
-
documentConfigPaths.delete(uri);
|
|
1116
|
-
dropProjectWithoutManagedDocuments(project.configPath);
|
|
1117
|
-
}
|
|
1118
|
-
async function projectForNearestConfig(uri) {
|
|
1119
|
-
const knownConfigPath = documentConfigPaths.get(uri);
|
|
1120
|
-
if (knownConfigPath !== void 0) return resolveProjectIfLoadable(knownConfigPath);
|
|
1121
|
-
const filePath = filePathFromUri(uri);
|
|
1122
|
-
if (filePath === void 0) return;
|
|
1123
|
-
let configPath;
|
|
1124
|
-
try {
|
|
1125
|
-
configPath = await findNearestConfigPathForFile(filePath);
|
|
1126
|
-
} catch {
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
if (configPath === void 0) return;
|
|
1130
|
-
documentConfigPaths.set(uri, configPath);
|
|
1131
|
-
return resolveProjectIfLoadable(configPath);
|
|
1132
|
-
}
|
|
1133
|
-
async function resolveProjectIfLoadable(configPath) {
|
|
1134
|
-
try {
|
|
1135
|
-
return await resolveProject(configPath);
|
|
1136
|
-
} catch {
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
async function resolveProject(configPath) {
|
|
1141
|
-
const entry = managedProjects.get(configPath);
|
|
1142
|
-
if (entry === void 0 || entry.status === "failed") return startProjectLoad(configPath);
|
|
1143
|
-
return entry.status === "loaded" ? entry.project : entry.load;
|
|
1144
|
-
}
|
|
1145
|
-
function refreshProject(configPath) {
|
|
1146
|
-
return startProjectLoad(configPath);
|
|
1147
|
-
}
|
|
1148
|
-
function startProjectLoad(configPath) {
|
|
1149
|
-
const existing = managedProjects.get(configPath);
|
|
1150
|
-
const previousLoad = existing?.status === "loading" ? existing.load : void 0;
|
|
1151
|
-
const lastGood = lastGoodProject(existing);
|
|
1152
|
-
const load = (previousLoad ?? Promise.resolve(void 0)).catch(() => void 0).then(() => loadProject(configPath)).then((project) => {
|
|
1153
|
-
if (isCurrentLoad(configPath, load)) {
|
|
1154
|
-
if (hasManagedDocuments(configPath)) managedProjects.set(configPath, {
|
|
1155
|
-
status: "loaded",
|
|
1156
|
-
project
|
|
1157
|
-
});
|
|
1158
|
-
else managedProjects.delete(configPath);
|
|
1159
|
-
clearConfigFailure(configPath);
|
|
1160
|
-
}
|
|
1161
|
-
return project;
|
|
1162
|
-
}, (error) => {
|
|
1163
|
-
if (isCurrentLoad(configPath, load)) if (!hasManagedDocuments(configPath)) {
|
|
1164
|
-
managedProjects.delete(configPath);
|
|
1165
|
-
clearConfigFailure(configPath);
|
|
1166
|
-
} else {
|
|
1167
|
-
publishConfigFailure(configPath, error);
|
|
1168
|
-
if (lastGood !== void 0) {
|
|
1169
|
-
managedProjects.set(configPath, {
|
|
1170
|
-
status: "loaded",
|
|
1171
|
-
project: lastGood
|
|
1172
|
-
});
|
|
1173
|
-
return lastGood;
|
|
1174
|
-
}
|
|
1175
|
-
managedProjects.set(configPath, { status: "failed" });
|
|
1176
|
-
unmanageDocuments(configPath);
|
|
1177
|
-
}
|
|
1178
|
-
throw error;
|
|
1179
|
-
});
|
|
1180
|
-
managedProjects.set(configPath, {
|
|
1181
|
-
status: "loading",
|
|
1182
|
-
load,
|
|
1183
|
-
lastGood
|
|
1184
|
-
});
|
|
1185
|
-
return load;
|
|
1186
|
-
}
|
|
1187
|
-
function publishConfigFailure(configPath, error) {
|
|
1188
|
-
sendDiagnostics({
|
|
1189
|
-
uri: pathToFileURL(configPath).toString(),
|
|
1190
|
-
diagnostics: [{
|
|
1191
|
-
range: {
|
|
1192
|
-
start: {
|
|
1193
|
-
line: 0,
|
|
1194
|
-
character: 0
|
|
1195
|
-
},
|
|
1196
|
-
end: {
|
|
1197
|
-
line: 0,
|
|
1198
|
-
character: 1
|
|
1199
|
-
}
|
|
1200
|
-
},
|
|
1201
|
-
message: configFailureMessage(error),
|
|
1202
|
-
code: CONFIG_LOAD_FAILED_CODE,
|
|
1203
|
-
severity: DiagnosticSeverity.Error,
|
|
1204
|
-
source: "prisma-next"
|
|
1205
|
-
}]
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
function configFailureMessage(error) {
|
|
1209
|
-
if (CliStructuredError.is(error)) return error.why ?? error.message;
|
|
1210
|
-
return error instanceof Error ? error.message : String(error);
|
|
1211
|
-
}
|
|
1212
|
-
function clearConfigFailure(configPath) {
|
|
1213
|
-
sendDiagnostics({
|
|
1214
|
-
uri: pathToFileURL(configPath).toString(),
|
|
1215
|
-
diagnostics: []
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
function isCurrentLoad(configPath, load) {
|
|
1219
|
-
const entry = managedProjects.get(configPath);
|
|
1220
|
-
return entry?.status === "loading" && entry.load === load;
|
|
1221
|
-
}
|
|
1222
|
-
async function loadProject(configPath) {
|
|
1223
|
-
const resolution = await resolveConfigInputs(configPath);
|
|
1224
|
-
const artifacts = createProjectArtifacts({
|
|
1225
|
-
inputs: resolution.inputs,
|
|
1226
|
-
controlStack: resolution.controlStack,
|
|
1227
|
-
getText: (uri) => documents.get(uri)?.getText(),
|
|
1228
|
-
...resolution.interpretation === void 0 ? {} : { interpretation: resolution.interpretation }
|
|
1229
|
-
});
|
|
1230
|
-
return {
|
|
1231
|
-
configPath,
|
|
1232
|
-
inputs: resolution.inputs,
|
|
1233
|
-
controlStack: resolution.controlStack,
|
|
1234
|
-
artifacts,
|
|
1235
|
-
...resolution.formatter === void 0 ? {} : { formatter: resolution.formatter },
|
|
1236
|
-
...resolution.interpretation === void 0 ? {} : { interpretation: resolution.interpretation }
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
function unmanageDocuments(configPath) {
|
|
1240
|
-
for (const document of documents.all()) if (documentConfigPaths.get(document.uri) === configPath) documentConfigPaths.delete(document.uri);
|
|
1241
|
-
}
|
|
1242
|
-
async function republishOpenDocumentsForConfig(configPath) {
|
|
1243
|
-
for (const document of documents.all()) {
|
|
1244
|
-
if (documentConfigPaths.get(document.uri) === configPath) {
|
|
1245
|
-
if (await resolveProjectForDocument(document.uri) === void 0) {
|
|
1246
|
-
sendDiagnostics({
|
|
1247
|
-
uri: document.uri,
|
|
1248
|
-
diagnostics: []
|
|
1249
|
-
});
|
|
1250
|
-
continue;
|
|
1251
|
-
}
|
|
1252
|
-
await publish(document.uri);
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
const filePath = filePathFromUri(document.uri);
|
|
1256
|
-
if (filePath === void 0) continue;
|
|
1257
|
-
if (await findNearestConfigPathForFile(filePath) === configPath) {
|
|
1258
|
-
documentConfigPaths.set(document.uri, configPath);
|
|
1259
|
-
await publish(document.uri);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
function publishSafely(uri) {
|
|
1264
|
-
publish(uri).catch((error) => {
|
|
1265
|
-
connection.console.error(error instanceof Error ? error.message : String(error));
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
async function formatDocument(uri) {
|
|
1269
|
-
const document = documents.get(uri);
|
|
1270
|
-
if (document === void 0) return [];
|
|
1271
|
-
const project = await resolveProjectForDocument(uri);
|
|
1272
|
-
if (project === void 0) return [];
|
|
1273
|
-
const source = document.getText();
|
|
1274
|
-
let formatted;
|
|
1275
|
-
try {
|
|
1276
|
-
formatted = format(source, project.formatter);
|
|
1277
|
-
} catch {
|
|
1278
|
-
return [];
|
|
1279
|
-
}
|
|
1280
|
-
if (formatted === source) return [];
|
|
1281
|
-
return [{
|
|
1282
|
-
range: {
|
|
1283
|
-
start: {
|
|
1284
|
-
line: 0,
|
|
1285
|
-
character: 0
|
|
1286
|
-
},
|
|
1287
|
-
end: document.positionAt(source.length)
|
|
1288
|
-
},
|
|
1289
|
-
newText: formatted
|
|
1290
|
-
}];
|
|
1291
|
-
}
|
|
1292
|
-
async function semanticTokensForDocument(uri, range) {
|
|
1293
|
-
const document = documents.get(uri);
|
|
1294
|
-
if (document === void 0) return emptySemanticTokens();
|
|
1295
|
-
if (document.getText().length > semanticTokenSourceLimit) return emptySemanticTokens();
|
|
1296
|
-
const project = await resolveProjectForDocument(uri);
|
|
1297
|
-
if (project === void 0) return emptySemanticTokens();
|
|
1298
|
-
const artifacts = project.artifacts.document(uri);
|
|
1299
|
-
if (artifacts === void 0) return emptySemanticTokens();
|
|
1300
|
-
return buildSemanticTokens({
|
|
1301
|
-
document: artifacts.document,
|
|
1302
|
-
sourceFile: artifacts.sourceFile,
|
|
1303
|
-
symbolTable: project.artifacts.symbolTable(),
|
|
1304
|
-
scalarTypes: project.controlStack.scalarTypes
|
|
1305
|
-
}, range);
|
|
1306
|
-
}
|
|
1307
|
-
async function completeDocument(uri, position) {
|
|
1308
|
-
if (documents.get(uri) === void 0) return [];
|
|
1309
|
-
const project = await resolveProjectForDocument(uri);
|
|
1310
|
-
if (project === void 0) return [];
|
|
1311
|
-
const artifacts = project.artifacts.document(uri);
|
|
1312
|
-
if (artifacts === void 0) return [];
|
|
1313
|
-
try {
|
|
1314
|
-
return [...providePslCompletionItems({
|
|
1315
|
-
context: classifyPslCompletionContext({
|
|
1316
|
-
document: artifacts.document,
|
|
1317
|
-
sourceFile: artifacts.sourceFile,
|
|
1318
|
-
position
|
|
1319
|
-
}),
|
|
1320
|
-
sourceFile: artifacts.sourceFile,
|
|
1321
|
-
candidates: {
|
|
1322
|
-
scalarTypes: project.controlStack.scalarTypes,
|
|
1323
|
-
pslBlockDescriptors: project.controlStack.pslBlockDescriptors,
|
|
1324
|
-
symbolTable: project.artifacts.symbolTable()
|
|
1325
|
-
},
|
|
1326
|
-
clientSupportsSnippets: clientCapabilities.completionSnippets
|
|
1327
|
-
})];
|
|
1328
|
-
} catch {
|
|
1329
|
-
return [];
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
connection.onInitialize(async (params) => {
|
|
1333
|
-
rootPath = resolveRootPath(params);
|
|
1334
|
-
watchedConfigGlob = join(rootPath, "**", CONFIG_FILENAME);
|
|
1335
|
-
clientCapabilities = resolveClientCapabilities(params);
|
|
1336
|
-
return { capabilities: {
|
|
1337
|
-
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
1338
|
-
documentFormattingProvider: true,
|
|
1339
|
-
foldingRangeProvider: true,
|
|
1340
|
-
semanticTokensProvider: {
|
|
1341
|
-
legend: semanticTokensLegend,
|
|
1342
|
-
full: true,
|
|
1343
|
-
range: true
|
|
1344
|
-
},
|
|
1345
|
-
completionProvider: { triggerCharacters: ["."] },
|
|
1346
|
-
...clientCapabilities.pullDiagnostics ? { diagnosticProvider: {
|
|
1347
|
-
interFileDependencies: false,
|
|
1348
|
-
workspaceDiagnostics: false
|
|
1349
|
-
} } : {}
|
|
1350
|
-
} };
|
|
1351
|
-
});
|
|
1352
|
-
connection.onInitialized(() => {
|
|
1353
|
-
if (clientCapabilities.watchedFilesRegistration) connection.sendRequest(RegistrationRequest.type, { registrations: [{
|
|
1354
|
-
id: "prisma-8-config-watcher",
|
|
1355
|
-
method: DidChangeWatchedFilesNotification.type.method,
|
|
1356
|
-
registerOptions: { watchers: [{ globPattern: watchedConfigGlob }] }
|
|
1357
|
-
}] });
|
|
1358
|
-
else logWarn("Client does not support dynamic file-watcher registration; Prisma Next config changes will not be picked up without a restart.");
|
|
1359
|
-
});
|
|
1360
|
-
connection.onDidChangeWatchedFiles(async (params) => {
|
|
1361
|
-
const changedConfigPaths = configPathsFromWatchedChanges(params.changes.map((change) => filePathFromUri(change.uri)));
|
|
1362
|
-
for (const configPath of changedConfigPaths) {
|
|
1363
|
-
if (managedProjects.has(configPath)) try {
|
|
1364
|
-
await refreshProject(configPath);
|
|
1365
|
-
} catch {
|
|
1366
|
-
continue;
|
|
1367
|
-
}
|
|
1368
|
-
if (!clientCapabilities.pullDiagnostics) await republishOpenDocumentsForConfig(configPath);
|
|
1369
|
-
}
|
|
1370
|
-
if (clientCapabilities.pullDiagnostics && clientCapabilities.diagnosticsRefresh && changedConfigPaths.size > 0) connection.languages.diagnostics.refresh();
|
|
1371
|
-
});
|
|
1372
|
-
connection.onDocumentFormatting((params) => formatDocument(params.textDocument.uri));
|
|
1373
|
-
connection.onCompletion((params) => completeDocument(params.textDocument.uri, params.position));
|
|
1374
|
-
connection.languages.semanticTokens.on((params) => semanticTokensForDocument(params.textDocument.uri));
|
|
1375
|
-
connection.languages.semanticTokens.onRange((params) => semanticTokensForDocument(params.textDocument.uri, params.range));
|
|
1376
|
-
connection.languages.diagnostics.on(async (params) => {
|
|
1377
|
-
const project = await resolveProjectForDocument(params.textDocument.uri);
|
|
1378
|
-
if (project === void 0) return {
|
|
1379
|
-
kind: DocumentDiagnosticReportKind.Full,
|
|
1380
|
-
items: []
|
|
1381
|
-
};
|
|
1382
|
-
return buildDocumentDiagnosticReport(project, params.textDocument.uri);
|
|
1383
|
-
});
|
|
1384
|
-
connection.onFoldingRanges(async (params) => {
|
|
1385
|
-
const project = await resolveProjectForDocument(params.textDocument.uri);
|
|
1386
|
-
if (project === void 0) return [];
|
|
1387
|
-
const artifacts = project.artifacts.document(params.textDocument.uri);
|
|
1388
|
-
if (artifacts === void 0) return [];
|
|
1389
|
-
return computeFoldingRanges(artifacts.document, artifacts.sourceFile);
|
|
1390
|
-
});
|
|
1391
|
-
documents.onDidOpen((event) => {
|
|
1392
|
-
artifactsForDocument(event.document.uri)?.documentChanged(event.document.uri);
|
|
1393
|
-
if (clientCapabilities.pullDiagnostics) return;
|
|
1394
|
-
publishSafely(event.document.uri);
|
|
1395
|
-
});
|
|
1396
|
-
documents.onDidChangeContent((event) => {
|
|
1397
|
-
artifactsForDocument(event.document.uri)?.documentChanged(event.document.uri);
|
|
1398
|
-
if (clientCapabilities.pullDiagnostics) return;
|
|
1399
|
-
publishSafely(event.document.uri);
|
|
1400
|
-
});
|
|
1401
|
-
documents.onDidClose((event) => {
|
|
1402
|
-
const uri = event.document.uri;
|
|
1403
|
-
const configPath = documentConfigPaths.get(uri);
|
|
1404
|
-
artifactsForDocument(uri)?.documentClosed(uri);
|
|
1405
|
-
documentConfigPaths.delete(uri);
|
|
1406
|
-
if (configPath !== void 0) dropProjectWithoutManagedDocuments(configPath);
|
|
1407
|
-
if (!clientCapabilities.pullDiagnostics) sendDiagnostics({
|
|
1408
|
-
uri,
|
|
1409
|
-
diagnostics: []
|
|
1410
|
-
});
|
|
1411
|
-
});
|
|
1412
|
-
documents.listen(connection);
|
|
1413
|
-
connection.listen();
|
|
1414
|
-
function artifactsForDocument(uri) {
|
|
1415
|
-
const configPath = documentConfigPaths.get(uri);
|
|
1416
|
-
if (configPath === void 0) return;
|
|
1417
|
-
const entry = managedProjects.get(configPath);
|
|
1418
|
-
return entry?.status === "loaded" ? entry.project.artifacts : void 0;
|
|
1419
|
-
}
|
|
1420
|
-
function hasManagedDocuments(configPath) {
|
|
1421
|
-
for (const managedConfigPath of documentConfigPaths.values()) if (managedConfigPath === configPath) return true;
|
|
1422
|
-
return false;
|
|
1423
|
-
}
|
|
1424
|
-
function dropProjectWithoutManagedDocuments(configPath) {
|
|
1425
|
-
if (hasManagedDocuments(configPath)) return;
|
|
1426
|
-
const entry = managedProjects.get(configPath);
|
|
1427
|
-
if (entry === void 0 || entry.status === "loading") return;
|
|
1428
|
-
managedProjects.delete(configPath);
|
|
1429
|
-
clearConfigFailure(configPath);
|
|
1430
|
-
}
|
|
1431
|
-
return {
|
|
1432
|
-
dispose: () => connection.dispose(),
|
|
1433
|
-
getDocumentAst: (uri) => artifactsForDocument(uri)?.document(uri),
|
|
1434
|
-
getProjectSymbolTable: (uri) => artifactsForDocument(uri)?.symbolTable()
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
|
-
function emptySemanticTokens() {
|
|
1438
|
-
return { data: [] };
|
|
1439
|
-
}
|
|
1440
|
-
function toDiagnostics(computed) {
|
|
1441
|
-
return computed.map((diagnostic) => ({
|
|
1442
|
-
range: diagnostic.range,
|
|
1443
|
-
message: diagnostic.message,
|
|
1444
|
-
code: diagnostic.code,
|
|
1445
|
-
severity: toLspSeverity(diagnostic.severity),
|
|
1446
|
-
source: "prisma-next"
|
|
1447
|
-
}));
|
|
1448
|
-
}
|
|
1449
|
-
function toLspSeverity(severity) {
|
|
1450
|
-
switch (severity) {
|
|
1451
|
-
case ParseDiagnosticSeverity.Warning: return DiagnosticSeverity.Warning;
|
|
1452
|
-
case ParseDiagnosticSeverity.Information: return DiagnosticSeverity.Information;
|
|
1453
|
-
case ParseDiagnosticSeverity.Hint: return DiagnosticSeverity.Hint;
|
|
1454
|
-
default: return DiagnosticSeverity.Error;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
const noClientCapabilities = {
|
|
1458
|
-
watchedFilesRegistration: false,
|
|
1459
|
-
completionSnippets: false,
|
|
1460
|
-
pullDiagnostics: false,
|
|
1461
|
-
diagnosticsRefresh: false
|
|
1462
|
-
};
|
|
1463
|
-
function resolveClientCapabilities(params) {
|
|
1464
|
-
return {
|
|
1465
|
-
watchedFilesRegistration: params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true,
|
|
1466
|
-
completionSnippets: params.capabilities.textDocument?.completion?.completionItem?.snippetSupport === true,
|
|
1467
|
-
pullDiagnostics: params.capabilities.textDocument?.diagnostic !== void 0,
|
|
1468
|
-
diagnosticsRefresh: params.capabilities.workspace?.diagnostics?.refreshSupport === true
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
function resolveRootPath(params) {
|
|
1472
|
-
const workspaceFolder = params.workspaceFolders?.[0];
|
|
1473
|
-
if (workspaceFolder !== void 0) return fileURLToPath(workspaceFolder.uri);
|
|
1474
|
-
if (params.rootUri) return fileURLToPath(params.rootUri);
|
|
1475
|
-
if (params.rootPath) return params.rootPath;
|
|
1476
|
-
return process.cwd();
|
|
1477
|
-
}
|
|
1478
|
-
function filePathFromUri(uri) {
|
|
1479
|
-
try {
|
|
1480
|
-
return fileURLToPath(uri);
|
|
1481
|
-
} catch {
|
|
1482
|
-
return;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
function configPathsFromWatchedChanges(paths) {
|
|
1486
|
-
const configPaths = /* @__PURE__ */ new Set();
|
|
1487
|
-
for (const path of paths) if (path?.endsWith("prisma.config.ts")) configPaths.add(path);
|
|
1488
|
-
return configPaths;
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* `objectMode: false` is what makes this a byte stream rather than a stream of
|
|
1492
|
-
* whatever objects the host yielded: it converts each chunk to a `Buffer`.
|
|
1493
|
-
* `vscode-jsonrpc` needs that — it slices header blocks with
|
|
1494
|
-
* `Buffer.from(chunk, 0, length)`, and on a plain `Uint8Array` those arguments
|
|
1495
|
-
* are ignored, so it reads the whole chunk as one header block and rejects the
|
|
1496
|
-
* message.
|
|
1497
|
-
*/
|
|
1498
|
-
function byteInputStream(stdin) {
|
|
1499
|
-
return Readable.from(stdin, { objectMode: false });
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Bridges the byte stream `vscode-jsonrpc` writes to the text sink a host
|
|
1503
|
-
* hands over.
|
|
1504
|
-
*
|
|
1505
|
-
* LSP declares each message's `Content-Length` in bytes, so a UTF-8 sequence
|
|
1506
|
-
* that arrives split across two writes has to be held back until it is whole:
|
|
1507
|
-
* decoding half of one yields a replacement character, which is a different
|
|
1508
|
-
* number of bytes than the header promised. `StreamMessageWriter` writes each
|
|
1509
|
-
* body in one call and Node never splits a chunk given to `_write`, so the
|
|
1510
|
-
* decoder holds nothing back in practice — it is here because the contract
|
|
1511
|
-
* this satisfies is "bytes in, text out", and a writer that chunks its bodies
|
|
1512
|
-
* would otherwise corrupt every multi-byte message silently.
|
|
1513
|
-
*
|
|
1514
|
-
* Back-pressure is dropped: `TextSink.write` returns nothing to wait on, so
|
|
1515
|
-
* every write reports flushed the moment the sink has taken it. A client that
|
|
1516
|
-
* stops reading grows the host's own output queue instead of slowing the
|
|
1517
|
-
* server down, and the diagnostics for a large schema are not small. Fixing it
|
|
1518
|
-
* needs a sink that reports when it drained.
|
|
1519
|
-
*/
|
|
1520
|
-
function textOutputStream(stdout) {
|
|
1521
|
-
const decoder = new StringDecoder("utf8");
|
|
1522
|
-
return new Writable({
|
|
1523
|
-
write(chunk, _encoding, callback) {
|
|
1524
|
-
stdout.write(decoder.write(chunk));
|
|
1525
|
-
callback();
|
|
1526
|
-
},
|
|
1527
|
-
final(callback) {
|
|
1528
|
-
const pending = decoder.end();
|
|
1529
|
-
if (pending !== "") stdout.write(pending);
|
|
1530
|
-
callback();
|
|
1531
|
-
}
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Sends everything written through the global `console` to the host's stderr
|
|
1536
|
-
* for the length of the run, and returns the undo.
|
|
1537
|
-
*
|
|
1538
|
-
* The client owns stdout: anything on it that is not a `Content-Length` frame
|
|
1539
|
-
* desynchronises the client for good. `console.log` and friends write straight
|
|
1540
|
-
* to the process's own stdout, so one call from anywhere in the dependency
|
|
1541
|
-
* graph — resolving a project's config reaches c12 and jiti — corrupts the
|
|
1542
|
-
* protocol. `vscode-languageserver/node` redirects the console for exactly
|
|
1543
|
-
* this reason when it takes stdio off `process.argv`; over injected streams
|
|
1544
|
-
* that never runs, so the redirect happens here.
|
|
1545
|
-
*
|
|
1546
|
-
* A dependency that writes to `process.stdout` directly still reaches the
|
|
1547
|
-
* client. Nothing short of replacing the process's own descriptor covers that,
|
|
1548
|
-
* and only the host owns the process.
|
|
1549
|
-
*/
|
|
1550
|
-
function captureConsole(stderr) {
|
|
1551
|
-
const host = globalThis.console;
|
|
1552
|
-
const sink = textOutputStream(stderr);
|
|
1553
|
-
globalThis.console = new Console({
|
|
1554
|
-
stdout: sink,
|
|
1555
|
-
stderr: sink
|
|
1556
|
-
});
|
|
1557
|
-
return () => {
|
|
1558
|
-
globalThis.console = host;
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* How long the conversation may stand completely still before a message the
|
|
1563
|
-
* connection took off the reader but never dispatched is written off. It
|
|
1564
|
-
* answers a cancellation itself without telling anyone, so the count of
|
|
1565
|
-
* messages awaiting dispatch can be left standing; every other route decrements
|
|
1566
|
-
* it. Any activity restarts the clock, so this delays the exit rather than
|
|
1567
|
-
* cutting a reply short.
|
|
1568
|
-
*/
|
|
1569
|
-
const stalledDispatchGraceMs = 50;
|
|
1570
|
-
/**
|
|
1571
|
-
* How long a host abort lets in-flight work drain before the run settles
|
|
1572
|
-
* regardless. The host has already decided to stop, so a handler that never
|
|
1573
|
-
* settles — or work that never goes idle — must not hold the exit code back
|
|
1574
|
-
* forever; it only gets this long to finish cleanly.
|
|
1575
|
-
*/
|
|
1576
|
-
const abortDrainDeadlineMs = 2e3;
|
|
1577
|
-
/**
|
|
1578
|
-
* How often the client's process id is polled when the host handed one over.
|
|
1579
|
-
* The same cadence `vscode-languageserver/node` uses for its own watch.
|
|
1580
|
-
*/
|
|
1581
|
-
const clientProcessPollMs = 3e3;
|
|
1582
|
-
function processAlive(pid) {
|
|
1583
|
-
try {
|
|
1584
|
-
process.kill(pid, 0);
|
|
1585
|
-
return true;
|
|
1586
|
-
} catch {
|
|
1587
|
-
return false;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Runs the server over the host's streams and resolves with the exit code the
|
|
1592
|
-
* client's departure implies. The host owns the process, so nothing here ends
|
|
1593
|
-
* it; every route out settles the promise instead.
|
|
1594
|
-
*/
|
|
1595
|
-
function runServerOverStreams(streams) {
|
|
1596
|
-
const input = byteInputStream(streams.stdin);
|
|
1597
|
-
const inputMessages = new StreamMessageReader(input);
|
|
1598
|
-
const outputMessages = new StreamMessageWriter(textOutputStream(streams.stdout));
|
|
1599
|
-
const releaseConsole = captureConsole(streams.stderr);
|
|
1600
|
-
return new Promise((resolve) => {
|
|
1601
|
-
let settled = false;
|
|
1602
|
-
/**
|
|
1603
|
-
* Messages the connection is handling and replies it is writing. A request
|
|
1604
|
-
* handler's dispatch covers everything it awaits and the write of its
|
|
1605
|
-
* reply, so this stays above zero for as long as the client is owed
|
|
1606
|
-
* anything.
|
|
1607
|
-
*/
|
|
1608
|
-
let inFlight = 0;
|
|
1609
|
-
/** Messages decoded off the stream that the connection has not started. */
|
|
1610
|
-
let awaitingDispatch = 0;
|
|
1611
|
-
let lastActivity = Date.now();
|
|
1612
|
-
let departure;
|
|
1613
|
-
let idleCheck;
|
|
1614
|
-
let abortDeadline;
|
|
1615
|
-
let clientWatch;
|
|
1616
|
-
function settle(code) {
|
|
1617
|
-
if (settled) return;
|
|
1618
|
-
settled = true;
|
|
1619
|
-
if (idleCheck !== void 0) clearTimeout(idleCheck);
|
|
1620
|
-
if (abortDeadline !== void 0) clearTimeout(abortDeadline);
|
|
1621
|
-
if (clientWatch !== void 0) clearInterval(clientWatch);
|
|
1622
|
-
releaseConsole();
|
|
1623
|
-
server.dispose();
|
|
1624
|
-
input.destroy();
|
|
1625
|
-
resolve(code);
|
|
1626
|
-
}
|
|
1627
|
-
function moved() {
|
|
1628
|
-
lastActivity = Date.now();
|
|
1629
|
-
checkIdle();
|
|
1630
|
-
}
|
|
1631
|
-
/**
|
|
1632
|
-
* Settles once nothing is left in flight. The client's departure is not the
|
|
1633
|
-
* end of the work: everything already read is queued, and a handler that
|
|
1634
|
-
* awaits — resolving a project reads the filesystem — has its reply written
|
|
1635
|
-
* turns later.
|
|
1636
|
-
*/
|
|
1637
|
-
function settleOnceIdle(code) {
|
|
1638
|
-
departure ??= code;
|
|
1639
|
-
checkIdle();
|
|
1640
|
-
}
|
|
1641
|
-
function checkIdle() {
|
|
1642
|
-
if (settled || departure === void 0 || idleCheck !== void 0) return;
|
|
1643
|
-
idleCheck = setTimeout(() => {
|
|
1644
|
-
idleCheck = void 0;
|
|
1645
|
-
if (settled || departure === void 0) return;
|
|
1646
|
-
if (inFlight > 0) return;
|
|
1647
|
-
if (awaitingDispatch === 0 || Date.now() - lastActivity >= stalledDispatchGraceMs) {
|
|
1648
|
-
settle(departure());
|
|
1649
|
-
return;
|
|
1650
|
-
}
|
|
1651
|
-
checkIdle();
|
|
1652
|
-
}, 1);
|
|
1653
|
-
}
|
|
1654
|
-
/** LSP reserves 0 for a client that asked to shut down before leaving. */
|
|
1655
|
-
function departureCode() {
|
|
1656
|
-
return watchDog.shutdownReceived ? 0 : 1;
|
|
1657
|
-
}
|
|
1658
|
-
const reader = {
|
|
1659
|
-
onError: inputMessages.onError,
|
|
1660
|
-
onClose: inputMessages.onClose,
|
|
1661
|
-
onPartialMessage: inputMessages.onPartialMessage,
|
|
1662
|
-
listen: (callback) => inputMessages.listen((message) => {
|
|
1663
|
-
awaitingDispatch += 1;
|
|
1664
|
-
moved();
|
|
1665
|
-
callback(message);
|
|
1666
|
-
}),
|
|
1667
|
-
dispose: () => inputMessages.dispose()
|
|
1668
|
-
};
|
|
1669
|
-
const writer = {
|
|
1670
|
-
onError: outputMessages.onError,
|
|
1671
|
-
onClose: outputMessages.onClose,
|
|
1672
|
-
write: (message) => {
|
|
1673
|
-
inFlight += 1;
|
|
1674
|
-
moved();
|
|
1675
|
-
return outputMessages.write(message).finally(() => {
|
|
1676
|
-
inFlight -= 1;
|
|
1677
|
-
moved();
|
|
1678
|
-
});
|
|
1679
|
-
},
|
|
1680
|
-
end: () => outputMessages.end(),
|
|
1681
|
-
dispose: () => outputMessages.dispose()
|
|
1682
|
-
};
|
|
1683
|
-
const watchDog = {
|
|
1684
|
-
shutdownReceived: false,
|
|
1685
|
-
initialize: () => void 0,
|
|
1686
|
-
exit: (code) => settleOnceIdle(() => code)
|
|
1687
|
-
};
|
|
1688
|
-
const server = createServer(createConnection((logger) => createProtocolConnection(reader, writer, logger, { messageStrategy: { handleMessage: (message, next) => {
|
|
1689
|
-
awaitingDispatch -= 1;
|
|
1690
|
-
inFlight += 1;
|
|
1691
|
-
moved();
|
|
1692
|
-
return Promise.resolve(next(message)).finally(() => {
|
|
1693
|
-
inFlight -= 1;
|
|
1694
|
-
moved();
|
|
1695
|
-
});
|
|
1696
|
-
} } }), watchDog, ProposedFeatures.all));
|
|
1697
|
-
inputMessages.onClose(() => settleOnceIdle(departureCode));
|
|
1698
|
-
inputMessages.onError((error) => {
|
|
1699
|
-
streams.stderr.write(`Language server transport error: ${messageOf(error)}\n`);
|
|
1700
|
-
settleOnceIdle(() => 1);
|
|
1701
|
-
});
|
|
1702
|
-
const clientProcessId = streams.clientProcessId;
|
|
1703
|
-
if (clientProcessId !== void 0) {
|
|
1704
|
-
const settleIfClientGone = () => {
|
|
1705
|
-
if (!processAlive(clientProcessId)) settle(departureCode());
|
|
1706
|
-
};
|
|
1707
|
-
clientWatch = setInterval(settleIfClientGone, clientProcessPollMs);
|
|
1708
|
-
clientWatch.unref();
|
|
1709
|
-
settleIfClientGone();
|
|
1710
|
-
}
|
|
1711
|
-
function settleOnAbort() {
|
|
1712
|
-
settleOnceIdle(departureCode);
|
|
1713
|
-
abortDeadline ??= setTimeout(() => settle(departureCode()), abortDrainDeadlineMs);
|
|
1714
|
-
abortDeadline.unref();
|
|
1715
|
-
}
|
|
1716
|
-
const hostShutdown = streams.signal;
|
|
1717
|
-
if (hostShutdown?.aborted === true) settleOnAbort();
|
|
1718
|
-
else hostShutdown?.addEventListener("abort", settleOnAbort, { once: true });
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
function messageOf(error) {
|
|
1722
|
-
return error instanceof Error ? error.message : String(error);
|
|
1723
|
-
}
|
|
1724
|
-
function startServer(streams) {
|
|
1725
|
-
if (streams === void 0) {
|
|
1726
|
-
createServer(createConnection$1(ProposedFeatures$1.all));
|
|
1727
|
-
return;
|
|
1728
|
-
}
|
|
1729
|
-
return runServerOverStreams(streams);
|
|
1730
|
-
}
|
|
1731
|
-
//#endregion
|
|
1732
|
-
export { startServer };
|
|
1733
|
-
|
|
1734
|
-
//# sourceMappingURL=exports-8ZUN43ve.mjs.map
|