@atscript/core 0.1.98 → 0.1.100

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/index.d.ts CHANGED
@@ -47,6 +47,8 @@ declare class Token {
47
47
  constructor(_data: TLexicalToken);
48
48
  toString(): string;
49
49
  clone(replace: Partial<TLexicalToken>): Token;
50
+ /** The underlying lexical token (for re-iterating its children). */
51
+ get lexicalToken(): TLexicalToken;
50
52
  get text(): string;
51
53
  get type(): "number" | "annotation" | "comment" | "punctuation" | "identifier" | "text" | "block" | "unknown" | "regexp" | "query";
52
54
  get range(): {
@@ -108,6 +110,16 @@ declare class Token {
108
110
  * Parsed query expression tree (for query-type annotation arguments)
109
111
  */
110
112
  queryNode?: SemanticQueryNode;
113
+ /** The parsed tree of a backtick argument — whichever of the three it was parsed as. */
114
+ get backtickNode(): SemanticQueryNode | SemanticExprNode | SemanticOrderNode | undefined;
115
+ /**
116
+ * Parsed arithmetic expression (for expr-type annotation arguments)
117
+ */
118
+ exprNode?: SemanticExprNode;
119
+ /**
120
+ * Parsed ordering (for order-type annotation arguments)
121
+ */
122
+ orderNode?: SemanticOrderNode;
111
123
  }
112
124
 
113
125
  interface TPluginManagers {
@@ -520,10 +532,37 @@ declare class AtscriptDoc {
520
532
  private _annotateNodesByTarget;
521
533
  get text(): string;
522
534
  update(text: string, debug?: boolean): void;
535
+ /** Lexical backtick tokens already parsed by `registerAnnotation`. */
536
+ private parsedBacktickArgs;
537
+ /**
538
+ * Backtick arguments of annotations that never get registered (dangling at
539
+ * EOF, or followed by a syntax error) are still parsed for diagnostics — by
540
+ * the argument spec of the preceding annotation when it resolves, else as a
541
+ * query predicate.
542
+ */
543
+ private parseUnregisteredBacktickArgs;
544
+ /**
545
+ * Parse a backtick argument by its spec type: `expr` / `order` get their own
546
+ * grammar; anything else (unknown annotation, position beyond the spec) parses
547
+ * as a query predicate.
548
+ */
549
+ private parseBacktickArgAs;
523
550
  cleanup(): void;
524
551
  private registerNodes;
525
552
  resolvedAnnotations: Token[];
526
553
  annotations: TAnnotationTokens[];
554
+ /**
555
+ * Annotation tokens survive merges across refs, chain refs and `extends`
556
+ * unchanged, so they are keyed by identity to the document that declared them.
557
+ */
558
+ private static readonly annotationOrigins;
559
+ /**
560
+ * The document in which the given annotation was written (and whose imports
561
+ * its type-reference arguments resolve against). Annotations inherited into
562
+ * another document through a chain ref, `extends` or `annotate` keep the
563
+ * declaring document. `undefined` for annotations never registered on a doc.
564
+ */
565
+ annotationOrigin(annotation: TAnnotationTokens): AtscriptDoc | undefined;
527
566
  registerAnnotation(annotationTokens: TAnnotationTokens): void;
528
567
  /**
529
568
  * Recursively resolves a type reference (and any property chain) to find the final underlying definition.
@@ -570,6 +609,18 @@ declare class AtscriptDoc {
570
609
  * resolve through the target interface rather than as top-level definitions.
571
610
  */
572
611
  annotateBlockAt(line: number, character: number): SemanticAnnotateNode | undefined;
612
+ /**
613
+ * The definition an annotated node stands for, with the document that declares it:
614
+ * a prop / type declaration's own definition, or — for an `annotate` block entry —
615
+ * the type of the target property the entry names (`annotate Host { name @x.y }`
616
+ * → the type of `Host.name`). Plugin hooks use it to introspect the field an
617
+ * annotation sits on, whether it is written inline or in an annotate block.
618
+ * `undefined` when the node has no definition or the entry does not resolve.
619
+ */
620
+ annotatedDefinition(node: SemanticNode | undefined): {
621
+ def: SemanticNode;
622
+ doc: AtscriptDoc;
623
+ } | undefined;
573
624
  /**
574
625
  * Collects ad-hoc annotations from all `annotate` blocks targeting a given type/interface.
575
626
  * Returns a map of property path (dot-joined) → annotations array.
@@ -636,6 +687,11 @@ declare class AtscriptDoc {
636
687
  doc?: AtscriptDoc;
637
688
  token?: Token;
638
689
  } | undefined;
690
+ /** Pushes an "Unknown identifier" error when `t` is not defined; returns whether it was. */
691
+ private reportUnknownIdentifier;
692
+ /** Definition link from `token` to `target`, or to what the token resolves to when omitted. */
693
+ private definitionLink;
694
+ private toRangeTarget;
639
695
  getToDefinitionAt(line: number, character: number): {
640
696
  targetUri: string;
641
697
  targetRange: {
@@ -745,7 +801,8 @@ declare class SemanticQueryNode extends SemanticNode {
745
801
  sourceToken: Token;
746
802
  constructor();
747
803
  registerAtDocument(doc: AtscriptDoc): void;
748
- private propagateQueryArgToken;
804
+ /** Every field ref of the predicate (both sides of comparisons), in source order. */
805
+ fieldRefs(): SemanticQueryFieldRefNode[];
749
806
  }
750
807
  declare class SemanticQueryLogicalNode extends SemanticNode {
751
808
  operator: TQueryLogicalOperator;
@@ -777,6 +834,54 @@ declare class SemanticQueryValueListNode extends SemanticNode {
777
834
  constructor();
778
835
  registerAtDocument(doc: AtscriptDoc): void;
779
836
  }
837
+ type TExprBinaryOperator = '+' | '-' | '*' | '/';
838
+ type SemanticExprItemNode = SemanticExprBinaryNode | SemanticExprUnaryNode | SemanticExprCallNode | SemanticExprNumberNode | SemanticQueryFieldRefNode;
839
+ /** Root of a parsed `expr` argument (closed arithmetic over field refs). */
840
+ declare class SemanticExprNode extends SemanticNode {
841
+ expression: SemanticExprItemNode;
842
+ sourceToken: Token;
843
+ constructor();
844
+ /** Every field-ref leaf of the expression, in source order. */
845
+ fieldRefs(): SemanticQueryFieldRefNode[];
846
+ registerAtDocument(doc: AtscriptDoc): void;
847
+ }
848
+ declare class SemanticExprBinaryNode extends SemanticNode {
849
+ op: TExprBinaryOperator;
850
+ left: SemanticExprItemNode;
851
+ right: SemanticExprItemNode;
852
+ constructor();
853
+ }
854
+ declare class SemanticExprUnaryNode extends SemanticNode {
855
+ op: "neg";
856
+ operand: SemanticExprItemNode;
857
+ constructor();
858
+ }
859
+ declare class SemanticExprCallNode extends SemanticNode {
860
+ fn: "coalesce";
861
+ args: SemanticExprItemNode[];
862
+ constructor();
863
+ }
864
+ declare class SemanticExprNumberNode extends SemanticNode {
865
+ valueToken: Token;
866
+ /** Numeric value (sign already applied when split from a signed number token). */
867
+ value: number;
868
+ constructor();
869
+ }
870
+ interface TOrderItem {
871
+ ref: SemanticQueryFieldRefNode;
872
+ desc: boolean;
873
+ /** The `asc` / `desc` keyword token, when written. */
874
+ dirToken?: Token;
875
+ }
876
+ /** Root of a parsed `order` argument: `key (asc|desc)?, …`. */
877
+ declare class SemanticOrderNode extends SemanticNode {
878
+ items: TOrderItem[];
879
+ sourceToken: Token;
880
+ constructor();
881
+ /** Every order key, in source order. */
882
+ fieldRefs(): SemanticQueryFieldRefNode[];
883
+ registerAtDocument(doc: AtscriptDoc): void;
884
+ }
780
885
 
781
886
  declare class SemanticArrayNode extends SemanticNode {
782
887
  constructor();
@@ -933,21 +1038,56 @@ interface TQueryScope {
933
1038
  */
934
1039
  unqualifiedTarget: string | null;
935
1040
  }
1041
+ /** Annotation argument types written in backticks, each parsed by its own grammar. */
1042
+ type TBacktickArgKind = 'query' | 'expr' | 'order';
1043
+ /** Whether an annotation argument type is written in backticks (`query`, `expr`, `order`). */
1044
+ declare function isBacktickArgType(type: string | undefined): type is TBacktickArgKind;
1045
+ /**
1046
+ * One value a `string` / `number` annotation argument may take (returned by the `valueScope`
1047
+ * hook), for editor completion and go-to-definition.
1048
+ */
1049
+ interface TValueCandidate {
1050
+ /** The argument value as written without quotes (`open` for `'open'`). */
1051
+ value: string;
1052
+ /** Where the value is declared; go-to-definition on the argument jumps there. */
1053
+ definition?: {
1054
+ doc: AtscriptDoc;
1055
+ token: Token;
1056
+ };
1057
+ /** Shown beside the value in the completion list. */
1058
+ documentation?: string;
1059
+ }
936
1060
  interface TAnnotationArgument {
937
1061
  optional?: boolean;
938
1062
  name: string;
939
- type: 'string' | 'number' | 'boolean' | 'ref' | 'query';
1063
+ /**
1064
+ * - `query`: backtick predicate (`status = 'open' and Issue.overdue = true`)
1065
+ * - `expr`: backtick arithmetic over field refs (`openCount * 10 + coalesce(overdue, 0)`):
1066
+ * `+ - * /`, unary `-`, parentheses, numeric literals, `coalesce(a, b, …)`
1067
+ * - `order`: backtick ordering (`raisedAt desc, id`): field refs with optional `asc` / `desc`
1068
+ */
1069
+ type: 'string' | 'number' | 'boolean' | 'ref' | TBacktickArgKind;
940
1070
  description?: string;
941
1071
  values?: string[];
942
1072
  /**
943
- * Editor field scope of a `query` or `string` argument. Called with the argument token
944
- * and the document that holds it; return `undefined` when the scope cannot be determined.
945
- * - `query`: the types the backtick expression may reference (drives completion, hover,
946
- * go-to-definition, find-references and rename of its field refs).
1073
+ * Editor field scope of a `query`, `expr`, `order` or `string` argument. Called with the
1074
+ * argument token and the document that holds it; return `undefined` when the scope cannot
1075
+ * be determined.
1076
+ * - `query` / `expr` / `order`: the types the backtick expression may reference (drives
1077
+ * completion, hover, go-to-definition, find-references and rename of its field refs).
947
1078
  * - `string`: the argument is a (dotted) field path of `unqualifiedTarget` (`'amount'`,
948
1079
  * `'address.city'`) — same editor features on the string; `allowedTypes` is unused.
949
1080
  */
950
1081
  fieldScope?: (argToken: Token, doc: AtscriptDoc) => TQueryScope | undefined;
1082
+ /**
1083
+ * Editor value scope of a `string` or `number` argument that names one of a closed set of
1084
+ * values declared elsewhere in the document (the literals of the annotated field's union,
1085
+ * say). Called with the annotation's main token (its `parentNode` is the annotated node)
1086
+ * and the document that holds it; return `undefined` when the set cannot be determined.
1087
+ * Completion offers the candidates, go-to-definition on the argument follows
1088
+ * `TValueCandidate.definition`. Candidates are advisory — it does not validate.
1089
+ */
1090
+ valueScope?: (annotationToken: Token, doc: AtscriptDoc) => TValueCandidate[] | undefined;
951
1091
  /**
952
1092
  * For a `ref` argument: filters the type names offered by completion.
953
1093
  * Called with each candidate declaration and the document that declares it;
@@ -1127,6 +1267,22 @@ interface TFieldRefTarget {
1127
1267
  /** Document that declares `prop`. */
1128
1268
  doc: AtscriptDoc;
1129
1269
  }
1270
+ /**
1271
+ * The annotation an argument token belongs to, found among the annotations of the annotated
1272
+ * node (`argToken.parentNode`, a prop or an annotate entry). For `fieldScope` hooks that scope
1273
+ * an argument by its siblings (`getSiblingAnnotation(arg)?.args[0]?.text`).
1274
+ */
1275
+ declare function getSiblingAnnotation(argToken: Token): TAnnotationTokens | undefined;
1276
+ /**
1277
+ * The values an annotation argument may take, from the `valueScope` hook of its spec
1278
+ * (`undefined` when the argument declares none or the set cannot be determined).
1279
+ */
1280
+ declare function getValueCandidates(annotationToken: Token, argIndex: number, doc: AtscriptDoc): TValueCandidate[] | undefined;
1281
+ /**
1282
+ * The declared value a value-argument token names (`valueScope`), or `undefined` when the token
1283
+ * is not a value argument or names no candidate.
1284
+ */
1285
+ declare function getDeclaredValue(token: Token, doc: AtscriptDoc): TValueCandidate | undefined;
1130
1286
  /**
1131
1287
  * Field scope of an annotation argument: the answer of the argument spec's `fieldScope`
1132
1288
  * hook when it declares one, otherwise the deprecated built-in `@db.*` query rules.
@@ -1185,14 +1341,35 @@ type TQueryCursorContext = {
1185
1341
  type: 'after-operator';
1186
1342
  } | {
1187
1343
  type: 'after-comparison';
1344
+ }
1345
+ /** `expr`: after a field, a number or `)` — an arithmetic operator follows. */
1346
+ | {
1347
+ type: 'after-operand';
1348
+ }
1349
+ /** `order`: after an order key — `asc`, `desc` or `,` follows. */
1350
+ | {
1351
+ type: 'after-order-key';
1352
+ }
1353
+ /** `order`: after `asc` / `desc` — `,` follows. */
1354
+ | {
1355
+ type: 'after-order-direction';
1188
1356
  };
1189
1357
  /**
1190
1358
  * Analyze text inside backticks up to cursor position
1191
1359
  * to determine what kind of completions to offer.
1192
1360
  * Uses lightweight text scanning, not full AST parsing,
1193
1361
  * so it works on incomplete/mid-typing input.
1362
+ *
1363
+ * `mode` selects the grammar of the argument (default `query`).
1194
1364
  */
1195
- declare function analyzeQueryCursorContext(textBeforeCursor: string): TQueryCursorContext;
1365
+ declare function analyzeQueryCursorContext(textBeforeCursor: string, mode?: TBacktickArgKind): TQueryCursorContext;
1366
+
1367
+ /** Vocabulary of `expr` / `order` arguments: arithmetic operators, functions, order directions. */
1368
+ declare const BACKTICK_ARG_VOCABULARY: {
1369
+ readonly arithmeticOps: readonly ["+", "-", "*", "/"];
1370
+ readonly functions: readonly ["coalesce"];
1371
+ readonly orderDirections: readonly ["asc", "desc"];
1372
+ };
1196
1373
 
1197
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1198
- export type { SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TDbConfig, TDbConfigDeclarative, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken };
1374
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1375
+ export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TBacktickArgKind, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken, TValueCandidate };