@prisma/orm-toolchain 8.0.0-rc.14-dev.13 → 8.0.0-rc.14-dev.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-telemetry.mjs +1 -1
- package/dist/cli.mjs +6 -6
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.mjs +1 -1
- package/dist/cli__migration-cli.mjs +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{domain-type-generation-DBIqOo-2-B_8sNhjJ.mjs → domain-type-generation-DFasK1Cx-DT41XFXn.mjs} +10 -10
- package/dist/domain-type-generation-DFasK1Cx-DT41XFXn.mjs.map +1 -0
- package/dist/emitter.mjs +2 -2
- package/dist/emitter__domain-type-generation.mjs +1 -1
- package/dist/{exports-DXfgwE62-BmuNqWBQ.mjs → exports-B41NJHCo-BaEu3TXy.mjs} +3 -3
- package/dist/{exports-DXfgwE62-BmuNqWBQ.mjs.map → exports-B41NJHCo-BaEu3TXy.mjs.map} +1 -1
- package/dist/{exports-CkefqB5C.mjs → exports-Ca10vlXU.mjs} +2 -2
- package/dist/{exports-CkefqB5C.mjs.map → exports-Ca10vlXU.mjs.map} +1 -1
- package/dist/{exports-Czk5PRpV.mjs → exports-F_cSTVqK.mjs} +261 -307
- package/dist/exports-F_cSTVqK.mjs.map +1 -0
- package/dist/{ref-BLBgE_oK-CrUDNhYI.mjs → ref-BLBgE_oK-CYZXibbI.mjs} +3 -3
- package/dist/{ref-BLBgE_oK-CrUDNhYI.mjs.map → ref-BLBgE_oK-CYZXibbI.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +3 -3
- package/package.json +12 -12
- package/dist/domain-type-generation-DBIqOo-2-B_8sNhjJ.mjs.map +0 -1
- package/dist/exports-Czk5PRpV.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as requireConfigSections, i as expandContractInputs, l as loadConfig, o as findNearestConfigPathForFile } from "./exports-
|
|
1
|
+
import { h as requireConfigSections, i as expandContractInputs, l as loadConfig, o as findNearestConfigPathForFile } from "./exports-Ca10vlXU.mjs";
|
|
2
2
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
3
3
|
import { createControlStack } from "@prisma/orm-framework/components/control";
|
|
4
4
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
@@ -8,12 +8,12 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
8
8
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
9
|
import { normalize as normalize$1 } from "node:path";
|
|
10
10
|
import { format } from "@prisma/orm-framework/psl-parser/format";
|
|
11
|
-
import { assembleAttributeSpecs, blockSpecFactoryOf, buildSymbolTable, findBlockDescriptor, isPrismaNextSchema, renameLegacyDirective } from "@prisma/orm-framework/psl-parser";
|
|
11
|
+
import { assembleAttributeSpecs, blockSpecFactoryOf, buildSymbolTable, createBinder, entityReference, findBlockDescriptor, isNamespaceLike, isPrismaNextSchema, matchesSelector, memberEntries, renameLegacyDirective, typeReferenceNode } from "@prisma/orm-framework/psl-parser";
|
|
12
12
|
import { CompletionItemKind, CompletionItemTag, ConnectionError, ConnectionErrors, DiagnosticSeverity, DidChangeWatchedFilesNotification, DocumentDiagnosticReportKind, FoldingRangeKind, InsertTextFormat, LSPErrorCodes, MarkupKind, ProposedFeatures, RegistrationRequest, ResponseError, SemanticTokenModifiers, SemanticTokenTypes, TextDocumentSyncKind, createConnection } from "vscode-languageserver";
|
|
13
13
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
14
|
-
import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PathExprAst, PslSources, StringLiteralExprAst, SyntaxNode, TaggedLiteralExprAst, TypesBlockAst, any,
|
|
14
|
+
import { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectLiteralExprAst, PathExprAst, PslSources, StringLiteralExprAst, SyntaxNode, TaggedLiteralExprAst, TypesBlockAst, any, isTrivia, nonTriviaSibling, parse, skipTriviaToken } from "@prisma/orm-framework/psl-parser/syntax";
|
|
15
15
|
import { hasPslInterpreter } from "@prisma/orm-framework/psl-parser/interpret";
|
|
16
|
-
import { isAuthoringPslBlockDescriptor
|
|
16
|
+
import { isAuthoringPslBlockDescriptor } from "@prisma/orm-framework/components/authoring";
|
|
17
17
|
import { ProposedFeatures as ProposedFeatures$1, StreamMessageReader, StreamMessageWriter, createConnection as createConnection$1, createProtocolConnection } from "vscode-languageserver/node";
|
|
18
18
|
import { Console } from "node:console";
|
|
19
19
|
import { Readable, Writable } from "node:stream";
|
|
@@ -494,6 +494,7 @@ function classifyModelFieldType(input) {
|
|
|
494
494
|
if (typeAnnotation === void 0) {
|
|
495
495
|
if (input.precedingToken !== void 0 && fieldName.syntax.isInside(input.precedingToken.offset)) return {
|
|
496
496
|
kind: "modelType",
|
|
497
|
+
field: input.field,
|
|
497
498
|
offset: input.offset,
|
|
498
499
|
fieldName: fieldNameText,
|
|
499
500
|
replacementStartOffset: input.offset
|
|
@@ -506,7 +507,7 @@ function classifyModelFieldType(input) {
|
|
|
506
507
|
if (name === void 0) return UNSUPPORTED;
|
|
507
508
|
if (name.syntax.isOutside(input.offset)) return UNSUPPORTED;
|
|
508
509
|
if (name.isOverQualified()) return UNSUPPORTED;
|
|
509
|
-
return classifyTypePosition(name, input.offset, fieldNameText, input.replacementStartOffset);
|
|
510
|
+
return classifyTypePosition(name, input.field, input.offset, fieldNameText, input.replacementStartOffset);
|
|
510
511
|
}
|
|
511
512
|
/**
|
|
512
513
|
* Builds the type-completion context for a qualified name. Roles are read
|
|
@@ -520,12 +521,13 @@ function classifyModelFieldType(input) {
|
|
|
520
521
|
* carries no populated segment and resolves to `modelType` rather than
|
|
521
522
|
* `unsupported`.
|
|
522
523
|
*/
|
|
523
|
-
function classifyTypePosition(name, offset, fieldName, replacementStartOffset) {
|
|
524
|
+
function classifyTypePosition(name, field, offset, fieldName, replacementStartOffset) {
|
|
524
525
|
const namespace = name.namespace()?.name();
|
|
525
526
|
if (namespace !== void 0 && namespace.length > 0) {
|
|
526
527
|
const namespaceSpace = name.space()?.name();
|
|
527
528
|
return {
|
|
528
529
|
kind: "namespaceMember",
|
|
530
|
+
field,
|
|
529
531
|
offset,
|
|
530
532
|
fieldName,
|
|
531
533
|
replacementStartOffset,
|
|
@@ -543,6 +545,7 @@ function classifyTypePosition(name, offset, fieldName, replacementStartOffset) {
|
|
|
543
545
|
};
|
|
544
546
|
return {
|
|
545
547
|
kind: "modelType",
|
|
548
|
+
field,
|
|
546
549
|
offset,
|
|
547
550
|
fieldName,
|
|
548
551
|
replacementStartOffset
|
|
@@ -850,107 +853,12 @@ function cursorIdentifier(at, offset) {
|
|
|
850
853
|
const left = at.leftBiased();
|
|
851
854
|
if (left?.kind === "Ident" && left.endOffset === offset) return left;
|
|
852
855
|
}
|
|
853
|
-
/**
|
|
854
|
-
* Presentation-level classification of a `types {}` binding: a
|
|
855
|
-
* non-constructor binding whose base is a configured scalar type refines that
|
|
856
|
-
* scalar (rendered as a default-library type); everything else reads as a
|
|
857
|
-
* plain alias. The authoritative scalar-or-not pronouncement lives in the
|
|
858
|
-
* interpreter's named-type resolution — this mirrors it for display only.
|
|
859
|
-
*/
|
|
860
|
-
function refinesScalarType(symbol, scalarTypes) {
|
|
861
|
-
return !symbol.isConstructor && symbol.baseType !== void 0 && scalarTypes.includes(symbol.baseType);
|
|
862
|
-
}
|
|
863
|
-
function modelSymbolForNode(symbolTable, node) {
|
|
864
|
-
const topLevelMatch = Object.values(symbolTable.topLevel.models).find((model) => sameSyntax(model.node.syntax, node.syntax));
|
|
865
|
-
if (topLevelMatch !== void 0) return topLevelMatch;
|
|
866
|
-
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
867
|
-
const namespaceMatch = Object.values(namespace.models).find((model) => sameSyntax(model.node.syntax, node.syntax));
|
|
868
|
-
if (namespaceMatch !== void 0) return namespaceMatch;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
function blockSymbolForNode(symbolTable, node) {
|
|
872
|
-
const topLevelMatch = Object.values(symbolTable.topLevel.blocks).find((block) => sameSyntax(block.node.syntax, node.syntax));
|
|
873
|
-
if (topLevelMatch !== void 0) return topLevelMatch;
|
|
874
|
-
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
875
|
-
const namespaceMatch = Object.values(namespace.blocks).find((block) => sameSyntax(block.node.syntax, node.syntax));
|
|
876
|
-
if (namespaceMatch !== void 0) return namespaceMatch;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
function fieldSymbolForNode(model, node) {
|
|
880
|
-
return Object.values(model.fields).find((field) => sameSyntax(field.node.syntax, node.syntax));
|
|
881
|
-
}
|
|
882
|
-
function localFieldNames(context, symbols, scalarTypes, typeConstructors = {}) {
|
|
883
|
-
switch (context.kind) {
|
|
884
|
-
case "blockAttributeNamedKey":
|
|
885
|
-
case "blockAttributeArgumentSlot":
|
|
886
|
-
case "blockAttributeValue": return [];
|
|
887
|
-
case "fieldAttributeNamedKey":
|
|
888
|
-
case "fieldAttributeArgumentSlot":
|
|
889
|
-
case "fieldAttributeValue":
|
|
890
|
-
case "modelAttributeNamedKey":
|
|
891
|
-
case "modelAttributeArgumentSlot":
|
|
892
|
-
case "modelAttributeValue": return scalarFieldNames(symbols, modelSymbolForNode(symbols, context.model), scalarTypes, typeConstructors);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
function referencedFieldNames(context, symbols, scalarTypes, typeConstructors = {}) {
|
|
896
|
-
switch (context.kind) {
|
|
897
|
-
case "blockAttributeNamedKey":
|
|
898
|
-
case "blockAttributeArgumentSlot":
|
|
899
|
-
case "blockAttributeValue":
|
|
900
|
-
case "modelAttributeNamedKey":
|
|
901
|
-
case "modelAttributeArgumentSlot":
|
|
902
|
-
case "modelAttributeValue": return [];
|
|
903
|
-
case "fieldAttributeNamedKey":
|
|
904
|
-
case "fieldAttributeArgumentSlot":
|
|
905
|
-
case "fieldAttributeValue": {
|
|
906
|
-
const model = modelSymbolForNode(symbols, context.model);
|
|
907
|
-
if (model === void 0) return [];
|
|
908
|
-
const field = fieldSymbolForNode(model, context.field);
|
|
909
|
-
if (field === void 0) return [];
|
|
910
|
-
return scalarFieldNames(symbols, referencedModel(symbols, model, field), scalarTypes, typeConstructors);
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
function scalarFieldNames(symbols, model, scalarTypes, typeConstructors) {
|
|
915
|
-
if (model === void 0) return [];
|
|
916
|
-
const namespaceName = model.node.syntax.findAncestor(NamespaceDeclarationAst.cast)?.name()?.name();
|
|
917
|
-
const namespace = namespaceName === void 0 ? void 0 : symbols.topLevel.namespaces[namespaceName];
|
|
918
|
-
return Object.values(model.fields).filter((field) => {
|
|
919
|
-
if (field.malformedType === true || field.typeContractSpaceId !== void 0) return false;
|
|
920
|
-
if (field.typeConstructor !== void 0) return isScalarConstructor(field.typeConstructor.path, typeConstructors);
|
|
921
|
-
if (field.typeNamespaceId !== void 0) return false;
|
|
922
|
-
const name = field.typeName;
|
|
923
|
-
if (namespace?.models[name] !== void 0 || namespace?.compositeTypes[name] !== void 0 || namespace?.blocks[name] !== void 0 || symbols.topLevel.models[name] !== void 0 || symbols.topLevel.compositeTypes[name] !== void 0 || symbols.topLevel.blocks[name] !== void 0) return false;
|
|
924
|
-
const namedType = symbols.topLevel.namedTypes[name];
|
|
925
|
-
if (namedType === void 0) return scalarTypes.includes(name);
|
|
926
|
-
return namedType.typeConstructor === void 0 ? refinesScalarType(namedType, scalarTypes) : isScalarConstructor(namedType.typeConstructor.path, typeConstructors);
|
|
927
|
-
}).map((field) => field.name);
|
|
928
|
-
}
|
|
929
|
-
function isScalarConstructor(path, typeConstructors) {
|
|
930
|
-
let current = typeConstructors;
|
|
931
|
-
for (const [index, segment] of path.entries()) {
|
|
932
|
-
const value = Object.hasOwn(current, segment) ? current[segment] : void 0;
|
|
933
|
-
if (value === void 0) return false;
|
|
934
|
-
if (isAuthoringTypeConstructorDescriptor(value)) return index === path.length - 1;
|
|
935
|
-
current = value;
|
|
936
|
-
}
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
function referencedModel(symbols, model, field) {
|
|
940
|
-
if (field.malformedType === true || field.typeContractSpaceId !== void 0) return void 0;
|
|
941
|
-
if (field.typeNamespaceId !== void 0) return symbols.topLevel.namespaces[field.typeNamespaceId]?.models[field.typeName];
|
|
942
|
-
const namespace = model.node.syntax.findAncestor(NamespaceDeclarationAst.cast)?.name()?.name();
|
|
943
|
-
return (namespace === void 0 ? void 0 : symbols.topLevel.namespaces[namespace]?.models[field.typeName]) ?? symbols.topLevel.models[field.typeName];
|
|
944
|
-
}
|
|
945
|
-
function sameSyntax(left, right) {
|
|
946
|
-
return left.offset === right.offset && left.endOffset === right.endOffset;
|
|
947
|
-
}
|
|
948
856
|
function attributeSpecResolver(context, source) {
|
|
949
857
|
switch (context.ownerKind) {
|
|
950
858
|
case "block": {
|
|
951
859
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
952
|
-
const block =
|
|
953
|
-
if (block
|
|
860
|
+
const block = source.binder.declaredSymbol(context.block.syntax);
|
|
861
|
+
if (block?.kind !== "block") return () => void 0;
|
|
954
862
|
return (name) => {
|
|
955
863
|
const factory = descriptor?.attributes?.[name];
|
|
956
864
|
if (factory === void 0) return void 0;
|
|
@@ -962,8 +870,8 @@ function attributeSpecResolver(context, source) {
|
|
|
962
870
|
}
|
|
963
871
|
case "model": {
|
|
964
872
|
if (source.authoringContributions === void 0) return () => void 0;
|
|
965
|
-
const model =
|
|
966
|
-
if (model
|
|
873
|
+
const model = source.binder.declaredSymbol(context.model.syntax);
|
|
874
|
+
if (model?.kind !== "model" || source.controlMutationDefaults === void 0) return () => void 0;
|
|
967
875
|
const specs = assembleAttributeSpecs(source.authoringContributions);
|
|
968
876
|
const specContext = {
|
|
969
877
|
symbols: source.symbolTable,
|
|
@@ -977,10 +885,10 @@ function attributeSpecResolver(context, source) {
|
|
|
977
885
|
}
|
|
978
886
|
case "field": {
|
|
979
887
|
if (source.authoringContributions === void 0) return () => void 0;
|
|
980
|
-
const model =
|
|
981
|
-
if (model
|
|
982
|
-
const field =
|
|
983
|
-
if (field
|
|
888
|
+
const model = source.binder.declaredSymbol(context.model.syntax);
|
|
889
|
+
if (model?.kind !== "model" || source.controlMutationDefaults === void 0) return () => void 0;
|
|
890
|
+
const field = source.binder.declaredSymbol(context.field.syntax);
|
|
891
|
+
if (field?.kind !== "field") return () => void 0;
|
|
984
892
|
const specs = assembleAttributeSpecs(source.authoringContributions);
|
|
985
893
|
const specContext = {
|
|
986
894
|
symbols: source.symbolTable,
|
|
@@ -1000,6 +908,22 @@ function attributeSpecResolver(context, source) {
|
|
|
1000
908
|
function requiredArgumentsSnippet(signature) {
|
|
1001
909
|
return requiredArguments(signature).map((argument, index) => requiredArgumentSnippet(argument, index + 1)).join(", ");
|
|
1002
910
|
}
|
|
911
|
+
function typeConstructorSnippet(name, descriptor) {
|
|
912
|
+
const args = descriptor.args ?? [];
|
|
913
|
+
const reference = descriptor.entityRefArg;
|
|
914
|
+
const count = Math.max(args.length, (reference?.index ?? -1) + 1);
|
|
915
|
+
const values = [];
|
|
916
|
+
for (let index = 0; index < count; index++) {
|
|
917
|
+
const arg = args[index];
|
|
918
|
+
if (index === reference?.index) values.push(argSnippetPlaceholder("identifier", values.length + 1, reference.entityKind));
|
|
919
|
+
else if (arg !== void 0 && arg.optional !== true) {
|
|
920
|
+
const key = arg.name ?? `arg${index + 1}`;
|
|
921
|
+
const placeholder = argSnippetPlaceholder(arg.kind === "string" || arg.kind === "stringArray" ? "str" : arg.kind === "object" ? "record" : "identifier", values.length + 1, key);
|
|
922
|
+
values.push(arg.kind === "stringArray" ? `[${placeholder}]` : placeholder);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return `${name}(${values.join(", ") || (count > 0 ? "${1:}" : "")})`;
|
|
926
|
+
}
|
|
1003
927
|
function requiredArguments(signature) {
|
|
1004
928
|
const positional = signature.positional ?? [];
|
|
1005
929
|
const positionalKeys = new Set(positional.map((argument) => argument.key));
|
|
@@ -1013,19 +937,116 @@ function requiredArguments(signature) {
|
|
|
1013
937
|
}])];
|
|
1014
938
|
}
|
|
1015
939
|
function requiredArgumentSnippet(argument, tabStop) {
|
|
1016
|
-
if (argument.kind === "positional") return argSnippetPlaceholder(argument.argument.type, tabStop, argument.argument.key);
|
|
1017
|
-
return `${argument.key}: ${argSnippetPlaceholder(argument.type, tabStop, argument.key)}`;
|
|
940
|
+
if (argument.kind === "positional") return argSnippetPlaceholder(argument.argument.type.kind, tabStop, argument.argument.key);
|
|
941
|
+
return `${argument.key}: ${argSnippetPlaceholder(argument.type.kind, tabStop, argument.key)}`;
|
|
1018
942
|
}
|
|
1019
|
-
function argSnippetPlaceholder(
|
|
943
|
+
function argSnippetPlaceholder(kind, tabStop, key) {
|
|
1020
944
|
const placeholder = `\${${tabStop.toString()}:${key}}`;
|
|
1021
|
-
if (
|
|
1022
|
-
if (
|
|
1023
|
-
if (
|
|
945
|
+
if (kind === "str") return `"${placeholder}"`;
|
|
946
|
+
if (kind === "list") return `[${placeholder}]`;
|
|
947
|
+
if (kind === "record") return `{ ${placeholder} }`;
|
|
1024
948
|
return placeholder;
|
|
1025
949
|
}
|
|
1026
950
|
function isOptionalParam(param) {
|
|
1027
951
|
return "optional" in param && param.optional === true;
|
|
1028
952
|
}
|
|
953
|
+
function refinesScalarType(symbol, binder) {
|
|
954
|
+
const node = typeReferenceNode(symbol);
|
|
955
|
+
return !symbol.isConstructor && symbol.node.typeAnnotation()?.name()?.namespace() === void 0 && node !== void 0 && binder.symbolForNode(node)?.kind === "contributedType";
|
|
956
|
+
}
|
|
957
|
+
function scopeCompletionItems(entries, binder, range, capabilities, selector) {
|
|
958
|
+
const items = [];
|
|
959
|
+
for (const [name, resolution] of entries) {
|
|
960
|
+
if (selector !== void 0) {
|
|
961
|
+
const reference = entityReference(resolution);
|
|
962
|
+
if (reference === void 0 || !matchesSelector(reference, selector)) continue;
|
|
963
|
+
} else if (resolution.kind === "block") continue;
|
|
964
|
+
const item = {
|
|
965
|
+
label: name,
|
|
966
|
+
filterText: name,
|
|
967
|
+
textEdit: {
|
|
968
|
+
range,
|
|
969
|
+
newText: name
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
switch (resolution.kind) {
|
|
973
|
+
case "model":
|
|
974
|
+
item.kind = CompletionItemKind.Class;
|
|
975
|
+
item.detail = "Model";
|
|
976
|
+
break;
|
|
977
|
+
case "compositeType":
|
|
978
|
+
item.kind = CompletionItemKind.Struct;
|
|
979
|
+
item.detail = "Composite type";
|
|
980
|
+
break;
|
|
981
|
+
case "namedType": {
|
|
982
|
+
const scalar = refinesScalarType(resolution.symbol, binder);
|
|
983
|
+
item.kind = scalar ? CompletionItemKind.Unit : CompletionItemKind.Reference;
|
|
984
|
+
item.detail = scalar ? "Scalar type" : "Type alias";
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
case "namespace":
|
|
988
|
+
case "contributedNamespace":
|
|
989
|
+
item.kind = CompletionItemKind.Module;
|
|
990
|
+
item.detail = "Namespace";
|
|
991
|
+
item.textEdit = {
|
|
992
|
+
range,
|
|
993
|
+
newText: `${name}.`
|
|
994
|
+
};
|
|
995
|
+
if (capabilities.clientSupportsTriggerSuggestCommand === true) item.command = {
|
|
996
|
+
title: "Suggest namespace members",
|
|
997
|
+
command: "editor.action.triggerSuggest"
|
|
998
|
+
};
|
|
999
|
+
break;
|
|
1000
|
+
case "contributedType": {
|
|
1001
|
+
const descriptor = resolution.symbol.descriptor;
|
|
1002
|
+
const callable = descriptor.args !== void 0 || descriptor.entityRefArg !== void 0;
|
|
1003
|
+
item.kind = callable ? CompletionItemKind.Function : CompletionItemKind.Class;
|
|
1004
|
+
if (callable) {
|
|
1005
|
+
item.textEdit = {
|
|
1006
|
+
range,
|
|
1007
|
+
newText: capabilities.clientSupportsSnippets ? typeConstructorSnippet(name, descriptor) : `${name}()`
|
|
1008
|
+
};
|
|
1009
|
+
if (capabilities.clientSupportsSnippets) item.insertTextFormat = InsertTextFormat.Snippet;
|
|
1010
|
+
}
|
|
1011
|
+
item.detail = descriptor.deprecated === void 0 ? descriptor.documentation || "Configured scalar type" : `Deprecated: use ${descriptor.deprecated.replacement}.`;
|
|
1012
|
+
if (descriptor.deprecated !== void 0) item.tags = [CompletionItemTag.Deprecated];
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
case "block":
|
|
1016
|
+
item.kind = resolution.symbol.keyword === "enum" ? CompletionItemKind.Enum : CompletionItemKind.Keyword;
|
|
1017
|
+
item.detail = resolution.symbol.keyword;
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
items.push(item);
|
|
1021
|
+
}
|
|
1022
|
+
return items;
|
|
1023
|
+
}
|
|
1024
|
+
function localFieldNames(context, binder) {
|
|
1025
|
+
if (context.ownerKind === "block") return [];
|
|
1026
|
+
const model = binder.declaredSymbol(context.model.syntax);
|
|
1027
|
+
return scalarFieldNames(model?.kind === "model" ? model : void 0, binder);
|
|
1028
|
+
}
|
|
1029
|
+
function referencedFieldNames(context, binder) {
|
|
1030
|
+
if (context.ownerKind !== "field") return [];
|
|
1031
|
+
const field = binder.declaredSymbol(context.field.syntax);
|
|
1032
|
+
if (field?.kind !== "field") return [];
|
|
1033
|
+
const node = typeReferenceNode(field);
|
|
1034
|
+
const target = node === void 0 ? void 0 : binder.symbolForNode(node);
|
|
1035
|
+
return scalarFieldNames(target?.kind === "model" ? target.symbol : void 0, binder);
|
|
1036
|
+
}
|
|
1037
|
+
function scalarFieldNames(model, binder) {
|
|
1038
|
+
if (model === void 0) return [];
|
|
1039
|
+
return Object.values(model.fields).filter((field) => {
|
|
1040
|
+
const node = typeReferenceNode(field);
|
|
1041
|
+
const resolution = node === void 0 ? void 0 : binder.symbolForNode(node);
|
|
1042
|
+
return resolution?.kind === "namedType" ? field.node.typeAnnotation()?.isConstructor() !== true && isScalarReference(resolution.symbol, binder) : isScalarReference(field, binder);
|
|
1043
|
+
}).map((field) => field.name);
|
|
1044
|
+
}
|
|
1045
|
+
function isScalarReference(symbol, binder) {
|
|
1046
|
+
const annotation = symbol.node.typeAnnotation();
|
|
1047
|
+
const name = annotation?.name();
|
|
1048
|
+
return name !== void 0 && binder.symbolForNode(name.syntax)?.kind === "contributedType" && (annotation?.isConstructor() === true || name.namespace() === void 0);
|
|
1049
|
+
}
|
|
1029
1050
|
function resolveGrammar(signature, path) {
|
|
1030
1051
|
let grammars = [signature];
|
|
1031
1052
|
for (const step of path) grammars = grammars.flatMap((grammar) => advanceGrammar(grammar, step));
|
|
@@ -1105,9 +1126,12 @@ function valueItems(input, type, syntax) {
|
|
|
1105
1126
|
case "null": return scalarItems(input, ["null"]);
|
|
1106
1127
|
case "fieldRef":
|
|
1107
1128
|
case "referencedFieldRef": return scalarItems(input, input.fieldNames(type.kind));
|
|
1129
|
+
case "entityRef": return scopeCompletionItems(input.scope.entries(), input.binder, {
|
|
1130
|
+
start: input.sourceFile.positionAt(input.context.replacementStartOffset),
|
|
1131
|
+
end: input.sourceFile.positionAt(input.context.replacementEndOffset)
|
|
1132
|
+
}, input, type.expected);
|
|
1108
1133
|
case "list":
|
|
1109
1134
|
case "record":
|
|
1110
|
-
case "entityRef":
|
|
1111
1135
|
case "int":
|
|
1112
1136
|
case "json":
|
|
1113
1137
|
case "rejecting": return [];
|
|
@@ -1148,17 +1172,6 @@ function orderedItems(items) {
|
|
|
1148
1172
|
sortText: index.toString().padStart(4, "0")
|
|
1149
1173
|
}));
|
|
1150
1174
|
}
|
|
1151
|
-
const categoryOrder = {
|
|
1152
|
-
configuredScalar: 0,
|
|
1153
|
-
topLevelModel: 1,
|
|
1154
|
-
topLevelCompositeType: 2,
|
|
1155
|
-
scalar: 3,
|
|
1156
|
-
typeAlias: 4,
|
|
1157
|
-
namespace: 5,
|
|
1158
|
-
namespaceModel: 6,
|
|
1159
|
-
namespaceCompositeType: 7,
|
|
1160
|
-
deprecatedScalar: 8
|
|
1161
|
-
};
|
|
1162
1175
|
const declarationKeywordCategoryOrder = {
|
|
1163
1176
|
native: 0,
|
|
1164
1177
|
genericBlock: 1
|
|
@@ -1197,11 +1210,13 @@ function providePslCompletionItems(input) {
|
|
|
1197
1210
|
const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
|
|
1198
1211
|
return spec === void 0 ? [] : provideAttributeArgumentSlotCompletionItems({
|
|
1199
1212
|
context,
|
|
1213
|
+
binder: input.candidates.binder,
|
|
1214
|
+
scope: input.candidates.binder.scopeAt("field" in context ? context.field.syntax : "model" in context ? context.model.syntax : context.block.syntax),
|
|
1200
1215
|
sourceFile: input.sourceFile,
|
|
1201
1216
|
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1202
1217
|
clientSupportsTriggerSuggestCommand: input.clientSupportsTriggerSuggestCommand === true,
|
|
1203
1218
|
clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
|
|
1204
|
-
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.
|
|
1219
|
+
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.binder) : referencedFieldNames(context, input.candidates.binder)
|
|
1205
1220
|
}, spec);
|
|
1206
1221
|
}
|
|
1207
1222
|
case "fieldAttributeValue":
|
|
@@ -1210,16 +1225,18 @@ function providePslCompletionItems(input) {
|
|
|
1210
1225
|
const spec = attributeSpecResolver(context, input.candidates)(context.attributeName);
|
|
1211
1226
|
return spec === void 0 ? [] : provideAttributeValueCompletionItems({
|
|
1212
1227
|
context,
|
|
1228
|
+
binder: input.candidates.binder,
|
|
1229
|
+
scope: input.candidates.binder.scopeAt("field" in context ? context.field.syntax : "model" in context ? context.model.syntax : context.block.syntax),
|
|
1213
1230
|
sourceFile: input.sourceFile,
|
|
1214
1231
|
clientSupportsSnippets: input.clientSupportsSnippets,
|
|
1215
1232
|
clientSupportsTriggerParameterHintsCommand: input.clientSupportsTriggerParameterHintsCommand === true,
|
|
1216
|
-
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.
|
|
1233
|
+
fieldNames: (kind) => kind === "fieldRef" ? localFieldNames(context, input.candidates.binder) : referencedFieldNames(context, input.candidates.binder)
|
|
1217
1234
|
}, spec);
|
|
1218
1235
|
}
|
|
1219
1236
|
case "declarationKeyword": return provideDeclarationKeywordCompletionItems(context, input.sourceFile, input.candidates, input.clientSupportsSnippets);
|
|
1220
1237
|
case "genericBlockKey": return provideGenericBlockKeyCompletionItems(context, input.sourceFile, input.candidates);
|
|
1221
|
-
case "modelType": return provideModelTypeCompletionItems(context, input.sourceFile, input.candidates);
|
|
1222
|
-
case "namespaceMember": return provideNamespaceMemberCompletionItems(context, input.sourceFile, input.candidates);
|
|
1238
|
+
case "modelType": return provideModelTypeCompletionItems(context, input.sourceFile, input.candidates, input);
|
|
1239
|
+
case "namespaceMember": return provideNamespaceMemberCompletionItems(context, input.sourceFile, input.candidates, input);
|
|
1223
1240
|
}
|
|
1224
1241
|
}
|
|
1225
1242
|
function provideAttributeNameCompletionItems(context, sourceFile, source, clientSupportsSnippets, clientSupportsTriggerParameterHintsCommand) {
|
|
@@ -1345,8 +1362,8 @@ function declarationKeywordSortText(candidate) {
|
|
|
1345
1362
|
function provideGenericBlockKeyCompletionItems(context, sourceFile, source) {
|
|
1346
1363
|
const descriptor = findBlockDescriptor(source.pslBlockDescriptors, context.blockKeyword);
|
|
1347
1364
|
if (descriptor === void 0) return [];
|
|
1348
|
-
const block =
|
|
1349
|
-
if (block
|
|
1365
|
+
const block = source.binder.declaredSymbol(context.block.syntax);
|
|
1366
|
+
if (block?.kind !== "block") return [];
|
|
1350
1367
|
const spec = blockSpecFactoryOf(descriptor)({
|
|
1351
1368
|
symbols: source.symbolTable,
|
|
1352
1369
|
block
|
|
@@ -1378,107 +1395,23 @@ function existingGenericBlockParameterNames(block, cursorOffset) {
|
|
|
1378
1395
|
}
|
|
1379
1396
|
return names;
|
|
1380
1397
|
}
|
|
1381
|
-
function provideModelTypeCompletionItems(context, sourceFile, source) {
|
|
1382
|
-
return
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
]);
|
|
1398
|
+
function provideModelTypeCompletionItems(context, sourceFile, source, capabilities) {
|
|
1399
|
+
return scopeCompletionItems(source.binder.scopeAt(context.field.syntax).entries(), source.binder, {
|
|
1400
|
+
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
1401
|
+
end: sourceFile.positionAt(context.offset)
|
|
1402
|
+
}, capabilities);
|
|
1387
1403
|
}
|
|
1388
|
-
function provideNamespaceMemberCompletionItems(context, sourceFile, source) {
|
|
1404
|
+
function provideNamespaceMemberCompletionItems(context, sourceFile, source, capabilities) {
|
|
1389
1405
|
if (context.space !== void 0) return [];
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
function modelTypeCompletionItems(context, sourceFile, candidates) {
|
|
1393
|
-
const replacementRange = {
|
|
1406
|
+
const qualifier = source.binder.scopeAt(context.field.syntax).lookup(context.namespace);
|
|
1407
|
+
return scopeCompletionItems(qualifier !== void 0 && isNamespaceLike(qualifier) ? memberEntries(qualifier) : [], source.binder, {
|
|
1394
1408
|
start: sourceFile.positionAt(context.replacementStartOffset),
|
|
1395
1409
|
end: sourceFile.positionAt(context.offset)
|
|
1396
|
-
};
|
|
1397
|
-
return candidates.map((candidate) => ({
|
|
1398
|
-
label: candidate.label,
|
|
1399
|
-
kind: candidate.kind,
|
|
1400
|
-
detail: candidate.detail,
|
|
1401
|
-
sortText: sortText(candidate),
|
|
1402
|
-
filterText: candidate.filterText,
|
|
1403
|
-
textEdit: {
|
|
1404
|
-
range: replacementRange,
|
|
1405
|
-
newText: candidate.insertText
|
|
1406
|
-
},
|
|
1407
|
-
...candidate.deprecated === true ? { tags: [CompletionItemTag.Deprecated] } : {}
|
|
1408
|
-
}));
|
|
1409
|
-
}
|
|
1410
|
-
function configuredScalarCandidates(source) {
|
|
1411
|
-
const constructors = source.authoringContributions?.type ?? {};
|
|
1412
|
-
return sortedUnique(source.scalarTypes).map((name) => {
|
|
1413
|
-
const descriptor = constructors[name];
|
|
1414
|
-
const typeConstructor = descriptor !== void 0 && isAuthoringTypeConstructorDescriptor(descriptor) ? descriptor : void 0;
|
|
1415
|
-
const base = {
|
|
1416
|
-
label: name,
|
|
1417
|
-
insertText: name,
|
|
1418
|
-
filterText: name,
|
|
1419
|
-
kind: CompletionItemKind.Keyword
|
|
1420
|
-
};
|
|
1421
|
-
if (typeConstructor?.deprecated !== void 0) return {
|
|
1422
|
-
...base,
|
|
1423
|
-
category: "deprecatedScalar",
|
|
1424
|
-
detail: `Deprecated: use ${typeConstructor.deprecated.replacement}.`,
|
|
1425
|
-
deprecated: true
|
|
1426
|
-
};
|
|
1427
|
-
return {
|
|
1428
|
-
...base,
|
|
1429
|
-
category: "configuredScalar",
|
|
1430
|
-
detail: typeConstructor?.documentation || "Configured scalar type"
|
|
1431
|
-
};
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
function topLevelSymbolCandidates(symbolTable, scalarTypes) {
|
|
1435
|
-
const { topLevel } = symbolTable;
|
|
1436
|
-
const namedTypes = Object.values(topLevel.namedTypes);
|
|
1437
|
-
const scalarRefinementNames = namedTypes.filter((symbol) => refinesScalarType(symbol, scalarTypes)).map((symbol) => symbol.name).sort(compareNames);
|
|
1438
|
-
const aliasNames = namedTypes.filter((symbol) => !refinesScalarType(symbol, scalarTypes)).map((symbol) => symbol.name).sort(compareNames);
|
|
1439
|
-
return [
|
|
1440
|
-
...symbolCandidates(recordNames(topLevel.models), "topLevelModel", "Model", CompletionItemKind.Class),
|
|
1441
|
-
...symbolCandidates(recordNames(topLevel.compositeTypes), "topLevelCompositeType", "Composite type", CompletionItemKind.Struct),
|
|
1442
|
-
...symbolCandidates(scalarRefinementNames, "scalar", "Scalar type", CompletionItemKind.Unit),
|
|
1443
|
-
...symbolCandidates(aliasNames, "typeAlias", "Type alias", CompletionItemKind.Reference)
|
|
1444
|
-
];
|
|
1445
|
-
}
|
|
1446
|
-
function allNamespaceCandidates(symbolTable) {
|
|
1447
|
-
return Object.values(symbolTable.topLevel.namespaces).sort((left, right) => compareNames(left.name, right.name)).map(namespaceQualifierCandidate);
|
|
1448
|
-
}
|
|
1449
|
-
function namespaceCandidates(namespace) {
|
|
1450
|
-
if (namespace === void 0) return [];
|
|
1451
|
-
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)];
|
|
1452
|
-
}
|
|
1453
|
-
function namespaceQualifierCandidate(namespace) {
|
|
1454
|
-
return {
|
|
1455
|
-
category: "namespace",
|
|
1456
|
-
label: namespace.name,
|
|
1457
|
-
insertText: namespace.name,
|
|
1458
|
-
filterText: namespace.name,
|
|
1459
|
-
detail: "Namespace",
|
|
1460
|
-
kind: CompletionItemKind.Module
|
|
1461
|
-
};
|
|
1462
|
-
}
|
|
1463
|
-
function symbolCandidates(names, category, detail, kind) {
|
|
1464
|
-
return names.map((name) => ({
|
|
1465
|
-
category,
|
|
1466
|
-
label: name,
|
|
1467
|
-
insertText: name,
|
|
1468
|
-
filterText: name,
|
|
1469
|
-
detail,
|
|
1470
|
-
kind
|
|
1471
|
-
}));
|
|
1472
|
-
}
|
|
1473
|
-
function recordNames(record) {
|
|
1474
|
-
return Object.values(record).map((symbol) => symbol.name).sort(compareNames);
|
|
1410
|
+
}, capabilities);
|
|
1475
1411
|
}
|
|
1476
1412
|
function sortedUnique(names) {
|
|
1477
1413
|
return [...new Set(names)].sort(compareNames);
|
|
1478
1414
|
}
|
|
1479
|
-
function sortText(candidate) {
|
|
1480
|
-
return `${categoryOrder[candidate.category]}:${candidate.label}`;
|
|
1481
|
-
}
|
|
1482
1415
|
function genericBlockParameterSortText(index, label) {
|
|
1483
1416
|
return `${index.toString().padStart(4, "0")}:${label}`;
|
|
1484
1417
|
}
|
|
@@ -1536,6 +1469,7 @@ var ProjectArtifacts = class {
|
|
|
1536
1469
|
#inputs;
|
|
1537
1470
|
#documents = /* @__PURE__ */ new Map();
|
|
1538
1471
|
#symbolTableResult;
|
|
1472
|
+
#binderResult;
|
|
1539
1473
|
#sources;
|
|
1540
1474
|
#interpretMemo;
|
|
1541
1475
|
constructor(options) {
|
|
@@ -1562,6 +1496,26 @@ var ProjectArtifacts = class {
|
|
|
1562
1496
|
};
|
|
1563
1497
|
symbolTable = () => this.#readSymbolTable();
|
|
1564
1498
|
symbolDiagnostics = () => this.#readSymbolTableResult().diagnostics;
|
|
1499
|
+
binder = () => this.#readBinderResult().binder;
|
|
1500
|
+
#readBinderResult() {
|
|
1501
|
+
const symbolTable = this.#readSymbolTable();
|
|
1502
|
+
const stack = this.#options.controlStack;
|
|
1503
|
+
this.#binderResult ??= createBinder({
|
|
1504
|
+
sources: this.sources,
|
|
1505
|
+
symbolTable,
|
|
1506
|
+
typeConstructors: stack.authoringContributions?.type ?? {},
|
|
1507
|
+
attributeSpecs: stack.authoringContributions === void 0 ? {
|
|
1508
|
+
model: {},
|
|
1509
|
+
field: {}
|
|
1510
|
+
} : assembleAttributeSpecs(stack.authoringContributions),
|
|
1511
|
+
pslBlockDescriptors: stack.pslBlockDescriptors,
|
|
1512
|
+
controlMutationDefaults: {
|
|
1513
|
+
defaultFunctionRegistry: stack.controlMutationDefaults?.defaultFunctionRegistry ?? /* @__PURE__ */ new Map(),
|
|
1514
|
+
dataTypeEntries: stack.authoringContributions?.dataTypes ?? {}
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
return this.#binderResult;
|
|
1518
|
+
}
|
|
1565
1519
|
documentChanged = (uri) => this.#drop(uri);
|
|
1566
1520
|
documentClosed = this.documentChanged;
|
|
1567
1521
|
updateInputs = (next) => {
|
|
@@ -1577,10 +1531,19 @@ var ProjectArtifacts = class {
|
|
|
1577
1531
|
#refreshSources() {
|
|
1578
1532
|
this.#sources = void 0;
|
|
1579
1533
|
this.#symbolTableResult = void 0;
|
|
1534
|
+
this.#binderResult = void 0;
|
|
1580
1535
|
this.#interpretMemo = void 0;
|
|
1581
1536
|
}
|
|
1582
1537
|
#projectInterpretDiagnostics() {
|
|
1583
|
-
if (this.#interpretation === void 0)
|
|
1538
|
+
if (this.#interpretation === void 0) {
|
|
1539
|
+
const bySourceId = /* @__PURE__ */ new Map();
|
|
1540
|
+
for (const diagnostic of this.#readBinderResult().diagnostics) {
|
|
1541
|
+
const group = bySourceId.get(diagnostic.filename) ?? [];
|
|
1542
|
+
group.push(...mapParseDiagnostics([diagnostic]));
|
|
1543
|
+
bySourceId.set(diagnostic.filename, group);
|
|
1544
|
+
}
|
|
1545
|
+
return bySourceId;
|
|
1546
|
+
}
|
|
1584
1547
|
this.#interpretMemo ??= this.#computeInterpretDistribution(this.#interpretation);
|
|
1585
1548
|
return this.#interpretMemo;
|
|
1586
1549
|
}
|
|
@@ -1781,94 +1744,93 @@ function collectCommentTokens(document) {
|
|
|
1781
1744
|
return tokens;
|
|
1782
1745
|
}
|
|
1783
1746
|
function collectDeclarations(source, tokens) {
|
|
1784
|
-
for (const declaration of source.document.declarations()) collectDeclaration(declaration, source, tokens
|
|
1747
|
+
for (const declaration of source.document.declarations()) collectDeclaration(declaration, source, tokens);
|
|
1785
1748
|
}
|
|
1786
|
-
function collectDeclaration(declaration, source, tokens
|
|
1749
|
+
function collectDeclaration(declaration, source, tokens) {
|
|
1787
1750
|
if (declaration instanceof ModelDeclarationAst) {
|
|
1788
1751
|
addToken(declaration.keyword(), "keyword", tokens);
|
|
1789
1752
|
addIdentifier(declaration.name(), "class", tokens, semanticTokenModifierBits.declaration);
|
|
1790
|
-
collectBlockMembers(declaration.members(), source, tokens
|
|
1753
|
+
collectBlockMembers(declaration.members(), source, tokens);
|
|
1791
1754
|
return;
|
|
1792
1755
|
}
|
|
1793
1756
|
if (declaration instanceof CompositeTypeDeclarationAst) {
|
|
1794
1757
|
addToken(declaration.keyword(), "keyword", tokens);
|
|
1795
1758
|
addIdentifier(declaration.name(), "struct", tokens, semanticTokenModifierBits.declaration);
|
|
1796
|
-
collectBlockMembers(declaration.members(), source, tokens
|
|
1759
|
+
collectBlockMembers(declaration.members(), source, tokens);
|
|
1797
1760
|
return;
|
|
1798
1761
|
}
|
|
1799
1762
|
if (declaration instanceof NamespaceDeclarationAst) {
|
|
1800
1763
|
addToken(declaration.keyword(), "keyword", tokens);
|
|
1801
1764
|
addIdentifier(declaration.name(), "namespace", tokens, semanticTokenModifierBits.declaration);
|
|
1802
|
-
const
|
|
1803
|
-
for (const nested of declaration.declarations()) collectDeclaration(nested, source, tokens, nestedNamespace);
|
|
1765
|
+
for (const nested of declaration.declarations()) collectDeclaration(nested, source, tokens);
|
|
1804
1766
|
return;
|
|
1805
1767
|
}
|
|
1806
1768
|
if (declaration instanceof TypesBlockAst) {
|
|
1807
1769
|
addToken(declaration.keyword(), "keyword", tokens);
|
|
1808
|
-
for (const namedType of declaration.declarations()) collectNamedTypeDeclaration(namedType, source, tokens
|
|
1770
|
+
for (const namedType of declaration.declarations()) collectNamedTypeDeclaration(namedType, source, tokens);
|
|
1809
1771
|
return;
|
|
1810
1772
|
}
|
|
1811
1773
|
addToken(declaration.keyword(), "keyword", tokens);
|
|
1812
1774
|
addIdentifier(declaration.name(), "type", tokens, semanticTokenModifierBits.declaration);
|
|
1813
|
-
collectGenericBlockMembers(declaration.members(), source, tokens
|
|
1775
|
+
collectGenericBlockMembers(declaration.members(), source, tokens);
|
|
1814
1776
|
}
|
|
1815
|
-
function collectNamedTypeDeclaration(declaration, source, tokens
|
|
1777
|
+
function collectNamedTypeDeclaration(declaration, source, tokens) {
|
|
1816
1778
|
addIdentifier(declaration.name(), "type", tokens, semanticTokenModifierBits.declaration);
|
|
1817
|
-
collectTypeAnnotation(declaration.typeAnnotation(), source, tokens
|
|
1818
|
-
collectAttributes(declaration.attributes(), source, tokens
|
|
1779
|
+
collectTypeAnnotation(declaration.typeAnnotation(), source, tokens);
|
|
1780
|
+
collectAttributes(declaration.attributes(), source, tokens);
|
|
1819
1781
|
}
|
|
1820
|
-
function collectGenericBlockMembers(members, source, tokens
|
|
1782
|
+
function collectGenericBlockMembers(members, source, tokens) {
|
|
1821
1783
|
for (const member of members) {
|
|
1822
1784
|
if ("key" in member) {
|
|
1823
1785
|
addIdentifier(member.key(), "property", tokens);
|
|
1824
|
-
collectExpression(member.value(), source, tokens
|
|
1786
|
+
collectExpression(member.value(), source, tokens);
|
|
1825
1787
|
continue;
|
|
1826
1788
|
}
|
|
1827
|
-
collectAttribute(member, source, tokens
|
|
1789
|
+
collectAttribute(member, source, tokens);
|
|
1828
1790
|
}
|
|
1829
1791
|
}
|
|
1830
|
-
function collectBlockMembers(members, source, tokens
|
|
1792
|
+
function collectBlockMembers(members, source, tokens) {
|
|
1831
1793
|
for (const member of members) {
|
|
1832
1794
|
if (member instanceof FieldDeclarationAst) {
|
|
1833
|
-
collectField(member, source, tokens
|
|
1795
|
+
collectField(member, source, tokens);
|
|
1834
1796
|
continue;
|
|
1835
1797
|
}
|
|
1836
|
-
collectAttribute(member, source, tokens
|
|
1798
|
+
collectAttribute(member, source, tokens);
|
|
1837
1799
|
}
|
|
1838
1800
|
}
|
|
1839
|
-
function collectField(field, source, tokens
|
|
1801
|
+
function collectField(field, source, tokens) {
|
|
1840
1802
|
addIdentifier(field.name(), "property", tokens, semanticTokenModifierBits.declaration);
|
|
1841
|
-
collectTypeAnnotation(field.typeAnnotation(), source, tokens
|
|
1842
|
-
collectAttributes(field.attributes(), source, tokens
|
|
1803
|
+
collectTypeAnnotation(field.typeAnnotation(), source, tokens);
|
|
1804
|
+
collectAttributes(field.attributes(), source, tokens);
|
|
1843
1805
|
}
|
|
1844
|
-
function collectTypeAnnotation(annotation, source, tokens
|
|
1806
|
+
function collectTypeAnnotation(annotation, source, tokens) {
|
|
1845
1807
|
if (annotation === void 0) return;
|
|
1846
|
-
collectTypeReference(annotation.name(), source, tokens
|
|
1847
|
-
collectAttributeArgList(annotation.argList(), source, tokens
|
|
1808
|
+
collectTypeReference(annotation.name(), source, tokens);
|
|
1809
|
+
collectAttributeArgList(annotation.argList(), source, tokens);
|
|
1848
1810
|
}
|
|
1849
|
-
function collectAttributes(attributes, source, tokens
|
|
1850
|
-
for (const attribute of attributes) collectAttribute(attribute, source, tokens
|
|
1811
|
+
function collectAttributes(attributes, source, tokens) {
|
|
1812
|
+
for (const attribute of attributes) collectAttribute(attribute, source, tokens);
|
|
1851
1813
|
}
|
|
1852
|
-
function collectAttribute(attribute, source, tokens
|
|
1853
|
-
const marker =
|
|
1814
|
+
function collectAttribute(attribute, source, tokens) {
|
|
1815
|
+
const marker = "at" in attribute ? attribute.at() : attribute.doubleAt();
|
|
1854
1816
|
collectDecoratorName(attribute.name(), marker, tokens);
|
|
1855
|
-
collectAttributeArgList(attribute.argList(), source, tokens
|
|
1817
|
+
collectAttributeArgList(attribute.argList(), source, tokens);
|
|
1856
1818
|
}
|
|
1857
1819
|
function collectDecoratorName(name, marker, tokens) {
|
|
1858
1820
|
if (name === void 0) return;
|
|
1859
1821
|
const segments = identifierSegments(name);
|
|
1860
1822
|
for (const [index, segment] of segments.entries()) tokens.push(rangeForDecoratorIdentifier(segment.identifier, index === 0 ? marker : void 0));
|
|
1861
1823
|
}
|
|
1862
|
-
function collectAttributeArgList(argList, source, tokens
|
|
1824
|
+
function collectAttributeArgList(argList, source, tokens) {
|
|
1863
1825
|
if (argList === void 0) return;
|
|
1864
|
-
for (const arg of argList.args()) collectAttributeArg(arg, source, tokens
|
|
1826
|
+
for (const arg of argList.args()) collectAttributeArg(arg, source, tokens);
|
|
1865
1827
|
}
|
|
1866
|
-
function collectAttributeArg(arg, source, tokens
|
|
1828
|
+
function collectAttributeArg(arg, source, tokens) {
|
|
1867
1829
|
const name = arg.name();
|
|
1868
1830
|
addIdentifier(name, "property", tokens);
|
|
1869
|
-
collectExpression(arg.value(), source, tokens,
|
|
1831
|
+
collectExpression(arg.value(), source, tokens, expressionContextForAttributeArg(name));
|
|
1870
1832
|
}
|
|
1871
|
-
function collectExpression(expression, source, tokens,
|
|
1833
|
+
function collectExpression(expression, source, tokens, context = {}) {
|
|
1872
1834
|
if (expression === void 0) return;
|
|
1873
1835
|
if (expression instanceof StringLiteralExprAst) {
|
|
1874
1836
|
addToken(expression.token(), "string", tokens);
|
|
@@ -1884,19 +1846,19 @@ function collectExpression(expression, source, tokens, namespace, context = {})
|
|
|
1884
1846
|
}
|
|
1885
1847
|
if (expression instanceof FunctionCallAst) {
|
|
1886
1848
|
const memberPath = expression.memberPath();
|
|
1887
|
-
if (memberPath === void 0) collectTypeReference(expression.name(), source, tokens
|
|
1849
|
+
if (memberPath === void 0) collectTypeReference(expression.name(), source, tokens);
|
|
1888
1850
|
else collectMemberPath(memberPath, tokens);
|
|
1889
|
-
for (const arg of expression.args()) collectAttributeArg(arg, source, tokens
|
|
1851
|
+
for (const arg of expression.args()) collectAttributeArg(arg, source, tokens);
|
|
1890
1852
|
return;
|
|
1891
1853
|
}
|
|
1892
1854
|
if (expression instanceof ArrayLiteralAst) {
|
|
1893
|
-
for (const element of expression.elements()) collectExpression(element, source, tokens,
|
|
1855
|
+
for (const element of expression.elements()) collectExpression(element, source, tokens, context);
|
|
1894
1856
|
return;
|
|
1895
1857
|
}
|
|
1896
1858
|
if (expression instanceof ObjectLiteralExprAst) {
|
|
1897
1859
|
for (const field of expression.fields()) {
|
|
1898
1860
|
addIdentifier(field.key(), "property", tokens);
|
|
1899
|
-
collectExpression(field.value(), source, tokens
|
|
1861
|
+
collectExpression(field.value(), source, tokens);
|
|
1900
1862
|
}
|
|
1901
1863
|
return;
|
|
1902
1864
|
}
|
|
@@ -1905,69 +1867,59 @@ function collectExpression(expression, source, tokens, namespace, context = {})
|
|
|
1905
1867
|
collectMemberPath(expression, tokens);
|
|
1906
1868
|
return;
|
|
1907
1869
|
}
|
|
1908
|
-
collectIdentifierExpression(expression, source, tokens,
|
|
1870
|
+
collectIdentifierExpression(expression, source, tokens, context);
|
|
1909
1871
|
}
|
|
1910
1872
|
/** A member path such as `address.city` names fields, one per segment. */
|
|
1911
1873
|
function collectMemberPath(path, tokens) {
|
|
1912
1874
|
for (const segment of path.segments()) addIdentifier(segment, "property", tokens);
|
|
1913
1875
|
}
|
|
1914
|
-
function collectIdentifierExpression(identifier, source, tokens,
|
|
1915
|
-
|
|
1916
|
-
|
|
1876
|
+
function collectIdentifierExpression(identifier, source, tokens, context) {
|
|
1877
|
+
if (identifier.name() === void 0) return;
|
|
1878
|
+
const resolution = source.binder.symbolForNode(identifier.syntax);
|
|
1917
1879
|
const bareIdentifierTokenType = context.bareIdentifierTokenType;
|
|
1918
|
-
if (bareIdentifierTokenType !== void 0) {
|
|
1880
|
+
if ((resolution === void 0 || resolution.kind === "unresolved" || resolution.kind === "crossSpace") && bareIdentifierTokenType !== void 0) {
|
|
1919
1881
|
tokens.push(rangeForIdentifier(identifier, bareIdentifierTokenType));
|
|
1920
1882
|
return;
|
|
1921
1883
|
}
|
|
1922
|
-
const classification = classifyTypeReference(
|
|
1884
|
+
const classification = classifyTypeReference(resolution, source.binder);
|
|
1923
1885
|
tokens.push(rangeForIdentifier(identifier, classification.tokenType, classification.modifierBitset));
|
|
1924
1886
|
}
|
|
1925
1887
|
function expressionContextForAttributeArg(name) {
|
|
1926
1888
|
const argName = name?.name();
|
|
1927
1889
|
return argName === "fields" || argName === "references" ? { bareIdentifierTokenType: "property" } : {};
|
|
1928
1890
|
}
|
|
1929
|
-
function collectTypeReference(name, source, tokens
|
|
1891
|
+
function collectTypeReference(name, source, tokens) {
|
|
1930
1892
|
if (name === void 0) return;
|
|
1931
1893
|
const segments = identifierSegments(name);
|
|
1932
1894
|
if (segments.length === 0) return;
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1895
|
+
for (const segment of segments.slice(0, -1)) {
|
|
1896
|
+
const qualifier = source.binder.scopeAt(name.syntax).lookup(segment.text);
|
|
1897
|
+
if (qualifier !== void 0 && isNamespaceLike(qualifier)) tokens.push(rangeForIdentifier(segment.identifier, "namespace"));
|
|
1898
|
+
}
|
|
1935
1899
|
const finalSegment = segments[segments.length - 1];
|
|
1936
1900
|
if (finalSegment === void 0) return;
|
|
1937
|
-
const classification = classifyTypeReference(
|
|
1901
|
+
const classification = classifyTypeReference(source.binder.symbolForNode(name.syntax), source.binder);
|
|
1938
1902
|
tokens.push(rangeForIdentifier(finalSegment.identifier, classification.tokenType, classification.modifierBitset));
|
|
1939
1903
|
}
|
|
1940
|
-
function classifyTypeReference(
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
tokenType: "type",
|
|
1956
|
-
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
1957
|
-
} : { tokenType: "type" };
|
|
1958
|
-
if (Object.hasOwn(symbols.topLevel.blocks, name)) return { tokenType: "type" };
|
|
1959
|
-
if (source.scalarTypes.includes(name)) return {
|
|
1960
|
-
tokenType: "type",
|
|
1961
|
-
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
1962
|
-
};
|
|
1963
|
-
return { tokenType: "type" };
|
|
1964
|
-
}
|
|
1965
|
-
function isKnownNamespace(name, symbols) {
|
|
1966
|
-
return Object.hasOwn(symbols.topLevel.namespaces, name);
|
|
1904
|
+
function classifyTypeReference(resolution, binder) {
|
|
1905
|
+
switch (resolution?.kind) {
|
|
1906
|
+
case "model": return { tokenType: "class" };
|
|
1907
|
+
case "compositeType": return { tokenType: "struct" };
|
|
1908
|
+
case "field": return { tokenType: "property" };
|
|
1909
|
+
case "contributedType": return {
|
|
1910
|
+
tokenType: "type",
|
|
1911
|
+
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
1912
|
+
};
|
|
1913
|
+
case "namedType": return refinesScalarType(resolution.symbol, binder) ? {
|
|
1914
|
+
tokenType: "type",
|
|
1915
|
+
modifierBitset: semanticTokenModifierBits.defaultLibrary
|
|
1916
|
+
} : { tokenType: "type" };
|
|
1917
|
+
default: return { tokenType: "type" };
|
|
1918
|
+
}
|
|
1967
1919
|
}
|
|
1968
1920
|
function identifierSegments(name) {
|
|
1969
1921
|
const segments = [];
|
|
1970
|
-
for (const identifier of
|
|
1922
|
+
for (const identifier of name.segments()) {
|
|
1971
1923
|
const text = identifier.name();
|
|
1972
1924
|
if (text !== void 0) segments.push({
|
|
1973
1925
|
identifier,
|
|
@@ -2252,8 +2204,7 @@ var Project = class {
|
|
|
2252
2204
|
return buildSemanticTokens({
|
|
2253
2205
|
document: document.parse().document,
|
|
2254
2206
|
sourceFile: document.sourceFile,
|
|
2255
|
-
|
|
2256
|
-
scalarTypes: data.controlStack.scalarTypes
|
|
2207
|
+
binder: data.artifacts.binder()
|
|
2257
2208
|
}, range);
|
|
2258
2209
|
}
|
|
2259
2210
|
async completions(uri, position, capabilities) {
|
|
@@ -2270,7 +2221,8 @@ var Project = class {
|
|
|
2270
2221
|
sourceFile: document.sourceFile,
|
|
2271
2222
|
candidates: {
|
|
2272
2223
|
...data.controlStack,
|
|
2273
|
-
symbolTable: data.artifacts.symbolTable()
|
|
2224
|
+
symbolTable: data.artifacts.symbolTable(),
|
|
2225
|
+
binder: data.artifacts.binder()
|
|
2274
2226
|
},
|
|
2275
2227
|
clientSupportsSnippets: capabilities.completionSnippets,
|
|
2276
2228
|
clientSupportsTriggerSuggestCommand: capabilities.completionTriggerSuggestCommand,
|
|
@@ -2292,7 +2244,8 @@ var Project = class {
|
|
|
2292
2244
|
position,
|
|
2293
2245
|
candidates: {
|
|
2294
2246
|
...data.controlStack,
|
|
2295
|
-
symbolTable: data.artifacts.symbolTable()
|
|
2247
|
+
symbolTable: data.artifacts.symbolTable(),
|
|
2248
|
+
binder: data.artifacts.binder()
|
|
2296
2249
|
}
|
|
2297
2250
|
});
|
|
2298
2251
|
} catch {
|
|
@@ -2436,6 +2389,7 @@ var Project = class {
|
|
|
2436
2389
|
async #load() {
|
|
2437
2390
|
const resolution = await resolveConfigInputs(this.configPath, (uri) => this.#options.documents.text(uri));
|
|
2438
2391
|
const artifacts = new ProjectArtifacts({
|
|
2392
|
+
controlStack: resolution.controlStack,
|
|
2439
2393
|
inputs: resolution.inputs,
|
|
2440
2394
|
readSnapshot: this.#options.documents.readSnapshot,
|
|
2441
2395
|
onInterpretationError: (uri, error) => {
|
|
@@ -3076,4 +3030,4 @@ function startServer(streams) {
|
|
|
3076
3030
|
//#endregion
|
|
3077
3031
|
export { startServer };
|
|
3078
3032
|
|
|
3079
|
-
//# sourceMappingURL=exports-
|
|
3033
|
+
//# sourceMappingURL=exports-F_cSTVqK.mjs.map
|