typescript 7.1.0-dev.20261001.1 → 7.1.0-dev.20261003.1
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/api/async/api.d.ts +73 -42
- package/dist/api/async/api.d.ts.map +1 -1
- package/dist/api/async/api.js +224 -68
- package/dist/api/async/api.js.map +1 -1
- package/dist/api/async/client.d.ts.map +1 -1
- package/dist/api/async/client.js +73 -16
- package/dist/api/async/client.js.map +1 -1
- package/dist/api/async/types.d.ts +4 -3
- package/dist/api/async/types.d.ts.map +1 -1
- package/dist/api/compilerOptions.generated.d.ts +123 -0
- package/dist/api/compilerOptions.generated.d.ts.map +1 -0
- package/dist/api/compilerOptions.generated.js +8 -0
- package/dist/api/compilerOptions.generated.js.map +1 -0
- package/dist/api/diagnosticFormatter.d.ts.map +1 -1
- package/dist/api/diagnosticFormatter.js.map +1 -1
- package/dist/api/fs.d.ts +10 -8
- package/dist/api/fs.d.ts.map +1 -1
- package/dist/api/fs.js.map +1 -1
- package/dist/api/node/encoder.generated.js +1 -1
- package/dist/api/node/encoder.generated.js.map +1 -1
- package/dist/api/node/node.d.ts +18 -10
- package/dist/api/node/node.d.ts.map +1 -1
- package/dist/api/node/node.generated.js +1 -1
- package/dist/api/node/node.generated.js.map +1 -1
- package/dist/api/node/node.infrastructure.d.ts.map +1 -1
- package/dist/api/node/node.infrastructure.js.map +1 -1
- package/dist/api/node/node.js +39 -11
- package/dist/api/node/node.js.map +1 -1
- package/dist/api/path.d.ts +46 -9
- package/dist/api/path.d.ts.map +1 -1
- package/dist/api/path.js +365 -28
- package/dist/api/path.js.map +1 -1
- package/dist/api/prepareCompilerOptions.generated.d.ts +5 -0
- package/dist/api/prepareCompilerOptions.generated.d.ts.map +1 -0
- package/dist/api/prepareCompilerOptions.generated.js +24 -0
- package/dist/api/prepareCompilerOptions.generated.js.map +1 -0
- package/dist/api/proto.generated.d.ts +223 -172
- package/dist/api/proto.generated.d.ts.map +1 -1
- package/dist/api/proto.generated.js +3 -0
- package/dist/api/proto.generated.js.map +1 -1
- package/dist/api/sourceFileCache.d.ts +15 -9
- package/dist/api/sourceFileCache.d.ts.map +1 -1
- package/dist/api/sourceFileCache.js +30 -12
- package/dist/api/sourceFileCache.js.map +1 -1
- package/dist/api/sync/api.d.ts +101 -49
- package/dist/api/sync/api.d.ts.map +1 -1
- package/dist/api/sync/api.js +314 -86
- package/dist/api/sync/api.js.map +1 -1
- package/dist/api/sync/types.d.ts +4 -3
- package/dist/api/sync/types.d.ts.map +1 -1
- package/dist/api/typedPaths.d.ts +3 -0
- package/dist/api/typedPaths.d.ts.map +1 -0
- package/dist/api/typedPaths.js +2 -0
- package/dist/api/typedPaths.js.map +1 -0
- package/dist/ast/ast.d.ts +58 -7
- package/dist/ast/ast.d.ts.map +1 -1
- package/dist/ast/ast.generated.d.ts +3 -3
- package/dist/ast/ast.generated.d.ts.map +1 -1
- package/dist/ast/factory.generated.d.ts +2 -2
- package/dist/ast/factory.generated.d.ts.map +1 -1
- package/dist/ast/factory.generated.js.map +1 -1
- package/dist/ast/is.generated.d.ts.map +1 -1
- package/dist/ast/is.generated.js +2 -1
- package/dist/ast/is.generated.js.map +1 -1
- package/dist/ast/scanner.d.ts.map +1 -1
- package/dist/ast/scanner.js +1 -0
- package/dist/ast/scanner.js.map +1 -1
- package/dist/enums/caseSensitivity.d.ts +2 -0
- package/dist/enums/caseSensitivity.d.ts.map +1 -0
- package/dist/enums/caseSensitivity.enum.d.ts +5 -0
- package/dist/enums/caseSensitivity.enum.d.ts.map +1 -0
- package/dist/enums/caseSensitivity.enum.js +7 -0
- package/dist/enums/caseSensitivity.enum.js.map +1 -0
- package/dist/enums/caseSensitivity.js +7 -0
- package/dist/enums/caseSensitivity.js.map +1 -0
- package/dist/enums/jsxEmit.enum.js +1 -1
- package/dist/enums/jsxEmit.enum.js.map +1 -1
- package/dist/enums/jsxEmit.js +1 -1
- package/dist/enums/jsxEmit.js.map +1 -1
- package/dist/enums/moduleDetectionKind.enum.js +1 -1
- package/dist/enums/moduleDetectionKind.enum.js.map +1 -1
- package/dist/enums/moduleDetectionKind.js +1 -1
- package/dist/enums/moduleDetectionKind.js.map +1 -1
- package/dist/enums/moduleKind.enum.js +1 -1
- package/dist/enums/moduleKind.enum.js.map +1 -1
- package/dist/enums/moduleKind.js +1 -1
- package/dist/enums/moduleKind.js.map +1 -1
- package/dist/enums/moduleResolutionKind.enum.js +1 -1
- package/dist/enums/moduleResolutionKind.enum.js.map +1 -1
- package/dist/enums/moduleResolutionKind.js +1 -1
- package/dist/enums/moduleResolutionKind.js.map +1 -1
- package/dist/enums/newLineKind.enum.js +1 -1
- package/dist/enums/newLineKind.enum.js.map +1 -1
- package/dist/enums/newLineKind.js +1 -1
- package/dist/enums/newLineKind.js.map +1 -1
- package/dist/enums/scriptTarget.d.ts.map +1 -1
- package/dist/enums/scriptTarget.enum.d.ts.map +1 -1
- package/dist/enums/scriptTarget.enum.js +1 -0
- package/dist/enums/scriptTarget.enum.js.map +1 -1
- package/dist/enums/scriptTarget.js +1 -0
- package/dist/enums/scriptTarget.js.map +1 -1
- package/dist/enums/syntaxKind.enum.d.ts +198 -197
- package/dist/enums/syntaxKind.enum.d.ts.map +1 -1
- package/dist/enums/syntaxKind.enum.js +199 -198
- package/dist/enums/syntaxKind.enum.js.map +1 -1
- package/dist/enums/syntaxKind.js +199 -198
- package/dist/enums/syntaxKind.js.map +1 -1
- package/dist/vscode/extensionApi.d.ts +56 -0
- package/dist/vscode/extensionApi.d.ts.map +1 -0
- package/dist/vscode/extensionApi.js +2 -0
- package/dist/vscode/extensionApi.js.map +1 -0
- package/dist/vscode/protocol.generated.d.ts +2886 -0
- package/dist/vscode/protocol.generated.d.ts.map +1 -0
- package/dist/vscode/protocol.generated.js +4 -0
- package/dist/vscode/protocol.generated.js.map +1 -0
- package/package.json +16 -9
- package/schemas/jsconfig.schema.json +2207 -0
- package/schemas/tsconfig.schema.json +2206 -0
package/dist/api/sync/api.js
CHANGED
|
@@ -22,9 +22,10 @@ import { TypePredicateKind } from "#enums/typePredicateKind";
|
|
|
22
22
|
import { ModifierFlags, unescapeLeadingUnderscores, } from "../../ast/index.js";
|
|
23
23
|
import { assertNever } from "../../internal/utils.js";
|
|
24
24
|
import { encodeNode, uint8ArrayToBase64, } from "../node/encoder.js";
|
|
25
|
-
import { decodeNode, getNodeId,
|
|
25
|
+
import { decodeNode, getNodeId, parseNodeHandleFromCompiler, readParseOptionsKey, readSourceFileHash, readSourceFileLease, RemoteNode, RemoteSourceFile, } from "../node/node.js";
|
|
26
26
|
import { Wtf8Decoder } from "../node/wtf8.js";
|
|
27
|
-
import {
|
|
27
|
+
import { canonicalize, CaseSensitivity, pathKey, toRootedDirectoryPath, toRootedPath, } from "../path.js";
|
|
28
|
+
import { prepareCompilerOptions } from "../prepareCompilerOptions.generated.js";
|
|
28
29
|
import { resolveFileName, toCreateSnapshotRequest, validateSymbolResponse, } from "../proto.js";
|
|
29
30
|
import { SourceFileCache, } from "../sourceFileCache.js";
|
|
30
31
|
import { Client, } from "./client.js";
|
|
@@ -51,12 +52,14 @@ export { all, defer } from "./generatorSupport.js";
|
|
|
51
52
|
import { sourceFileResponseToUint8Array } from "../node/encoder.js";
|
|
52
53
|
import { executeRequestGenerators, } from "./generatorSupport.js";
|
|
53
54
|
export class API {
|
|
55
|
+
/** @internal */
|
|
54
56
|
client;
|
|
57
|
+
/** @internal */
|
|
55
58
|
sourceFileCache;
|
|
56
59
|
toPath;
|
|
57
|
-
currentDirectory;
|
|
58
60
|
decoder = new Wtf8Decoder();
|
|
59
|
-
|
|
61
|
+
currentDirectory;
|
|
62
|
+
caseSensitivity;
|
|
60
63
|
initialized = false;
|
|
61
64
|
initializing;
|
|
62
65
|
activeSnapshots = new Map();
|
|
@@ -70,6 +73,69 @@ export class API {
|
|
|
70
73
|
this.printer = new Printer(this.client);
|
|
71
74
|
this.internal = new InternalAPI(this.client, this.ensureInitialized);
|
|
72
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Looks up a remote declaration's binder symbol. Throws for synthesized or configuration ASTs.
|
|
78
|
+
*/
|
|
79
|
+
get getSymbol() {
|
|
80
|
+
const owner = this;
|
|
81
|
+
return cacheGeneratorMethod(owner, "getSymbol", function (declaration) {
|
|
82
|
+
const file = getRemoteSourceFile(declaration);
|
|
83
|
+
if (!file)
|
|
84
|
+
throw new Error(`Source file not found for declaration`);
|
|
85
|
+
const record = file.symbolCache;
|
|
86
|
+
if (!record)
|
|
87
|
+
throw new Error(`Cached source file not found for declaration`);
|
|
88
|
+
const index = parseNodeHandleFromCompiler(getNodeId(declaration)).index;
|
|
89
|
+
const cached = record.symbolsByDeclarationNodeIndex.get(index);
|
|
90
|
+
if (cached)
|
|
91
|
+
return cached;
|
|
92
|
+
return owner.fetchDeclarationSymbol(record, index);
|
|
93
|
+
}, function* (declaration) {
|
|
94
|
+
const file = getRemoteSourceFile(declaration);
|
|
95
|
+
if (!file)
|
|
96
|
+
throw new Error(`Source file not found for declaration`);
|
|
97
|
+
const record = file.symbolCache;
|
|
98
|
+
if (!record)
|
|
99
|
+
throw new Error(`Cached source file not found for declaration`);
|
|
100
|
+
const index = parseNodeHandleFromCompiler(getNodeId(declaration)).index;
|
|
101
|
+
const cached = record.symbolsByDeclarationNodeIndex.get(index);
|
|
102
|
+
if (cached)
|
|
103
|
+
return cached;
|
|
104
|
+
return yield* owner.fetchDeclarationSymbol.gen(record, index);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
get fetchDeclarationSymbol() {
|
|
108
|
+
const owner = this;
|
|
109
|
+
return cacheGeneratorMethod(owner, "fetchDeclarationSymbol", function (record, index) {
|
|
110
|
+
const data = owner.client.apiRequest("getSymbolOfDeclaration", {
|
|
111
|
+
file: record.descriptor,
|
|
112
|
+
index,
|
|
113
|
+
});
|
|
114
|
+
validateSymbolResponse(data);
|
|
115
|
+
const reference = data.reference;
|
|
116
|
+
if (reference.kind !== SymbolOwnerKind.File) {
|
|
117
|
+
throw new Error(`Symbol ${reference.id} is not file-owned`);
|
|
118
|
+
}
|
|
119
|
+
const fileOwner = { record, api: owner };
|
|
120
|
+
const symbol = owner.sourceFileCache.getOrCreateSymbol(record, reference.file, reference.id, () => new Symbol(data, { kind: SymbolOwnerKind.File, owner: fileOwner }));
|
|
121
|
+
record.symbolsByDeclarationNodeIndex.set(index, symbol);
|
|
122
|
+
return symbol;
|
|
123
|
+
}, function* (record, index) {
|
|
124
|
+
const data = yield* apiRequest("getSymbolOfDeclaration", {
|
|
125
|
+
file: record.descriptor,
|
|
126
|
+
index,
|
|
127
|
+
});
|
|
128
|
+
validateSymbolResponse(data);
|
|
129
|
+
const reference = data.reference;
|
|
130
|
+
if (reference.kind !== SymbolOwnerKind.File) {
|
|
131
|
+
throw new Error(`Symbol ${reference.id} is not file-owned`);
|
|
132
|
+
}
|
|
133
|
+
const fileOwner = { record, api: owner };
|
|
134
|
+
const symbol = owner.sourceFileCache.getOrCreateSymbol(record, reference.file, reference.id, () => new Symbol(data, { kind: SymbolOwnerKind.File, owner: fileOwner }));
|
|
135
|
+
record.symbolsByDeclarationNodeIndex.set(index, symbol);
|
|
136
|
+
return symbol;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
73
139
|
/**
|
|
74
140
|
* Create an API instance from an existing LSP connection's API session.
|
|
75
141
|
* Use this when connecting to an API pipe provided by an LSP server via custom/initializeAPISession.
|
|
@@ -106,11 +172,9 @@ export class API {
|
|
|
106
172
|
return cacheGeneratorMethod(owner, "initializeWorker", function () {
|
|
107
173
|
try {
|
|
108
174
|
const response = owner.client.apiRequest("initialize", null);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
owner.
|
|
112
|
-
owner.currentDirectory = currentDirectory;
|
|
113
|
-
owner.toPath = (fileName) => toPath(fileName, currentDirectory, getCanonicalFileName);
|
|
175
|
+
owner.currentDirectory = response.currentDirectory;
|
|
176
|
+
owner.caseSensitivity = response.caseSensitivity;
|
|
177
|
+
owner.toPath = (fileName, basePath = response.currentDirectory) => pathKey(toRootedPath(fileName, toRootedDirectoryPath(basePath, response.currentDirectory)), response.caseSensitivity);
|
|
114
178
|
owner.initialized = true;
|
|
115
179
|
}
|
|
116
180
|
catch (error) {
|
|
@@ -120,11 +184,9 @@ export class API {
|
|
|
120
184
|
}, function* () {
|
|
121
185
|
try {
|
|
122
186
|
const response = yield* apiRequest("initialize", null);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
owner.
|
|
126
|
-
owner.currentDirectory = currentDirectory;
|
|
127
|
-
owner.toPath = (fileName) => toPath(fileName, currentDirectory, getCanonicalFileName);
|
|
187
|
+
owner.currentDirectory = response.currentDirectory;
|
|
188
|
+
owner.caseSensitivity = response.caseSensitivity;
|
|
189
|
+
owner.toPath = (fileName, basePath = response.currentDirectory) => pathKey(toRootedPath(fileName, toRootedDirectoryPath(basePath, response.currentDirectory)), response.caseSensitivity);
|
|
128
190
|
owner.initialized = true;
|
|
129
191
|
}
|
|
130
192
|
catch (error) {
|
|
@@ -140,10 +202,13 @@ export class API {
|
|
|
140
202
|
return this.currentDirectory;
|
|
141
203
|
}
|
|
142
204
|
getCanonicalFileName(fileName) {
|
|
143
|
-
|
|
205
|
+
return canonicalize(fileName, this.getCaseSensitivity());
|
|
206
|
+
}
|
|
207
|
+
getCaseSensitivity() {
|
|
208
|
+
if (this.caseSensitivity === undefined) {
|
|
144
209
|
throw new Error("API has not been initialized");
|
|
145
210
|
}
|
|
146
|
-
return this.
|
|
211
|
+
return this.caseSensitivity;
|
|
147
212
|
}
|
|
148
213
|
getNewLine() {
|
|
149
214
|
return "\n";
|
|
@@ -155,6 +220,9 @@ export class API {
|
|
|
155
220
|
const orchestratorResponse = owner.client.apiRequest("createBuildOrchestrator", {
|
|
156
221
|
...buildOrchestratorOptions,
|
|
157
222
|
...buildOrchestratorOptions.overrideCompilerOptions,
|
|
223
|
+
cwd: buildOrchestratorOptions.cwd === undefined
|
|
224
|
+
? undefined
|
|
225
|
+
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, owner.getCurrentDirectory()),
|
|
158
226
|
rootNames,
|
|
159
227
|
});
|
|
160
228
|
const orchestrator = new BuildOrchestrator(owner.client, orchestratorResponse, () => {
|
|
@@ -167,6 +235,9 @@ export class API {
|
|
|
167
235
|
const orchestratorResponse = yield* apiRequest("createBuildOrchestrator", {
|
|
168
236
|
...buildOrchestratorOptions,
|
|
169
237
|
...buildOrchestratorOptions.overrideCompilerOptions,
|
|
238
|
+
cwd: buildOrchestratorOptions.cwd === undefined
|
|
239
|
+
? undefined
|
|
240
|
+
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, owner.getCurrentDirectory()),
|
|
170
241
|
rootNames,
|
|
171
242
|
});
|
|
172
243
|
const orchestrator = new BuildOrchestrator(owner.client, orchestratorResponse, () => {
|
|
@@ -293,7 +364,7 @@ export class API {
|
|
|
293
364
|
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
294
365
|
const lease = readSourceFileLease(view);
|
|
295
366
|
try {
|
|
296
|
-
const decoded = new RemoteSourceFile(data, this.decoder, this.client.getTimingCollector());
|
|
367
|
+
const decoded = new RemoteSourceFile(data, this.decoder, this.client.getTimingCollector(), this);
|
|
297
368
|
return this.addSourceFileLease(decoded, lease);
|
|
298
369
|
}
|
|
299
370
|
catch (error) {
|
|
@@ -306,7 +377,7 @@ export class API {
|
|
|
306
377
|
}
|
|
307
378
|
addSourceFileLease(sourceFile, lease) {
|
|
308
379
|
const cached = this.sourceFileCache.setForLease(sourceFile, lease);
|
|
309
|
-
const retained = new RetainedSourceFile(cached, lease,
|
|
380
|
+
const retained = new RetainedSourceFile(cached, lease, () => {
|
|
310
381
|
this.activeSourceFileLeases.delete(lease);
|
|
311
382
|
this.sourceFileCache.releaseLease(lease);
|
|
312
383
|
});
|
|
@@ -359,7 +430,7 @@ export class API {
|
|
|
359
430
|
owner.ensureInitialized();
|
|
360
431
|
const requestParams = toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params));
|
|
361
432
|
const data = owner.client.apiRequest("createSnapshot", requestParams);
|
|
362
|
-
const snapshot = new Snapshot(data, owner.
|
|
433
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
363
434
|
owner.activeSnapshots.delete(snapshot.id);
|
|
364
435
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
365
436
|
}, owner.createSnapshotUpdater(() => snapshot), undefined);
|
|
@@ -370,7 +441,7 @@ export class API {
|
|
|
370
441
|
yield* owner.ensureInitialized.gen();
|
|
371
442
|
const requestParams = toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params));
|
|
372
443
|
const data = yield* apiRequest("createSnapshot", requestParams);
|
|
373
|
-
const snapshot = new Snapshot(data, owner.
|
|
444
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
374
445
|
owner.activeSnapshots.delete(snapshot.id);
|
|
375
446
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
376
447
|
}, owner.createSnapshotUpdater(() => snapshot), undefined);
|
|
@@ -395,7 +466,7 @@ export class API {
|
|
|
395
466
|
return baseSnapshot;
|
|
396
467
|
}
|
|
397
468
|
owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
398
|
-
const snapshot = new Snapshot(data, owner.
|
|
469
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
399
470
|
owner.activeSnapshots.delete(snapshot.id);
|
|
400
471
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
401
472
|
}, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
@@ -415,7 +486,7 @@ export class API {
|
|
|
415
486
|
return baseSnapshot;
|
|
416
487
|
}
|
|
417
488
|
owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
418
|
-
const snapshot = new Snapshot(data, owner.
|
|
489
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
419
490
|
owner.activeSnapshots.delete(snapshot.id);
|
|
420
491
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
421
492
|
}, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
@@ -429,11 +500,15 @@ export class API {
|
|
|
429
500
|
const prepareOptions = (options) => {
|
|
430
501
|
if (!options)
|
|
431
502
|
return undefined;
|
|
432
|
-
const { moduleResolver, ...rest } = options;
|
|
503
|
+
const { moduleResolver, projectReferences, ...rest } = options;
|
|
433
504
|
moduleResolver?.ensureNotDisposed();
|
|
434
505
|
return {
|
|
435
506
|
...rest,
|
|
436
507
|
moduleResolver: moduleResolver?.id,
|
|
508
|
+
projectReferences: projectReferences?.map(reference => ({
|
|
509
|
+
...reference,
|
|
510
|
+
path: toRootedPath(reference.path, this.getCurrentDirectory()),
|
|
511
|
+
})),
|
|
437
512
|
};
|
|
438
513
|
};
|
|
439
514
|
return {
|
|
@@ -476,7 +551,7 @@ export class API {
|
|
|
476
551
|
if (baseSnapshot) {
|
|
477
552
|
owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
478
553
|
}
|
|
479
|
-
const snapshot = new Snapshot(data, owner.
|
|
554
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
480
555
|
owner.activeSnapshots.delete(snapshot.id);
|
|
481
556
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
482
557
|
}, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
@@ -497,7 +572,7 @@ export class API {
|
|
|
497
572
|
if (baseSnapshot) {
|
|
498
573
|
owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
499
574
|
}
|
|
500
|
-
const snapshot = new Snapshot(data, owner.
|
|
575
|
+
const snapshot = new Snapshot(data, owner.toPath, owner, () => {
|
|
501
576
|
owner.activeSnapshots.delete(snapshot.id);
|
|
502
577
|
owner.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
503
578
|
}, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
@@ -562,7 +637,7 @@ export class API {
|
|
|
562
637
|
: undefined;
|
|
563
638
|
try {
|
|
564
639
|
const id = owner.client.apiRequest("createModuleResolver", {
|
|
565
|
-
compilerOptions,
|
|
640
|
+
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
|
|
566
641
|
moduleResolutions: options?.moduleResolutions,
|
|
567
642
|
resolveModuleNameCallback: callback?.name,
|
|
568
643
|
});
|
|
@@ -579,7 +654,7 @@ export class API {
|
|
|
579
654
|
: undefined;
|
|
580
655
|
try {
|
|
581
656
|
const id = yield* apiRequest("createModuleResolver", {
|
|
582
|
-
compilerOptions,
|
|
657
|
+
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
|
|
583
658
|
moduleResolutions: options?.moduleResolutions,
|
|
584
659
|
resolveModuleNameCallback: callback?.name,
|
|
585
660
|
});
|
|
@@ -702,18 +777,43 @@ function sourceFileDescriptor(sourceFile) {
|
|
|
702
777
|
nodeId: sourceFile.nodeId,
|
|
703
778
|
};
|
|
704
779
|
}
|
|
780
|
+
function getRemoteSourceFile(node) {
|
|
781
|
+
if (!(node instanceof RemoteNode))
|
|
782
|
+
return undefined;
|
|
783
|
+
const file = node.getSourceFile();
|
|
784
|
+
return file instanceof RemoteSourceFile && file.api ? file : undefined;
|
|
785
|
+
}
|
|
786
|
+
function getNodeAPI(node) {
|
|
787
|
+
const api = getRemoteSourceFile(node)?.api;
|
|
788
|
+
if (!api)
|
|
789
|
+
return undefined;
|
|
790
|
+
if (!(api instanceof API))
|
|
791
|
+
throw new Error("Source file does not belong to the sync API");
|
|
792
|
+
return api;
|
|
793
|
+
}
|
|
794
|
+
/** Looks up a remote declaration's binder symbol through its API. Throws for non-remote declarations. */
|
|
795
|
+
export function getSymbol(declaration) {
|
|
796
|
+
const api = getNodeAPI(declaration);
|
|
797
|
+
if (!api)
|
|
798
|
+
throw new Error("Source file not found for declaration");
|
|
799
|
+
return api.getSymbol(declaration);
|
|
800
|
+
}
|
|
801
|
+
getSymbol.gen = function* (declaration) {
|
|
802
|
+
const api = getNodeAPI(declaration);
|
|
803
|
+
if (!api)
|
|
804
|
+
throw new Error("Source file not found for declaration");
|
|
805
|
+
return yield* api.getSymbol.gen(declaration);
|
|
806
|
+
};
|
|
705
807
|
/** An independently retained source file and its disposable remote-lifetime lease. */
|
|
706
808
|
export class RetainedSourceFile {
|
|
707
809
|
sourceFile;
|
|
708
810
|
lease;
|
|
709
|
-
client;
|
|
710
811
|
onDispose;
|
|
711
812
|
disposed = false;
|
|
712
813
|
disposePromise;
|
|
713
|
-
constructor(sourceFile, lease,
|
|
814
|
+
constructor(sourceFile, lease, onDispose) {
|
|
714
815
|
this.sourceFile = sourceFile;
|
|
715
816
|
this.lease = lease;
|
|
716
|
-
this.client = client;
|
|
717
817
|
this.onDispose = onDispose;
|
|
718
818
|
}
|
|
719
819
|
[globalThis.Symbol.dispose]() {
|
|
@@ -732,9 +832,12 @@ export class RetainedSourceFile {
|
|
|
732
832
|
return cacheGeneratorMethod(owner, "disposeWorker", function () {
|
|
733
833
|
if (owner.disposed)
|
|
734
834
|
return;
|
|
835
|
+
const api = getNodeAPI(owner.sourceFile);
|
|
836
|
+
if (!api)
|
|
837
|
+
throw new Error("Retained source file has no owning API");
|
|
735
838
|
owner.disposed = true;
|
|
736
839
|
try {
|
|
737
|
-
|
|
840
|
+
api.client.apiRequest("releaseSourceFile", { lease: owner.lease });
|
|
738
841
|
}
|
|
739
842
|
finally {
|
|
740
843
|
owner.onDispose();
|
|
@@ -742,6 +845,9 @@ export class RetainedSourceFile {
|
|
|
742
845
|
}, function* () {
|
|
743
846
|
if (owner.disposed)
|
|
744
847
|
return;
|
|
848
|
+
const api = getNodeAPI(owner.sourceFile);
|
|
849
|
+
if (!api)
|
|
850
|
+
throw new Error("Retained source file has no owning API");
|
|
745
851
|
owner.disposed = true;
|
|
746
852
|
try {
|
|
747
853
|
yield* apiRequest("releaseSourceFile", { lease: owner.lease });
|
|
@@ -800,7 +906,7 @@ export class Snapshot {
|
|
|
800
906
|
operation;
|
|
801
907
|
projectMap;
|
|
802
908
|
toPath;
|
|
803
|
-
|
|
909
|
+
api;
|
|
804
910
|
disposed = false;
|
|
805
911
|
disposePromise;
|
|
806
912
|
onDispose;
|
|
@@ -808,9 +914,12 @@ export class Snapshot {
|
|
|
808
914
|
projectDataMap;
|
|
809
915
|
updateSnapshot;
|
|
810
916
|
internal;
|
|
811
|
-
|
|
917
|
+
get client() {
|
|
918
|
+
return this.api.client;
|
|
919
|
+
}
|
|
920
|
+
constructor(data, toPath, api, onDispose, updateSnapshot, baseSnapshot) {
|
|
812
921
|
this.id = data.snapshot;
|
|
813
|
-
this.
|
|
922
|
+
this.api = api;
|
|
814
923
|
this.toPath = toPath;
|
|
815
924
|
this.onDispose = onDispose;
|
|
816
925
|
this.updateSnapshot = updateSnapshot;
|
|
@@ -825,14 +934,14 @@ export class Snapshot {
|
|
|
825
934
|
this.projectDataMap = new Map([...projectDataMap].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
826
935
|
this.snapshotRegistry = new SnapshotObjectRegistry(this.id);
|
|
827
936
|
for (const projData of this.projectDataMap.values()) {
|
|
828
|
-
const project = new Project(projData, this.id,
|
|
937
|
+
const project = new Project(projData, this.id, toPath, api, this.snapshotRegistry);
|
|
829
938
|
this.projectMap.set(projData.id, project);
|
|
830
939
|
}
|
|
831
940
|
this.operation = {
|
|
832
941
|
createdPrograms: data.operation.createdPrograms?.map(projectId => this.requireProject(projectId).program),
|
|
833
942
|
openedFiles: data.operation.openedFiles?.map(result => ({ project: this.requireProject(result.project) })),
|
|
834
943
|
};
|
|
835
|
-
this.internal = new SnapshotInternalAPI(this.id, client);
|
|
944
|
+
this.internal = new SnapshotInternalAPI(this.id, api.client);
|
|
836
945
|
}
|
|
837
946
|
getProjects() {
|
|
838
947
|
this.ensureNotDisposed();
|
|
@@ -840,7 +949,8 @@ export class Snapshot {
|
|
|
840
949
|
}
|
|
841
950
|
getConfiguredProject(configFileName) {
|
|
842
951
|
this.ensureNotDisposed();
|
|
843
|
-
|
|
952
|
+
const id = this.toPath(configFileName);
|
|
953
|
+
return this.projectMap.get(id);
|
|
844
954
|
}
|
|
845
955
|
getProject(projectId) {
|
|
846
956
|
this.ensureNotDisposed();
|
|
@@ -1050,20 +1160,22 @@ class SnapshotObjectRegistry {
|
|
|
1050
1160
|
}
|
|
1051
1161
|
}
|
|
1052
1162
|
class ProjectObjectRegistry {
|
|
1053
|
-
client;
|
|
1054
1163
|
snapshotId;
|
|
1055
1164
|
project;
|
|
1056
1165
|
snapshotRegistry;
|
|
1057
|
-
sourceFileCache;
|
|
1058
1166
|
types = new Map();
|
|
1059
1167
|
signatures = new Map();
|
|
1060
1168
|
disposed = false;
|
|
1061
|
-
|
|
1062
|
-
this.client
|
|
1169
|
+
get client() {
|
|
1170
|
+
return this.project.api.client;
|
|
1171
|
+
}
|
|
1172
|
+
get sourceFileCache() {
|
|
1173
|
+
return this.project.api.sourceFileCache;
|
|
1174
|
+
}
|
|
1175
|
+
constructor(snapshotId, project, snapshotRegistry) {
|
|
1063
1176
|
this.snapshotId = snapshotId;
|
|
1064
1177
|
this.project = project;
|
|
1065
1178
|
this.snapshotRegistry = snapshotRegistry;
|
|
1066
|
-
this.sourceFileCache = sourceFileCache;
|
|
1067
1179
|
snapshotRegistry.addProjectRegistry(this);
|
|
1068
1180
|
}
|
|
1069
1181
|
getOrCreateSymbol(data) {
|
|
@@ -1076,7 +1188,7 @@ class ProjectObjectRegistry {
|
|
|
1076
1188
|
const record = this.sourceFileCache.getOrCreateRecord(reference.file, this.snapshotId, this.project.id);
|
|
1077
1189
|
return this.sourceFileCache.getOrCreateSymbol(record, reference.file, reference.id, () => new Symbol(data, {
|
|
1078
1190
|
kind: SymbolOwnerKind.File,
|
|
1079
|
-
owner: { record,
|
|
1191
|
+
owner: { record, api: this.project.api },
|
|
1080
1192
|
}));
|
|
1081
1193
|
}
|
|
1082
1194
|
/** Find an already-interned symbol and retain its file record for this registry. */
|
|
@@ -1086,7 +1198,7 @@ class ProjectObjectRegistry {
|
|
|
1086
1198
|
return this.snapshotRegistry.getSymbol(reference.id);
|
|
1087
1199
|
}
|
|
1088
1200
|
const record = this.sourceFileCache.findRecord(reference.file);
|
|
1089
|
-
const symbol = record?.
|
|
1201
|
+
const symbol = record?.symbolsById.get(reference.id);
|
|
1090
1202
|
if (record && symbol) {
|
|
1091
1203
|
this.sourceFileCache.retainRecord(record, this.snapshotId, this.project.id);
|
|
1092
1204
|
}
|
|
@@ -1502,6 +1614,8 @@ class ProjectObjectRegistry {
|
|
|
1502
1614
|
}
|
|
1503
1615
|
}
|
|
1504
1616
|
export class Project {
|
|
1617
|
+
/** @internal */
|
|
1618
|
+
api;
|
|
1505
1619
|
id;
|
|
1506
1620
|
configFileName;
|
|
1507
1621
|
currentDirectory;
|
|
@@ -1514,10 +1628,10 @@ export class Project {
|
|
|
1514
1628
|
program;
|
|
1515
1629
|
checker;
|
|
1516
1630
|
languageService;
|
|
1517
|
-
client;
|
|
1518
1631
|
snapshotId;
|
|
1519
|
-
constructor(data, snapshotId,
|
|
1632
|
+
constructor(data, snapshotId, toPath, api, snapshotRegistry) {
|
|
1520
1633
|
this.id = data.id;
|
|
1634
|
+
this.api = api;
|
|
1521
1635
|
this.configFileName = data.configFileName;
|
|
1522
1636
|
this.currentDirectory = data.currentDirectory;
|
|
1523
1637
|
this.dirty = data.dirty;
|
|
@@ -1527,12 +1641,11 @@ export class Project {
|
|
|
1527
1641
|
this.parsedCommandLine = data.parsedCommandLine;
|
|
1528
1642
|
this.compilerOptions = this.parsedCommandLine.options;
|
|
1529
1643
|
this.rootFiles = this.parsedCommandLine.fileNames;
|
|
1530
|
-
this.client = client;
|
|
1531
1644
|
this.snapshotId = snapshotId;
|
|
1532
|
-
this.program = new Program(snapshotId, this,
|
|
1533
|
-
const objectRegistry = new ProjectObjectRegistry(
|
|
1534
|
-
this.checker = new Checker(snapshotId, this,
|
|
1535
|
-
this.languageService = new LanguageService(snapshotId, this,
|
|
1645
|
+
this.program = new Program(snapshotId, this, toPath);
|
|
1646
|
+
const objectRegistry = new ProjectObjectRegistry(snapshotId, this, snapshotRegistry);
|
|
1647
|
+
this.checker = new Checker(snapshotId, this, objectRegistry);
|
|
1648
|
+
this.languageService = new LanguageService(snapshotId, this, objectRegistry);
|
|
1536
1649
|
}
|
|
1537
1650
|
/** @deprecated Use `languageService.getImportAdderEdits`. */
|
|
1538
1651
|
get getImportAdderEdits() {
|
|
@@ -1559,12 +1672,13 @@ export class Project {
|
|
|
1559
1672
|
export class LanguageService {
|
|
1560
1673
|
snapshotId;
|
|
1561
1674
|
project;
|
|
1562
|
-
client;
|
|
1563
1675
|
objectRegistry;
|
|
1564
|
-
|
|
1676
|
+
get client() {
|
|
1677
|
+
return this.project.api.client;
|
|
1678
|
+
}
|
|
1679
|
+
constructor(snapshotId, project, objectRegistry) {
|
|
1565
1680
|
this.snapshotId = snapshotId;
|
|
1566
1681
|
this.project = project;
|
|
1567
|
-
this.client = client;
|
|
1568
1682
|
this.objectRegistry = objectRegistry;
|
|
1569
1683
|
}
|
|
1570
1684
|
get getImportAdderEdits() {
|
|
@@ -1747,28 +1861,28 @@ export class Program {
|
|
|
1747
1861
|
snapshotId;
|
|
1748
1862
|
id;
|
|
1749
1863
|
project;
|
|
1750
|
-
client;
|
|
1751
|
-
sourceFileCache;
|
|
1752
1864
|
toPath;
|
|
1753
|
-
formatDiagnosticsHost;
|
|
1754
1865
|
decoder = new Wtf8Decoder();
|
|
1755
1866
|
sourceFileMetadataCache = new Map();
|
|
1756
1867
|
ownedSnapshot;
|
|
1757
1868
|
disposePromise;
|
|
1758
|
-
|
|
1869
|
+
get client() {
|
|
1870
|
+
return this.project.api.client;
|
|
1871
|
+
}
|
|
1872
|
+
get sourceFileCache() {
|
|
1873
|
+
return this.project.api.sourceFileCache;
|
|
1874
|
+
}
|
|
1875
|
+
constructor(snapshotId, project, toPath) {
|
|
1759
1876
|
this.snapshotId = snapshotId;
|
|
1760
1877
|
this.id = project.id;
|
|
1761
1878
|
this.project = project;
|
|
1762
|
-
this.client = client;
|
|
1763
|
-
this.sourceFileCache = sourceFileCache;
|
|
1764
1879
|
this.toPath = toPath;
|
|
1765
|
-
this.formatDiagnosticsHost = formatDiagnosticsHost;
|
|
1766
1880
|
}
|
|
1767
1881
|
getCurrentDirectory() {
|
|
1768
1882
|
return this.project.currentDirectory;
|
|
1769
1883
|
}
|
|
1770
1884
|
getCanonicalFileName(fileName) {
|
|
1771
|
-
return this.
|
|
1885
|
+
return this.project.api.getCanonicalFileName(fileName);
|
|
1772
1886
|
}
|
|
1773
1887
|
getNewLine() {
|
|
1774
1888
|
return this.project.compilerOptions.newLine === NewLineKind.CRLF ? "\r\n" : "\n";
|
|
@@ -1809,7 +1923,34 @@ export class Program {
|
|
|
1809
1923
|
const owner = this;
|
|
1810
1924
|
return cacheGeneratorMethod(owner, "getSourceFile", function (file) {
|
|
1811
1925
|
const fileName = resolveFileName(file);
|
|
1812
|
-
const path = owner.
|
|
1926
|
+
const path = owner.pathKeyForFileName(fileName);
|
|
1927
|
+
return owner.getSourceFileWorker(file, path);
|
|
1928
|
+
}, function* (file) {
|
|
1929
|
+
const fileName = resolveFileName(file);
|
|
1930
|
+
const path = owner.pathKeyForFileName(fileName);
|
|
1931
|
+
return yield* owner.getSourceFileWorker.gen(file, path);
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Returns the source file for an already-canonical path.
|
|
1936
|
+
*
|
|
1937
|
+
* @internal
|
|
1938
|
+
*/
|
|
1939
|
+
get getSourceFileByPath() {
|
|
1940
|
+
const owner = this;
|
|
1941
|
+
return cacheGeneratorMethod(owner, "getSourceFileByPath", function (path) {
|
|
1942
|
+
// The wire format is a string, but the cache key remains the supplied
|
|
1943
|
+
// PathKey and is never treated as a RootedPath.
|
|
1944
|
+
return owner.getSourceFileWorker(path, path);
|
|
1945
|
+
}, function* (path) {
|
|
1946
|
+
// The wire format is a string, but the cache key remains the supplied
|
|
1947
|
+
// PathKey and is never treated as a RootedPath.
|
|
1948
|
+
return yield* owner.getSourceFileWorker.gen(path, path);
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
get getSourceFileWorker() {
|
|
1952
|
+
const owner = this;
|
|
1953
|
+
return cacheGeneratorMethod(owner, "getSourceFileWorker", function (file, path) {
|
|
1813
1954
|
// Check if we already have a retained cache entry for this (snapshot, project) pair
|
|
1814
1955
|
const retained = owner.sourceFileCache.getRetained(path, owner.snapshotId, owner.project.id);
|
|
1815
1956
|
if (retained) {
|
|
@@ -1825,11 +1966,9 @@ export class Program {
|
|
|
1825
1966
|
return undefined;
|
|
1826
1967
|
}
|
|
1827
1968
|
// Create a new RemoteSourceFile and cache it (set returns existing if hash matches)
|
|
1828
|
-
const decoded = new RemoteSourceFile(binaryData, owner.decoder, owner.client.getTimingCollector());
|
|
1969
|
+
const decoded = new RemoteSourceFile(binaryData, owner.decoder, owner.client.getTimingCollector(), owner.project.api);
|
|
1829
1970
|
return owner.sourceFileCache.set(decoded, owner.snapshotId, owner.project.id);
|
|
1830
|
-
}, function* (file) {
|
|
1831
|
-
const fileName = resolveFileName(file);
|
|
1832
|
-
const path = owner.toPath(fileName);
|
|
1971
|
+
}, function* (file, path) {
|
|
1833
1972
|
// Check if we already have a retained cache entry for this (snapshot, project) pair
|
|
1834
1973
|
const retained = owner.sourceFileCache.getRetained(path, owner.snapshotId, owner.project.id);
|
|
1835
1974
|
if (retained) {
|
|
@@ -1845,7 +1984,7 @@ export class Program {
|
|
|
1845
1984
|
return undefined;
|
|
1846
1985
|
}
|
|
1847
1986
|
// Create a new RemoteSourceFile and cache it (set returns existing if hash matches)
|
|
1848
|
-
const decoded = new RemoteSourceFile(binaryData, owner.decoder, owner.client.getTimingCollector());
|
|
1987
|
+
const decoded = new RemoteSourceFile(binaryData, owner.decoder, owner.client.getTimingCollector(), owner.project.api);
|
|
1849
1988
|
return owner.sourceFileCache.set(decoded, owner.snapshotId, owner.project.id);
|
|
1850
1989
|
});
|
|
1851
1990
|
}
|
|
@@ -1995,9 +2134,9 @@ export class Program {
|
|
|
1995
2134
|
get getSourceFileMetadata() {
|
|
1996
2135
|
const owner = this;
|
|
1997
2136
|
return cacheGeneratorMethod(owner, "getSourceFileMetadata", function (file) {
|
|
1998
|
-
return owner.getSourceFileMetadataByPath(owner.
|
|
2137
|
+
return owner.getSourceFileMetadataByPath(owner.pathKeyForFileName(resolveFileName(file)));
|
|
1999
2138
|
}, function* (file) {
|
|
2000
|
-
return yield* owner.getSourceFileMetadataByPath.gen(owner.
|
|
2139
|
+
return yield* owner.getSourceFileMetadataByPath.gen(owner.pathKeyForFileName(resolveFileName(file)));
|
|
2001
2140
|
});
|
|
2002
2141
|
}
|
|
2003
2142
|
/**
|
|
@@ -2027,6 +2166,8 @@ export class Program {
|
|
|
2027
2166
|
get fetchSourceFileMetadata() {
|
|
2028
2167
|
const owner = this;
|
|
2029
2168
|
return cacheGeneratorMethod(owner, "fetchSourceFileMetadata", function (path) {
|
|
2169
|
+
// PathKey is serialized as a string; the server deliberately treats all
|
|
2170
|
+
// client-provided path text as untrusted input.
|
|
2030
2171
|
const data = owner.client.apiRequest("getSourceFileMetadata", {
|
|
2031
2172
|
snapshot: owner.snapshotId,
|
|
2032
2173
|
project: owner.project.id,
|
|
@@ -2034,6 +2175,8 @@ export class Program {
|
|
|
2034
2175
|
});
|
|
2035
2176
|
return data ?? undefined;
|
|
2036
2177
|
}, function* (path) {
|
|
2178
|
+
// PathKey is serialized as a string; the server deliberately treats all
|
|
2179
|
+
// client-provided path text as untrusted input.
|
|
2037
2180
|
const data = yield* apiRequest("getSourceFileMetadata", {
|
|
2038
2181
|
snapshot: owner.snapshotId,
|
|
2039
2182
|
project: owner.project.id,
|
|
@@ -2042,6 +2185,9 @@ export class Program {
|
|
|
2042
2185
|
return data ?? undefined;
|
|
2043
2186
|
});
|
|
2044
2187
|
}
|
|
2188
|
+
pathKeyForFileName(fileName) {
|
|
2189
|
+
return this.toPath(fileName, this.project.currentDirectory);
|
|
2190
|
+
}
|
|
2045
2191
|
/**
|
|
2046
2192
|
* Returns whether the given source file was loaded as part of an external library
|
|
2047
2193
|
* (e.g. a dependency resolved from `node_modules`). The underlying program metadata is
|
|
@@ -2107,7 +2253,7 @@ export class Program {
|
|
|
2107
2253
|
if (!binaryData) {
|
|
2108
2254
|
return undefined;
|
|
2109
2255
|
}
|
|
2110
|
-
return new RemoteSourceFile(binaryData, owner.decoder);
|
|
2256
|
+
return new RemoteSourceFile(binaryData, owner.decoder, undefined, owner.project.api);
|
|
2111
2257
|
}, function* (file) {
|
|
2112
2258
|
const binaryData = sourceFileResponseToUint8Array(yield* apiRequest("getConfigSourceFile", {
|
|
2113
2259
|
snapshot: owner.snapshotId,
|
|
@@ -2117,7 +2263,7 @@ export class Program {
|
|
|
2117
2263
|
if (!binaryData) {
|
|
2118
2264
|
return undefined;
|
|
2119
2265
|
}
|
|
2120
|
-
return new RemoteSourceFile(binaryData, owner.decoder);
|
|
2266
|
+
return new RemoteSourceFile(binaryData, owner.decoder, undefined, owner.project.api);
|
|
2121
2267
|
});
|
|
2122
2268
|
}
|
|
2123
2269
|
/**
|
|
@@ -2574,19 +2720,101 @@ function toEmitOutput(response) {
|
|
|
2574
2720
|
export class Checker {
|
|
2575
2721
|
snapshotId;
|
|
2576
2722
|
project;
|
|
2577
|
-
client;
|
|
2578
2723
|
objectRegistry;
|
|
2579
2724
|
wellKnownSymbols;
|
|
2580
2725
|
wellKnownSignatures;
|
|
2581
|
-
|
|
2726
|
+
get client() {
|
|
2727
|
+
return this.project.api.client;
|
|
2728
|
+
}
|
|
2729
|
+
constructor(snapshotId, project, objectRegistry) {
|
|
2582
2730
|
this.snapshotId = snapshotId;
|
|
2583
2731
|
this.project = project;
|
|
2584
|
-
this.client = client;
|
|
2585
2732
|
this.objectRegistry = objectRegistry;
|
|
2586
2733
|
}
|
|
2587
2734
|
dispose() {
|
|
2588
2735
|
this.objectRegistry.clear();
|
|
2589
2736
|
}
|
|
2737
|
+
/** Get the merged symbol, or the original symbol if it has not been merged. */
|
|
2738
|
+
get getMergedSymbol() {
|
|
2739
|
+
const owner = this;
|
|
2740
|
+
return cacheGeneratorMethod(owner, "getMergedSymbol", function (symbol) {
|
|
2741
|
+
const data = owner.client.apiRequest("getMergedSymbol", {
|
|
2742
|
+
snapshot: owner.snapshotId,
|
|
2743
|
+
project: owner.project.id,
|
|
2744
|
+
symbol: symbol.reference,
|
|
2745
|
+
});
|
|
2746
|
+
return owner.objectRegistry.getOrCreateSymbol(data);
|
|
2747
|
+
}, function* (symbol) {
|
|
2748
|
+
const data = yield* apiRequest("getMergedSymbol", {
|
|
2749
|
+
snapshot: owner.snapshotId,
|
|
2750
|
+
project: owner.project.id,
|
|
2751
|
+
symbol: symbol.reference,
|
|
2752
|
+
});
|
|
2753
|
+
return owner.objectRegistry.getOrCreateSymbol(data);
|
|
2754
|
+
});
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Get a node's merged symbol. For a declaration, prefer
|
|
2758
|
+
* {@link Checker.getSymbolOfDeclaration} for a non-nullable result.
|
|
2759
|
+
*/
|
|
2760
|
+
get getSymbolOfNode() {
|
|
2761
|
+
const owner = this;
|
|
2762
|
+
return cacheGeneratorMethod(owner, "getSymbolOfNode", function (node) {
|
|
2763
|
+
const data = owner.client.apiRequest("getSymbolOfNode", {
|
|
2764
|
+
snapshot: owner.snapshotId,
|
|
2765
|
+
project: owner.project.id,
|
|
2766
|
+
location: getNodeId(node),
|
|
2767
|
+
});
|
|
2768
|
+
return data ? owner.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2769
|
+
}, function* (node) {
|
|
2770
|
+
const data = yield* apiRequest("getSymbolOfNode", {
|
|
2771
|
+
snapshot: owner.snapshotId,
|
|
2772
|
+
project: owner.project.id,
|
|
2773
|
+
location: getNodeId(node),
|
|
2774
|
+
});
|
|
2775
|
+
return data ? owner.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
/** Get a declaration's merged symbol. */
|
|
2779
|
+
get getSymbolOfDeclaration() {
|
|
2780
|
+
const owner = this;
|
|
2781
|
+
return cacheGeneratorMethod(owner, "getSymbolOfDeclaration", function (node) {
|
|
2782
|
+
const data = owner.client.apiRequest("getSymbolOfDeclarationForChecker", {
|
|
2783
|
+
snapshot: owner.snapshotId,
|
|
2784
|
+
project: owner.project.id,
|
|
2785
|
+
location: getNodeId(node),
|
|
2786
|
+
});
|
|
2787
|
+
// Declarations normally have symbols, but preserve unexpected null results at runtime.
|
|
2788
|
+
return (data && owner.objectRegistry.getOrCreateSymbol(data));
|
|
2789
|
+
}, function* (node) {
|
|
2790
|
+
const data = yield* apiRequest("getSymbolOfDeclarationForChecker", {
|
|
2791
|
+
snapshot: owner.snapshotId,
|
|
2792
|
+
project: owner.project.id,
|
|
2793
|
+
location: getNodeId(node),
|
|
2794
|
+
});
|
|
2795
|
+
// Declarations normally have symbols, but preserve unexpected null results at runtime.
|
|
2796
|
+
return (data && owner.objectRegistry.getOrCreateSymbol(data));
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
/** Get a symbol's merged parent, if any. */
|
|
2800
|
+
get getParentOfSymbol() {
|
|
2801
|
+
const owner = this;
|
|
2802
|
+
return cacheGeneratorMethod(owner, "getParentOfSymbol", function (symbol) {
|
|
2803
|
+
const data = owner.client.apiRequest("getParentOfSymbolForChecker", {
|
|
2804
|
+
snapshot: owner.snapshotId,
|
|
2805
|
+
project: owner.project.id,
|
|
2806
|
+
symbol: symbol.reference,
|
|
2807
|
+
});
|
|
2808
|
+
return data ? owner.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2809
|
+
}, function* (symbol) {
|
|
2810
|
+
const data = yield* apiRequest("getParentOfSymbolForChecker", {
|
|
2811
|
+
snapshot: owner.snapshotId,
|
|
2812
|
+
project: owner.project.id,
|
|
2813
|
+
symbol: symbol.reference,
|
|
2814
|
+
});
|
|
2815
|
+
return data ? owner.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2590
2818
|
get getSymbolAtLocation() {
|
|
2591
2819
|
const owner = this;
|
|
2592
2820
|
function getSymbolAtLocation(nodeOrNodes) {
|
|
@@ -4223,7 +4451,7 @@ export class NodeHandle {
|
|
|
4223
4451
|
kind;
|
|
4224
4452
|
path;
|
|
4225
4453
|
constructor(handle, canonicalProject, fileOwner) {
|
|
4226
|
-
const parsed =
|
|
4454
|
+
const parsed = parseNodeHandleFromCompiler(handle);
|
|
4227
4455
|
this.index = parsed.index;
|
|
4228
4456
|
this.kind = parsed.kind;
|
|
4229
4457
|
this.path = parsed.path;
|
|
@@ -4245,7 +4473,7 @@ export class NodeHandle {
|
|
|
4245
4473
|
}
|
|
4246
4474
|
if (!project)
|
|
4247
4475
|
throw new Error(`Node handle for '${owner.path}' has no project context`);
|
|
4248
|
-
const sourceFile = project.program.
|
|
4476
|
+
const sourceFile = project.program.getSourceFileByPath(owner.path);
|
|
4249
4477
|
if (!sourceFile) {
|
|
4250
4478
|
return undefined;
|
|
4251
4479
|
}
|
|
@@ -4257,7 +4485,7 @@ export class NodeHandle {
|
|
|
4257
4485
|
}
|
|
4258
4486
|
if (!project)
|
|
4259
4487
|
throw new Error(`Node handle for '${owner.path}' has no project context`);
|
|
4260
|
-
const sourceFile = yield* project.program.
|
|
4488
|
+
const sourceFile = yield* project.program.getSourceFileByPath.gen(owner.path);
|
|
4261
4489
|
if (!sourceFile) {
|
|
4262
4490
|
return undefined;
|
|
4263
4491
|
}
|
|
@@ -4267,15 +4495,15 @@ export class NodeHandle {
|
|
|
4267
4495
|
get fetchOwnerFile() {
|
|
4268
4496
|
const owner = this;
|
|
4269
4497
|
return cacheGeneratorMethod(owner, "fetchOwnerFile", function (fileOwner) {
|
|
4270
|
-
const data = fileOwner.client.apiRequestBinary("getCachedSourceFile", { file: fileOwner.record.descriptor });
|
|
4498
|
+
const data = fileOwner.api.client.apiRequestBinary("getCachedSourceFile", { file: fileOwner.record.descriptor });
|
|
4271
4499
|
if (!data)
|
|
4272
4500
|
throw new Error(`Source file '${fileOwner.record.descriptor.fileName}' is not available`);
|
|
4273
|
-
return fileOwner.
|
|
4501
|
+
return fileOwner.api.sourceFileCache.attachFile(fileOwner.record, new RemoteSourceFile(data, new Wtf8Decoder(), fileOwner.api.client.getTimingCollector(), fileOwner.api));
|
|
4274
4502
|
}, function* (fileOwner) {
|
|
4275
4503
|
const data = sourceFileResponseToUint8Array(yield* apiRequest("getCachedSourceFile", { file: fileOwner.record.descriptor }));
|
|
4276
4504
|
if (!data)
|
|
4277
4505
|
throw new Error(`Source file '${fileOwner.record.descriptor.fileName}' is not available`);
|
|
4278
|
-
return fileOwner.
|
|
4506
|
+
return fileOwner.api.sourceFileCache.attachFile(fileOwner.record, new RemoteSourceFile(data, new Wtf8Decoder(), fileOwner.api.client.getTimingCollector(), fileOwner.api));
|
|
4279
4507
|
});
|
|
4280
4508
|
}
|
|
4281
4509
|
}
|
|
@@ -4409,10 +4637,10 @@ export class Symbol {
|
|
|
4409
4637
|
}
|
|
4410
4638
|
const fileOwner = owner.storage.owner;
|
|
4411
4639
|
// A file-owned symbol's relationships are always owned by the same file.
|
|
4412
|
-
const cached = reference.file === fileOwner.record.descriptor.nodeId ? fileOwner.record.
|
|
4640
|
+
const cached = reference.file === fileOwner.record.descriptor.nodeId ? fileOwner.record.symbolsById.get(reference.id) : undefined;
|
|
4413
4641
|
if (cached)
|
|
4414
4642
|
return cached;
|
|
4415
|
-
const data = fileOwner.client.apiRequest(method, { symbol: owner.reference });
|
|
4643
|
+
const data = fileOwner.api.client.apiRequest(method, { symbol: owner.reference });
|
|
4416
4644
|
if (!data)
|
|
4417
4645
|
throw new Error(`${method} returned null symbol for Symbol ${owner.id}`);
|
|
4418
4646
|
return owner.internFileSymbol(fileOwner, data);
|
|
@@ -4422,7 +4650,7 @@ export class Symbol {
|
|
|
4422
4650
|
}
|
|
4423
4651
|
const fileOwner = owner.storage.owner;
|
|
4424
4652
|
// A file-owned symbol's relationships are always owned by the same file.
|
|
4425
|
-
const cached = reference.file === fileOwner.record.descriptor.nodeId ? fileOwner.record.
|
|
4653
|
+
const cached = reference.file === fileOwner.record.descriptor.nodeId ? fileOwner.record.symbolsById.get(reference.id) : undefined;
|
|
4426
4654
|
if (cached)
|
|
4427
4655
|
return cached;
|
|
4428
4656
|
const data = yield* apiRequest(method, { symbol: owner.reference });
|
|
@@ -4438,7 +4666,7 @@ export class Symbol {
|
|
|
4438
4666
|
return owner.storage.registry.fetchSymbols(owner, method);
|
|
4439
4667
|
}
|
|
4440
4668
|
const fileOwner = owner.storage.owner;
|
|
4441
|
-
const data = fileOwner.client.apiRequest(method, { symbol: owner.reference });
|
|
4669
|
+
const data = fileOwner.api.client.apiRequest(method, { symbol: owner.reference });
|
|
4442
4670
|
return data?.map(symbol => owner.internFileSymbol(fileOwner, symbol)) ?? [];
|
|
4443
4671
|
}, function* (method) {
|
|
4444
4672
|
if (owner.storage.kind === SymbolOwnerKind.Snapshot) {
|
|
@@ -4454,7 +4682,7 @@ export class Symbol {
|
|
|
4454
4682
|
const reference = data.reference;
|
|
4455
4683
|
if (reference.kind !== SymbolOwnerKind.File)
|
|
4456
4684
|
throw new Error(`Symbol ${reference.id} is not file-owned`);
|
|
4457
|
-
return fileOwner.
|
|
4685
|
+
return fileOwner.api.sourceFileCache.getOrCreateSymbol(fileOwner.record, reference.file, reference.id, () => new Symbol(data, { kind: SymbolOwnerKind.File, owner: fileOwner }));
|
|
4458
4686
|
}
|
|
4459
4687
|
}
|
|
4460
4688
|
class TypeObject {
|