Skip to content

Commit c9c0f3a

Browse files
PR feedback.
1 parent df13b8f commit c9c0f3a

File tree

10 files changed

+69
-70
lines changed

10 files changed

+69
-70
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace ts {
167167

168168
return checker;
169169

170-
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationTokenObject) {
170+
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
171171
// Ensure we have all the type information in place for this file so that all the
172172
// emitter questions of this resolver will return the right information.
173173
getDiagnostics(sourceFile, cancellationToken);
@@ -11681,8 +11681,8 @@ namespace ts {
1168111681
}
1168211682
}
1168311683

11684-
var cancellationToken: CancellationTokenObject;
11685-
function getDiagnostics(sourceFile: SourceFile, ct: CancellationTokenObject): Diagnostic[] {
11684+
var cancellationToken: CancellationToken;
11685+
function getDiagnostics(sourceFile: SourceFile, ct: CancellationToken): Diagnostic[] {
1168611686
try {
1168711687
// Record the cancellation token so it can be checked later on during checkSourceElement.
1168811688
// Do this in a finally block so we can ensure that it gets reset back to nothing after

src/compiler/core.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -798,25 +798,4 @@ namespace ts {
798798
Debug.assert(false, message);
799799
}
800800
}
801-
}
802-
803-
namespace ts {
804-
export class OperationCanceledException { }
805-
806-
export class CancellationTokenObject {
807-
public static None: CancellationTokenObject = new CancellationTokenObject(null)
808-
809-
constructor(private cancellationToken: CancellationToken) {
810-
}
811-
812-
public isCancellationRequested() {
813-
return this.cancellationToken && this.cancellationToken.isCancellationRequested();
814-
}
815-
816-
public throwIfCancellationRequested(): void {
817-
if (this.isCancellationRequested()) {
818-
throw new OperationCanceledException();
819-
}
820-
}
821-
}
822801
}

src/compiler/program.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace ts {
104104
};
105105
}
106106

107-
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[] {
107+
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[] {
108108
let diagnostics = program.getOptionsDiagnostics(cancellationToken).concat(
109109
program.getSyntacticDiagnostics(sourceFile, cancellationToken),
110110
program.getGlobalDiagnostics(cancellationToken),
@@ -233,11 +233,11 @@ namespace ts {
233233
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
234234
}
235235

236-
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationTokenObject): EmitResult {
236+
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult {
237237
return runWithCancellationToken(() => emitWorker(this, sourceFile, writeFileCallback, cancellationToken));
238238
}
239239

240-
function emitWorker(program: Program, sourceFile: SourceFile, writeFileCallback: WriteFileCallback, cancellationToken: CancellationTokenObject): EmitResult {
240+
function emitWorker(program: Program, sourceFile: SourceFile, writeFileCallback: WriteFileCallback, cancellationToken: CancellationToken): EmitResult {
241241
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
242242
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
243243
// get any preEmit diagnostics, not just the ones
@@ -272,8 +272,8 @@ namespace ts {
272272

273273
function getDiagnosticsHelper(
274274
sourceFile: SourceFile,
275-
getDiagnostics: (sourceFile: SourceFile, cancellationToken: CancellationTokenObject) => Diagnostic[],
276-
cancellationToken: CancellationTokenObject): Diagnostic[] {
275+
getDiagnostics: (sourceFile: SourceFile, cancellationToken: CancellationToken) => Diagnostic[],
276+
cancellationToken: CancellationToken): Diagnostic[] {
277277
if (sourceFile) {
278278
return getDiagnostics(sourceFile, cancellationToken);
279279
}
@@ -289,19 +289,19 @@ namespace ts {
289289
return sortAndDeduplicateDiagnostics(allDiagnostics);
290290
}
291291

292-
function getSyntacticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
292+
function getSyntacticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
293293
return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile, cancellationToken);
294294
}
295295

296-
function getSemanticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
296+
function getSemanticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
297297
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile, cancellationToken);
298298
}
299299

300-
function getDeclarationDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
300+
function getDeclarationDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
301301
return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile, cancellationToken);
302302
}
303303

304-
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
304+
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
305305
return sourceFile.parseDiagnostics;
306306
}
307307

@@ -321,7 +321,7 @@ namespace ts {
321321
}
322322
}
323323

324-
function getSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
324+
function getSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
325325
return runWithCancellationToken(() => {
326326
let typeChecker = getDiagnosticsProducingTypeChecker();
327327

@@ -334,7 +334,7 @@ namespace ts {
334334
});
335335
}
336336

337-
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationTokenObject): Diagnostic[] {
337+
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
338338
return runWithCancellationToken(() => {
339339
if (!isDeclarationFile(sourceFile)) {
340340
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);

src/compiler/types.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,13 +1210,13 @@ namespace ts {
12101210
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
12111211
* will be invoked when writing the JavaScript and declaration files.
12121212
*/
1213-
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationTokenObject): EmitResult;
1213+
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult;
12141214

1215-
getOptionsDiagnostics(cancellationToken?: CancellationTokenObject): Diagnostic[];
1216-
getGlobalDiagnostics(cancellationToken?: CancellationTokenObject): Diagnostic[];
1217-
getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[];
1218-
getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[];
1219-
getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[];
1215+
getOptionsDiagnostics(cancellationToken?: CancellationToken): Diagnostic[];
1216+
getGlobalDiagnostics(cancellationToken?: CancellationToken): Diagnostic[];
1217+
getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
1218+
getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
1219+
getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
12201220

12211221
/**
12221222
* Gets a type checker that can be used to semantically analyze source fils in the program.
@@ -1324,9 +1324,9 @@ namespace ts {
13241324
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
13251325

13261326
// Should not be called directly. Should only be accessed through the Program instance.
1327-
/* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[];
1327+
/* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
13281328
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
1329-
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): EmitResolver;
1329+
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken): EmitResolver;
13301330

13311331
/* @internal */ getNodeCount(): number;
13321332
/* @internal */ getIdentifierCount(): number;
@@ -2052,14 +2052,18 @@ namespace ts {
20522052
verticalTab = 0x0B, // \v
20532053
}
20542054

2055+
export class OperationCanceledException { }
2056+
20552057
export interface CancellationToken {
20562058
isCancellationRequested(): boolean;
2059+
2060+
/** @throws OperationCanceledException if isCancellationRequested is true */
2061+
throwIfCancellationRequested(): void;
20572062
}
20582063

20592064
export interface CompilerHost {
20602065
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
20612066
getDefaultLibFileName(options: CompilerOptions): string;
2062-
getCancellationToken? (): CancellationToken;
20632067
writeFile: WriteFileCallback;
20642068
getCurrentDirectory(): string;
20652069
getCanonicalFileName(fileName: string): string;

src/harness/fourslash.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ module FourSlash {
190190
return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n";
191191
}
192192

193-
export class TestCancellationToken implements ts.CancellationToken {
193+
export class TestCancellationToken implements ts.HostCancellationToken {
194194
// 0 - cancelled
195195
// >0 - not cancelled
196196
// <0 - not cancelled and value denotes number of isCancellationRequested after which token become cancelled
197-
private static NotCancelled: number = -1;
198-
private numberOfCallsBeforeCancellation: number = TestCancellationToken.NotCancelled;
199-
public isCancellationRequested(): boolean {
197+
private static NotCanceled: number = -1;
198+
private numberOfCallsBeforeCancellation: number = TestCancellationToken.NotCanceled;
200199

200+
public isCancellationRequested(): boolean {
201201
if (this.numberOfCallsBeforeCancellation < 0) {
202202
return false;
203203
}
@@ -216,7 +216,7 @@ module FourSlash {
216216
}
217217

218218
public resetCancelled(): void {
219-
this.numberOfCallsBeforeCancellation = TestCancellationToken.NotCancelled;
219+
this.numberOfCallsBeforeCancellation = TestCancellationToken.NotCanceled;
220220
}
221221
}
222222

src/harness/harnessLanguageService.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,11 @@ module Harness.LanguageService {
103103
}
104104
}
105105

106-
class CancellationToken {
107-
public static None: CancellationToken = new CancellationToken(null);
108-
109-
constructor(private cancellationToken: ts.CancellationToken) {
110-
}
106+
class DefaultHostCancellationToken implements ts.HostCancellationToken {
107+
public static Instance = new DefaultHostCancellationToken();
111108

112109
public isCancellationRequested() {
113-
return this.cancellationToken && this.cancellationToken.isCancellationRequested();
110+
return false;
114111
}
115112
}
116113

@@ -124,8 +121,8 @@ module Harness.LanguageService {
124121
export class LanguageServiceAdapterHost {
125122
protected fileNameToScript: ts.Map<ScriptInfo> = {};
126123

127-
constructor(protected cancellationToken: ts.CancellationToken = CancellationToken.None,
128-
protected settings = ts.getDefaultCompilerOptions()) {
124+
constructor(protected cancellationToken = DefaultHostCancellationToken.Instance,
125+
protected settings = ts.getDefaultCompilerOptions()) {
129126
}
130127

131128
public getNewLine(): string {
@@ -173,8 +170,8 @@ module Harness.LanguageService {
173170

174171
/// Native adapter
175172
class NativeLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceHost {
176-
getCompilationSettings(): ts.CompilerOptions { return this.settings; }
177-
getCancellationToken(): ts.CancellationToken { return this.cancellationToken; }
173+
getCompilationSettings() { return this.settings; }
174+
getCancellationToken() { return this.cancellationToken; }
178175
getCurrentDirectory(): string { return ""; }
179176
getDefaultLibFileName(): string { return ""; }
180177
getScriptFileNames(): string[] { return this.getFilenames(); }
@@ -194,7 +191,7 @@ module Harness.LanguageService {
194191

195192
export class NativeLanugageServiceAdapter implements LanguageServiceAdapter {
196193
private host: NativeLanguageServiceHost;
197-
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
194+
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
198195
this.host = new NativeLanguageServiceHost(cancellationToken, options);
199196
}
200197
getHost() { return this.host; }
@@ -206,7 +203,7 @@ module Harness.LanguageService {
206203
/// Shim adapter
207204
class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost, ts.CoreServicesShimHost {
208205
private nativeHost: NativeLanguageServiceHost;
209-
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
206+
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
210207
super(cancellationToken, options);
211208
this.nativeHost = new NativeLanguageServiceHost(cancellationToken, options);
212209
}
@@ -218,7 +215,7 @@ module Harness.LanguageService {
218215
positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToLineAndCharacter(fileName, position); }
219216

220217
getCompilationSettings(): string { return JSON.stringify(this.nativeHost.getCompilationSettings()); }
221-
getCancellationToken(): ts.CancellationToken { return this.nativeHost.getCancellationToken(); }
218+
getCancellationToken(): ts.HostCancellationToken { return this.nativeHost.getCancellationToken(); }
222219
getCurrentDirectory(): string { return this.nativeHost.getCurrentDirectory(); }
223220
getDefaultLibFileName(): string { return this.nativeHost.getDefaultLibFileName(); }
224221
getScriptFileNames(): string { return JSON.stringify(this.nativeHost.getScriptFileNames()); }
@@ -399,7 +396,7 @@ module Harness.LanguageService {
399396
export class ShimLanugageServiceAdapter implements LanguageServiceAdapter {
400397
private host: ShimLanguageServiceHost;
401398
private factory: ts.TypeScriptServicesFactory;
402-
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
399+
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
403400
this.host = new ShimLanguageServiceHost(cancellationToken, options);
404401
this.factory = new TypeScript.Services.TypeScriptServicesFactory();
405402
}
@@ -446,7 +443,7 @@ module Harness.LanguageService {
446443
class SessionClientHost extends NativeLanguageServiceHost implements ts.server.SessionClientHost {
447444
private client: ts.server.SessionClient;
448445

449-
constructor(cancellationToken: ts.CancellationToken, settings: ts.CompilerOptions) {
446+
constructor(cancellationToken: ts.HostCancellationToken, settings: ts.CompilerOptions) {
450447
super(cancellationToken, settings);
451448
}
452449

@@ -575,7 +572,7 @@ module Harness.LanguageService {
575572
export class ServerLanugageServiceAdapter implements LanguageServiceAdapter {
576573
private host: SessionClientHost;
577574
private client: ts.server.SessionClient;
578-
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
575+
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
579576
// This is the main host that tests use to direct tests
580577
var clientHost = new SessionClientHost(cancellationToken, options);
581578
var client = new ts.server.SessionClient(clientHost);

src/services/navigateTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ts.NavigateTo {
33
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
44

5-
export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[] {
5+
export function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] {
66
let patternMatcher = createPatternMatcher(searchValue);
77
let rawItems: RawNavigateToItem[] = [];
88

src/services/services.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,10 @@ namespace ts {
944944
}
945945
}
946946

947+
export interface HostCancellationToken {
948+
isCancellationRequested(): boolean;
949+
}
950+
947951
//
948952
// Public interface of the host of a language service instance.
949953
//
@@ -955,7 +959,7 @@ namespace ts {
955959
getScriptVersion(fileName: string): string;
956960
getScriptSnapshot(fileName: string): IScriptSnapshot;
957961
getLocalizedDiagnosticMessages?(): any;
958-
getCancellationToken?(): CancellationToken;
962+
getCancellationToken?(): HostCancellationToken;
959963
getCurrentDirectory(): string;
960964
getDefaultLibFileName(options: CompilerOptions): string;
961965
log? (s: string): void;
@@ -2379,6 +2383,21 @@ namespace ts {
23792383
return ScriptElementKind.unknown;
23802384
}
23812385

2386+
class CancellationTokenObject implements CancellationToken {
2387+
constructor(private cancellationToken: HostCancellationToken) {
2388+
}
2389+
2390+
public isCancellationRequested() {
2391+
return this.cancellationToken && this.cancellationToken.isCancellationRequested();
2392+
}
2393+
2394+
public throwIfCancellationRequested(): void {
2395+
if (this.isCancellationRequested()) {
2396+
throw new OperationCanceledException();
2397+
}
2398+
}
2399+
}
2400+
23822401
export function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry = createDocumentRegistry()): LanguageService {
23832402
let syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
23842403
let ruleProvider: formatting.RulesProvider;

src/services/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace ts {
5151
getScriptVersion(fileName: string): string;
5252
getScriptSnapshot(fileName: string): ScriptSnapshotShim;
5353
getLocalizedDiagnosticMessages(): string;
54-
getCancellationToken(): CancellationToken;
54+
getCancellationToken(): HostCancellationToken;
5555
getCurrentDirectory(): string;
5656
getDefaultLibFileName(options: string): string;
5757
getNewLine?(): string;
@@ -326,7 +326,7 @@ namespace ts {
326326
}
327327
}
328328

329-
public getCancellationToken(): CancellationToken {
329+
public getCancellationToken(): HostCancellationToken {
330330
return this.shimHost.getCancellationToken();
331331
}
332332

0 commit comments

Comments
 (0)