-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2332 from yoyo930021/impl-cancellationToken
Stop computing outdated diagnostics with CancellationToken
- Loading branch information
Showing
9 changed files
with
128 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { T_TypeScript } from '../services/dependencyService'; | ||
import { CancellationToken as TSCancellationToken } from 'typescript'; | ||
import { CancellationTokenSource, CancellationToken as LSPCancellationToken } from 'vscode-languageserver'; | ||
|
||
export interface VCancellationToken extends LSPCancellationToken { | ||
tsToken: TSCancellationToken; | ||
} | ||
|
||
export class VCancellationTokenSource extends CancellationTokenSource { | ||
constructor(private tsModule: T_TypeScript) { | ||
super(); | ||
} | ||
|
||
get token(): VCancellationToken { | ||
const operationCancelException = this.tsModule.OperationCanceledException; | ||
const token = super.token as VCancellationToken; | ||
token.tsToken = { | ||
isCancellationRequested() { | ||
return token.isCancellationRequested; | ||
}, | ||
throwIfCancellationRequested() { | ||
if (token.isCancellationRequested) { | ||
throw new operationCancelException(); | ||
} | ||
} | ||
}; | ||
return token; | ||
} | ||
} | ||
|
||
export function isVCancellationRequested(token?: VCancellationToken) { | ||
return new Promise(resolve => { | ||
if (!token) { | ||
resolve(false); | ||
} else { | ||
setImmediate(() => resolve(token.isCancellationRequested)); | ||
} | ||
}); | ||
} |