carrick 0.3.148 → 0.3.150

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.
@@ -14,15 +14,20 @@
14
14
  * A service-root `jsconfig.json` ranks after those names and before an
15
15
  * ancestor `tsconfig.json` (carrick#3497): tsserver types a JavaScript file
16
16
  * under the jsconfig beside it, not under a config above. Where no ancestor
17
- * config exists the answer stays undefined, as before: the service is then
18
- * typed per file by `fileConfigPath`, which reads the same jsconfig.
17
+ * config exists the answer stays undefined, as before: each file is then
18
+ * typed by `GoverningConfigs` alone, which reads the same jsconfig.
19
19
  *
20
20
  * The walk stops at the scan root, inclusive: a config outside the scanned
21
21
  * tree is never read. With no scan root, or a service outside it, only the
22
22
  * service root is searched.
23
+ *
24
+ * The service config is the fallback of the per-file rule
25
+ * (`GoverningConfigs`, carrick#3497): a file a config inside the service
26
+ * lists is typed under that config.
23
27
  */
24
28
  import * as fs from 'node:fs';
25
29
  import * as path from 'node:path';
30
+ import { ProjectGraph } from './project-references.js';
26
31
  /** The names a service root is searched for, in order. */
27
32
  const SERVICE_ROOT_NAMES = ['tsconfig.json', 'tsconfig.build.json', 'tsconfig.app.json'];
28
33
  /** The root config tsserver types a JavaScript service under, after the names above. */
@@ -68,40 +73,85 @@ export function realPath(p) {
68
73
  /** The names an editor looks for in a file's directory, in order. */
69
74
  const FILE_CONFIG_NAMES = ['tsconfig.json', 'jsconfig.json'];
70
75
  /**
71
- * The config an editor types `file` under, for a service with none at its
72
- * root (carrick#1604): the nearest `tsconfig.json`, then `jsconfig.json`, in
73
- * each directory from the file's up to the service root, inclusive. The
74
- * climb stops after a directory named `node_modules`, as tsserver's does. A file
75
- * outside the service root, or with no config on its way up, has none.
76
+ * The config each file of one service is typed under (carrick#1604,
77
+ * carrick#3497 ruling R-N1): the one the TypeScript language service picks.
78
+ * From the file's directory up to the service root, inclusive, each directory's
79
+ * `tsconfig.json`, else `jsconfig.json`, is asked whether its program, or a
80
+ * project it references, lists the file; the first that does types it (a
81
+ * solution config hands the file to the reference that lists it). A config
82
+ * that lists the file nowhere is passed over. The climb stops after a
83
+ * directory named `node_modules`, as tsserver's does. A file no config inside
84
+ * the service lists falls back to the service config (`findServiceTsconfig`
85
+ * or the named one) and the project of its references that lists the file,
86
+ * else to that config itself; with no service config, to none.
76
87
  *
77
- * `known` caches the answer per directory; pass one map for one service so
78
- * its files share the climb.
88
+ * The scanner's `module_aliases::Governing` is the same rule, and
89
+ * `tests/module_resolution_parity_test.rs` holds both to the compiler's own
90
+ * answer.
79
91
  */
80
- export function fileConfigPath(file, serviceRoot, known = new Map()) {
81
- const root = path.resolve(serviceRoot);
82
- const climbed = [];
83
- let found;
84
- let dir = path.dirname(path.resolve(file));
85
- for (;;) {
86
- const from = path.relative(root, dir);
87
- if (from.startsWith('..') || path.isAbsolute(from))
88
- break;
89
- if (known.has(dir)) {
90
- found = known.get(dir);
91
- break;
92
+ export class GoverningConfigs {
93
+ serviceConfig;
94
+ report;
95
+ root;
96
+ /** Directory -> the config in it, for every directory a climb visited. */
97
+ dirConfigs = new Map();
98
+ /** Config -> its projects; undefined for one that cannot be read. */
99
+ graphs = new Map();
100
+ /**
101
+ * @param serviceRoot the service directory
102
+ * @param serviceConfig the fallback config, absolute, or undefined for none
103
+ * @param report where a config or reference that cannot be read is named
104
+ */
105
+ constructor(serviceRoot, serviceConfig, report = () => { }) {
106
+ this.serviceConfig = serviceConfig;
107
+ this.report = report;
108
+ this.root = path.resolve(serviceRoot);
109
+ }
110
+ /** Absolute path of the config that types `file`, or undefined for none. */
111
+ configFor(file) {
112
+ const absolute = path.resolve(file);
113
+ let dir = path.dirname(absolute);
114
+ for (;;) {
115
+ const from = path.relative(this.root, dir);
116
+ if (from.startsWith('..') || path.isAbsolute(from))
117
+ break;
118
+ const config = this.configIn(dir);
119
+ const owner = config === undefined ? undefined : this.listingOwner(config, absolute);
120
+ if (owner !== undefined)
121
+ return owner;
122
+ // tsserver looks in a `node_modules` directory itself, then stops.
123
+ if (dir === this.root || path.basename(dir) === 'node_modules')
124
+ break;
125
+ dir = path.dirname(dir);
92
126
  }
93
- climbed.push(dir);
94
- const name = FILE_CONFIG_NAMES.find((n) => fs.existsSync(path.join(dir, n)));
95
- if (name !== undefined) {
96
- found = path.join(dir, name);
97
- break;
127
+ if (this.serviceConfig === undefined)
128
+ return undefined;
129
+ return this.listingOwner(this.serviceConfig, absolute) ?? this.serviceConfig;
130
+ }
131
+ configIn(dir) {
132
+ if (!this.dirConfigs.has(dir)) {
133
+ const name = FILE_CONFIG_NAMES.find((n) => fs.existsSync(path.join(dir, n)));
134
+ this.dirConfigs.set(dir, name === undefined ? undefined : path.join(dir, name));
98
135
  }
99
- // tsserver looks in a `node_modules` directory itself, then stops.
100
- if (dir === root || path.basename(dir) === 'node_modules')
101
- break;
102
- dir = path.dirname(dir);
136
+ return this.dirConfigs.get(dir);
137
+ }
138
+ /** The project reached from `config` that lists `file`, absolute. */
139
+ listingOwner(config, file) {
140
+ if (!this.graphs.has(config)) {
141
+ try {
142
+ this.graphs.set(config, { graph: new ProjectGraph(config), reported: 0 });
143
+ }
144
+ catch (err) {
145
+ this.report(`tsconfig ${config} could not be read and was skipped: ${err instanceof Error ? err.message : String(err)}`);
146
+ this.graphs.set(config, undefined);
147
+ }
148
+ }
149
+ const entry = this.graphs.get(config);
150
+ if (entry === undefined)
151
+ return undefined;
152
+ const owner = entry.graph.listingOwnerOf(file);
153
+ entry.graph.diagnostics.slice(entry.reported).forEach(this.report);
154
+ entry.reported = entry.graph.diagnostics.length;
155
+ return owner?.configPath;
103
156
  }
104
- for (const d of climbed)
105
- known.set(d, found);
106
- return found;
107
157
  }
@@ -1203,6 +1203,9 @@ function unbuiltPart(claim) {
1203
1203
  else if ('parts' in name) {
1204
1204
  return 'name.parts';
1205
1205
  }
1206
+ else if ('first' in name) {
1207
+ // Judged in `firstNameOutcome`: its entries are plain slots or the decorated name.
1208
+ }
1206
1209
  else if (!('literal' in name)) {
1207
1210
  // A literal is judged in `judgeOp`, a document or reference slot too; a make's or scope's still is not.
1208
1211
  slots.push({ ...name, document: undefined, ref: undefined });
@@ -2487,12 +2490,18 @@ class DeclarationReader {
2487
2490
  */
2488
2491
  judgeOp(receiver, claim, rules) {
2489
2492
  // Amendment 7, part 3 (carrick#3047): the form says how the service
2490
- // writes the op, and the op kinds a form belongs to.
2493
+ // writes the op, and the op kinds a form belongs to. A `new` receive
2494
+ // subscribes when the export is constructed (carrick-cloud#3139).
2491
2495
  const form = claim.form ?? 'call';
2492
- if (form === 'new' && claim.op !== 'send' && claim.op !== 'request')
2496
+ if (form === 'new' && claim.op !== 'send' && claim.op !== 'request' && claim.op !== 'receive') {
2493
2497
  return unchecked('claim_invalid');
2498
+ }
2494
2499
  if (form === 'decorate' && claim.op !== 'receive')
2495
2500
  return unchecked('claim_invalid');
2501
+ // A name the decorated method gives (amendment 8) is read on a decorate receive only.
2502
+ const decorated = claim.name !== undefined && ('first' in claim.name || ('bound' in claim.name && claim.name.bound === 'decorated'));
2503
+ if (decorated && form !== 'decorate')
2504
+ return unchecked('claim_invalid');
2496
2505
  // `returns` judges the handler a receive op registers.
2497
2506
  if (claim.returns !== undefined && (claim.op !== 'receive' || claim.handler === undefined)) {
2498
2507
  return unchecked('claim_invalid');
@@ -2516,6 +2525,11 @@ class DeclarationReader {
2516
2525
  if (claim.request !== undefined && !requestAtValid(claim))
2517
2526
  return unchecked('claim_invalid');
2518
2527
  const name = claim.name;
2528
+ if (decorated && name !== undefined) {
2529
+ if ('first' in name && (name.first.length < 2 || name.first.length > 4))
2530
+ return unchecked('claim_invalid');
2531
+ return this.decoratedNameOutcome(receiver, claim, 'first' in name ? name.first : [{ bound: 'decorated' }]);
2532
+ }
2519
2533
  // A send carries a payload: a name alone on `send(data)` is the data. An
2520
2534
  // op that runs a function or client it is handed takes its name from
2521
2535
  // what it runs, and one that hands its handler a receiver (a server's
@@ -2644,6 +2658,10 @@ class DeclarationReader {
2644
2658
  const ran = this.boundRunsOutcome(receiver.makerHolding, boundRuns);
2645
2659
  return ran.verdict === 'verified' && requestDropped !== undefined ? { ...ran, requestDropped } : ran;
2646
2660
  }
2661
+ return this.opVerified(callee, bodyMembers, requestDropped);
2662
+ }
2663
+ /** A verified op: the callee's declarations and members, for `labelledMembers`. */
2664
+ opVerified(callee, bodyMembers = [], requestDropped) {
2647
2665
  const declarations = this.declarationsOf(callee);
2648
2666
  const members = callee.named
2649
2667
  ? (callee.named.property.declarations ?? [])
@@ -2656,6 +2674,113 @@ class DeclarationReader {
2656
2674
  ...(requestDropped === undefined ? {} : { requestDropped }),
2657
2675
  };
2658
2676
  }
2677
+ /**
2678
+ * A name read from the first entry the call fills, in order, or from the
2679
+ * decorated method alone (amendment 8 of carrick#2434): a GraphQL root field
2680
+ * written as a method decorator. The op is a decorate receive whose
2681
+ * decorated method is the handler, so it holds no other part. `first` has
2682
+ * two to four entries, none twice, `{ bound: 'decorated' }` only last.
2683
+ *
2684
+ * Strict D2 holds on EVERY overload that returns a method decorator, never
2685
+ * on one: a reader that falls back to the method on `@Query()` would also
2686
+ * write the method's name on `@Query('x')` unless every overload taking a
2687
+ * string there is a `first` entry. Per overload, D2 runs once for each
2688
+ * entry that takes a string there, that entry as the name and the others
2689
+ * accounted for; with none, it runs with no name, and any string slot
2690
+ * competes. Each slot entry takes a string on at least one such overload,
2691
+ * else the reason a name slot that takes none answers.
2692
+ */
2693
+ decoratedNameOutcome(receiver, claim, entries) {
2694
+ if (claim.form !== 'decorate' || claim.op !== 'receive')
2695
+ return unchecked('claim_invalid');
2696
+ const parts = [
2697
+ claim.payload, claim.handler, claim.ack, claim.runs, claim.yields, claim.request, claim.returns,
2698
+ claim.method_key, claim.method_default, claim.options, claim.base,
2699
+ ];
2700
+ if (parts.some(part => part !== undefined))
2701
+ return unchecked('claim_invalid');
2702
+ const slots = [];
2703
+ const seen = new Set();
2704
+ for (const [index, entry] of entries.entries()) {
2705
+ if ('bound' in entry) {
2706
+ if (index !== entries.length - 1)
2707
+ return unchecked('claim_invalid');
2708
+ continue;
2709
+ }
2710
+ const slot = { arg: entry.arg, ...(entry.key === undefined ? {} : { key: entry.key }) };
2711
+ const id = `${slot.arg}.${slot.key ?? ''}`;
2712
+ if (seen.has(id))
2713
+ return unchecked('claim_invalid');
2714
+ seen.add(id);
2715
+ slots.push(slot);
2716
+ }
2717
+ const callee = this.ownCallee(receiver, claim.path ?? [], claim.member, 'call');
2718
+ if ('failure' in callee)
2719
+ return callee.failure;
2720
+ const labels = claim.key_labels ?? {};
2721
+ let best;
2722
+ let decorators = 0;
2723
+ // Per slot entry, why it takes no string on an overload, until one where it does.
2724
+ const unread = new Map(slots.map(slot => [slot, undefined]));
2725
+ const takes = new Set();
2726
+ for (const signature of callee.signatures) {
2727
+ const given = this.decoratorOutcome(signature, 'method');
2728
+ if (given) {
2729
+ best = furthest(best, 1, given);
2730
+ continue;
2731
+ }
2732
+ decorators += 1;
2733
+ const here = [];
2734
+ for (const slot of slots) {
2735
+ const failure = this.nameEntryFailure(signature, slot);
2736
+ if (failure === undefined) {
2737
+ here.push(slot);
2738
+ takes.add(slot);
2739
+ }
2740
+ else {
2741
+ unread.set(slot, furthest(unread.get(slot), failure.rank, failure.outcome));
2742
+ }
2743
+ }
2744
+ if (here.length === 0) {
2745
+ const ambiguity = this.nameSiblings(signature, { positional: new Map(), keyed: new Map() }, new Map(), labels, []);
2746
+ if (ambiguity)
2747
+ return ambiguity;
2748
+ continue;
2749
+ }
2750
+ for (const slot of here) {
2751
+ const layout = this.layout({ name: slot });
2752
+ if ('failure' in layout)
2753
+ return layout.failure;
2754
+ const others = here.filter(other => other !== slot);
2755
+ const result = this.messageSignatureOutcome(signature, layout.value, labels, undefined, others);
2756
+ if (result.rank !== Infinity)
2757
+ return result.outcome;
2758
+ }
2759
+ }
2760
+ if (decorators === 0)
2761
+ return best.outcome;
2762
+ for (const [slot, failure] of unread) {
2763
+ if (!takes.has(slot))
2764
+ return failure.outcome;
2765
+ }
2766
+ return this.opVerified(callee);
2767
+ }
2768
+ /**
2769
+ * Why a `first` slot takes no name string on one overload, or undefined
2770
+ * when it does: as a name slot is read (`messageSignatureOutcome`, steps 1
2771
+ * and 3).
2772
+ */
2773
+ nameEntryFailure(signature, slot) {
2774
+ const declared = this.keyParameterAt(signature, slot.arg);
2775
+ if (declared === undefined)
2776
+ return { rank: 1, outcome: failed('param_missing') };
2777
+ if (slot.key === undefined) {
2778
+ const read = this.throughConditional(declared);
2779
+ return this.acceptsString(read) ? undefined : { rank: 1, outcome: this.slotFailure(read, 'name_not_string') };
2780
+ }
2781
+ const view = this.viewFor(declared, new Map([[slot.key, 'name']]), given => this.runsFailure(given));
2782
+ return 'rank' in view ? view : undefined;
2783
+ }
2659
2784
  /**
2660
2785
  * `form: set` on a send (amendment 7 part 3, carrick#3047): the service
2661
2786
  * assigns the reply (`ctx.body = x`). `member` is a property that `path`
@@ -2899,6 +3024,10 @@ class DeclarationReader {
2899
3024
  * call's other parts.
2900
3025
  */
2901
3026
  methodOutcome(claim, rules, receiver) {
3027
+ // A GraphQL root field written as a decorator states its root word (amendment 8).
3028
+ if (claim.protocol === 'graphql' && claim.form === 'decorate' && claim.method === undefined) {
3029
+ return unchecked('claim_invalid');
3030
+ }
2902
3031
  const words = methodWords(claim, rules);
2903
3032
  // A procedure named by its key (#2474 R6a): a receive op with a handler.
2904
3033
  // On http the label states its method, a route word, and the member names
@@ -3257,9 +3386,10 @@ class DeclarationReader {
3257
3386
  * (design D2, `nameSiblings`).
3258
3387
  *
3259
3388
  * `runsAs` replaces the `runs` predicate (an adapter's collection, #2474
3260
- * R6a); absent, a `runs` slot is a declared function.
3389
+ * R6a); absent, a `runs` slot is a declared function. `others` are a
3390
+ * `first` name's other entries (amendment 8), see `nameSiblings`.
3261
3391
  */
3262
- messageSignatureOutcome(signature, layout, labels, runsAs) {
3392
+ messageSignatureOutcome(signature, layout, labels, runsAs, others) {
3263
3393
  const runsFailure = runsAs ?? ((declared) => this.runsFailure(declared));
3264
3394
  for (const [arg, part] of layout.positional) {
3265
3395
  if (part === 'method') {
@@ -3320,7 +3450,7 @@ class DeclarationReader {
3320
3450
  return view;
3321
3451
  views.set(arg, view.view);
3322
3452
  }
3323
- const ambiguity = this.nameSiblings(signature, layout, views, labels);
3453
+ const ambiguity = this.nameSiblings(signature, layout, views, labels, others);
3324
3454
  if (ambiguity)
3325
3455
  return { rank: 4, outcome: ambiguity };
3326
3456
  return { rank: Infinity, outcome: VERIFIED };
@@ -3411,7 +3541,10 @@ class DeclarationReader {
3411
3541
  * The labels must agree with the claim: at most one key is labelled `name`,
3412
3542
  * and only the claim's own name key; that key is never labelled `not_name`.
3413
3543
  * A `not_name` label for a key an overload does not declare is ignored
3414
- * (one label map serves every overload). No name, no rule.
3544
+ * (one label map serves every overload). No name, no rule, except for a
3545
+ * `first` name (amendment 8): `others` are its other entries that take a
3546
+ * string on this overload, accounted for as the name is, and the rule holds
3547
+ * with no name in the run at all.
3415
3548
  *
3416
3549
  * Rest parameters: a rest the claim puts a payload or handler in belongs
3417
3550
  * wholly to that part; one that holds the name holds other names too; from
@@ -3421,7 +3554,7 @@ class DeclarationReader {
3421
3554
  * cannot be read at all (`...args: Rest<B>`, a conditional on a type
3422
3555
  * parameter), since it could hold a string slot.
3423
3556
  */
3424
- nameSiblings(signature, layout, views, labels) {
3557
+ nameSiblings(signature, layout, views, labels, others) {
3425
3558
  const namedAt = [...layout.positional].find(([, part]) => part === 'name')?.[0];
3426
3559
  let nameKey;
3427
3560
  for (const keys of layout.keyed.values()) {
@@ -3429,15 +3562,28 @@ class DeclarationReader {
3429
3562
  if (part === 'name')
3430
3563
  nameKey = key;
3431
3564
  }
3432
- if (namedAt === undefined && nameKey === undefined)
3565
+ // A `first` name (amendment 8) is judged with no name of its own too: a
3566
+ // string slot there is one a fallback name would be written over.
3567
+ if (namedAt === undefined && nameKey === undefined && others === undefined)
3433
3568
  return undefined;
3434
3569
  const ambiguous = failed('name_ambiguous');
3570
+ // The `first` entries beside this run's name, which name the op on another
3571
+ // call: a position, or a key of the object at one.
3572
+ const otherAt = new Set((others ?? []).filter(slot => slot.key === undefined).map(slot => slot.arg));
3573
+ const otherKeys = new Map();
3574
+ for (const slot of others ?? []) {
3575
+ if (slot.key !== undefined)
3576
+ otherKeys.set(slot.arg, (otherKeys.get(slot.arg) ?? new Set()).add(slot.key));
3577
+ }
3578
+ const nameKeys = new Set([...otherKeys.values()].flatMap(keys => [...keys]));
3579
+ if (nameKey !== undefined)
3580
+ nameKeys.add(nameKey);
3435
3581
  const nameLabels = Object.keys(labels).filter(key => labels[key] === 'name');
3436
3582
  if (nameLabels.length > 1)
3437
3583
  return ambiguous;
3438
- if (nameLabels.length === 1 && nameLabels[0] !== nameKey)
3584
+ if (nameLabels.length === 1 && !nameKeys.has(nameLabels[0]))
3439
3585
  return ambiguous;
3440
- if (nameKey !== undefined && labels[nameKey] === 'not_name')
3586
+ if ([...nameKeys].some(key => labels[key] === 'not_name'))
3441
3587
  return ambiguous;
3442
3588
  // A string key at the call the claim neither assigns nor labels.
3443
3589
  const unaccountedKey = (keys, assigned) => keys.some(key => !assigned.has(key) && labels[key] !== 'not_name');
@@ -3446,11 +3592,14 @@ class DeclarationReader {
3446
3592
  // An argument the claim gives no part: a string, an object with a string
3447
3593
  // key nobody accounts for, or a rest the verifier cannot read, which could
3448
3594
  // hold either and no label can account for (fail closed, carrick#1687).
3449
- const competes = (slot) => slot === VARIADIC || takesString(slot) || unaccountedKey(this.stringKeys(slot), none);
3595
+ const competes = (slot, i) => slot === VARIADIC ||
3596
+ takesString(slot) ||
3597
+ unaccountedKey(this.stringKeys(slot), (i === undefined ? undefined : otherKeys.get(i)) ?? none);
3450
3598
  // Every object the claim reads keys of: its other string keys.
3451
3599
  for (const [arg, keys] of layout.keyed) {
3452
3600
  const view = views.get(arg);
3453
- if (view && unaccountedKey(this.stringKeys(view), keys))
3601
+ const accounted = new Set([...keys.keys(), ...(otherKeys.get(arg) ?? [])]);
3602
+ if (view && unaccountedKey(this.stringKeys(view), accounted))
3454
3603
  return ambiguous;
3455
3604
  }
3456
3605
  const parameters = signature.getParameters();
@@ -3458,11 +3607,14 @@ class DeclarationReader {
3458
3607
  const lastDeclaration = last?.valueDeclaration;
3459
3608
  const restIndex = lastDeclaration && ts.isParameter(lastDeclaration) && lastDeclaration.dotDotDotToken ? parameters.length - 1 : -1;
3460
3609
  const fixed = restIndex === -1 ? parameters.length : restIndex;
3461
- const assigned = (i) => layout.positional.has(i) || layout.keyed.has(i);
3610
+ const assigned = (i) => layout.positional.has(i) || layout.keyed.has(i) || otherAt.has(i);
3611
+ // A rest never holds a `first` position: it would hold other names too.
3612
+ if (restIndex !== -1 && [...otherAt].some(arg => arg >= restIndex))
3613
+ return ambiguous;
3462
3614
  for (let i = 0; i < fixed; i++) {
3463
3615
  if (assigned(i))
3464
3616
  continue;
3465
- if (competes(this.keyParameterAt(signature, i)))
3617
+ if (competes(this.keyParameterAt(signature, i), i))
3466
3618
  return ambiguous;
3467
3619
  }
3468
3620
  if (restIndex === -1)
@@ -3476,7 +3628,7 @@ class DeclarationReader {
3476
3628
  for (let i = restIndex; i < restIndex + fixedLength; i++) {
3477
3629
  if (assigned(i))
3478
3630
  continue;
3479
- if (competes(this.keyParameterAt(signature, i)))
3631
+ if (competes(this.keyParameterAt(signature, i), i))
3480
3632
  return ambiguous;
3481
3633
  }
3482
3634
  if (variable !== -1) {
@@ -51,7 +51,7 @@ import { ts } from 'ts-morph';
51
51
  import type { ProjectLoader } from './project-loader.js';
52
52
  import type { PositionRowsCounts } from './types.js';
53
53
  /** The format's version, written in the header. */
54
- export declare const POSITION_ROWS_VERSION = 4;
54
+ export declare const POSITION_ROWS_VERSION = 5;
55
55
  /** The type is `any`, declared or inferred. Never set with the error type. */
56
56
  export declare const FLAG_ANY = 1;
57
57
  /** The type is the compiler's error type: something did not resolve. */
@@ -86,7 +86,7 @@ export declare const FLAG_RUNS_HANDED = 128;
86
86
  export declare const DECL_CAP = 16;
87
87
  /** The kinds {@link kindOf} gives a node; `decl` and `jsx` rows are written beside them. */
88
88
  export type NodeKind = 'call' | 'member' | 'compare' | 'ident';
89
- export type PositionKind = NodeKind | 'decl' | 'jsx';
89
+ export type PositionKind = NodeKind | 'decl' | 'jsx' | 'typed_decl';
90
90
  /** `[kind, start, end, symbol, decl_file, decl_line, decl_package, type_text, flags]` */
91
91
  export type PositionRow = [
92
92
  PositionKind,
@@ -247,6 +247,16 @@ export declare class PositionWalker {
247
247
  * A throw writes one row flagged {@link FLAG_CHECKER_THREW}.
248
248
  */
249
249
  private declRows;
250
+ /**
251
+ * The `typed_decl` row of a call (carrick#2448): the callee is a value
252
+ * (a parameter, a property, a local) whose type is a named function's own
253
+ * (`send: typeof fetch`), so the compiler gives the type a symbol whose
254
+ * declaration is that function's. Written only when the callee symbol is
255
+ * not already that declaration and the type's symbol is named (an
256
+ * anonymous function or type literal is `__function` / `__type`), so a
257
+ * direct call or a method call writes none.
258
+ */
259
+ private typedDeclRow;
250
260
  /** The row's symbol, following aliases to a target that has a declaration. */
251
261
  symbolOf(kind: PositionKind, node: ts.Node): ts.Symbol | undefined;
252
262
  /**
@@ -56,7 +56,7 @@ import { WriteGuard, installedPackageDirectory, isDeclarationFileName, moduleExp
56
56
  import { attributedDeclaration, installedPackageOf, typeDeclaration } from './declaration-attribution.js';
57
57
  import { typeToStringAsDeclared } from './print-type.js';
58
58
  /** The format's version, written in the header. */
59
- export const POSITION_ROWS_VERSION = 4;
59
+ export const POSITION_ROWS_VERSION = 5;
60
60
  /** The type is `any`, declared or inferred. Never set with the error type. */
61
61
  export const FLAG_ANY = 1;
62
62
  /** The type is the compiler's error type: something did not resolve. */
@@ -426,6 +426,11 @@ export class PositionWalker {
426
426
  for (const decl of this.declRows(kind, node))
427
427
  rows.push(['decl', row[1], row[2], ...tail(decl)]);
428
428
  }
429
+ if (kind === 'call' && !(row[8] & FLAG_CHECKER_THREW)) {
430
+ const typed = this.typedDeclRow(node, row[1], row[2]);
431
+ if (typed)
432
+ rows.push(typed);
433
+ }
429
434
  }
430
435
  if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
431
436
  rows.push(this.row('jsx', node.tagName, sourceFile));
@@ -743,6 +748,45 @@ export class PositionWalker {
743
748
  rows.sort((a, b) => compareNames(a.row[4], b.row[4]) || a.start - b.start);
744
749
  return rows.map(({ row }) => row);
745
750
  }
751
+ /**
752
+ * The `typed_decl` row of a call (carrick#2448): the callee is a value
753
+ * (a parameter, a property, a local) whose type is a named function's own
754
+ * (`send: typeof fetch`), so the compiler gives the type a symbol whose
755
+ * declaration is that function's. Written only when the callee symbol is
756
+ * not already that declaration and the type's symbol is named (an
757
+ * anonymous function or type literal is `__function` / `__type`), so a
758
+ * direct call or a method call writes none.
759
+ */
760
+ typedDeclRow(node, start, end) {
761
+ if (!ts.isCallExpression(node))
762
+ return undefined;
763
+ try {
764
+ const symbol = this.symbolOf('call', node);
765
+ if (!symbol)
766
+ return undefined;
767
+ const type = this.checker.getNonNullableType(this.checker.getTypeAtLocation(node.expression));
768
+ const typeSymbol = type.symbol;
769
+ if (!typeSymbol || typeSymbol.name.startsWith('__'))
770
+ return undefined;
771
+ if (type.getCallSignatures().length === 0)
772
+ return undefined;
773
+ const declaration = this.typeDeclaration(type);
774
+ if (!declaration)
775
+ return undefined;
776
+ const own = symbol.declarations ?? [];
777
+ if (own.some((d) => (typeSymbol.declarations ?? []).includes(d)))
778
+ return undefined;
779
+ const file = declaration.getSourceFile();
780
+ const { declFile, declLine, declPackage } = this.located(file, declaration.getStart(file));
781
+ let flags = this.publication(typeSymbol, declaration);
782
+ if (declFile === null)
783
+ flags |= FLAG_DECLARATION_UNNAMED;
784
+ return ['typed_decl', start, end, ts.symbolName(typeSymbol), declFile, declLine, declPackage, null, flags];
785
+ }
786
+ catch {
787
+ return undefined;
788
+ }
789
+ }
746
790
  /** The row's symbol, following aliases to a target that has a declaration. */
747
791
  symbolOf(kind, node) {
748
792
  let symbol;
@@ -929,6 +973,7 @@ function nameNodeOf(kind, node) {
929
973
  case 'ident':
930
974
  return node;
931
975
  case 'decl':
976
+ case 'typed_decl':
932
977
  return undefined;
933
978
  case 'jsx':
934
979
  // The tag: `<Badge>`, `<ui.Button>`, `<this.Panel>`; a namespaced
@@ -81,17 +81,12 @@ export declare class ProjectLoader {
81
81
  /** The tsconfig the service names, when the project is built from one. */
82
82
  private namedTsconfigPath;
83
83
  /**
84
- * Set when the service has no config at or above its root: each file is then
85
- * typed under the nearest `tsconfig.json`/`jsconfig.json` on its way up to
86
- * the service root (carrick#1604), and the default project holds the rest.
84
+ * The config each file is typed under (carrick#1604, carrick#3497): set for
85
+ * a service built from a tsconfig, with it as the fallback, and for one
86
+ * with no config at or above its root, with none. Unset (a snapshot or a
87
+ * Deno project), every file is the default project's.
87
88
  */
88
- private inferredService;
89
- /** The per-directory answers of `fileConfigPath` for this service. */
90
- private readonly fileConfigs;
91
- /** The reference owner rule of each config a file was found under. */
92
- private readonly ownerRules;
93
- /** Each file's owning config (carrick#1604), resolved on first use. */
94
- private configPathFor;
89
+ private governing;
95
90
  /** Programs built for owning projects other than the named tsconfig. */
96
91
  private readonly ownerProjects;
97
92
  private readonly repoRoot;
@@ -128,22 +123,15 @@ export declare class ProjectLoader {
128
123
  */
129
124
  private projectFromConfig;
130
125
  /**
131
- * Which project types `file` (carrick#1604): the key of its owning
132
- * project's program, or `''` for the default one. In a tsconfig that
133
- * references other projects, a file belongs to the first project in search
134
- * order (the named config, then its references depth-first, in declared
135
- * order) that lists it while none of its own references does (carrick#2418),
136
- * and is typed under that project's options. A file no project includes, and every request that
137
- * names no file, uses the default project, built from the named tsconfig
138
- * as before.
126
+ * Which project types `file` (carrick#1604, carrick#3497): the key of its
127
+ * owning project's program, or `''` for the default one. The owner is the
128
+ * config `GoverningConfigs` picks: the nearest config inside the service
129
+ * whose program, or a project it references (carrick#2418's search order),
130
+ * lists the file, else the service's tsconfig. The service's own tsconfig,
131
+ * every request that names no file, and a file no config governs use the
132
+ * default project.
139
133
  */
140
134
  projectKeyFor(file?: string): string;
141
- /**
142
- * `projectKeyFor` for a service with no config at its root: the owner of the
143
- * nearest config on the file's way up to the service root, or `''` (the
144
- * default project, under the inferred options) for a file with none.
145
- */
146
- private inferredKeyFor;
147
135
  /**
148
136
  * The project behind a key from `projectKeyFor`, built on first use and
149
137
  * kept: a service whose files all belong to one project builds one.