Hook up CancellationToken

This commit is contained in:
Matt Bierner
2018-07-11 08:50:14 -07:00
parent 97734e3a39
commit 6c99578088

View File

@@ -15,6 +15,7 @@ class TagClosing {
private _disposed = false;
private _timeout: NodeJS.Timer | undefined = undefined;
private _cancel: vscode.CancellationTokenSource | undefined = undefined;
private readonly _disposables: vscode.Disposable[] = [];
constructor(
@@ -27,12 +28,20 @@ class TagClosing {
}
public dispose() {
disposeAll(this._disposables);
this._disposed = true;
disposeAll(this._disposables);
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = undefined;
}
if (this._cancel) {
this._cancel.cancel();
this._cancel.dispose();
this._cancel = undefined;
}
}
private onDidChangeTextDocument(
@@ -53,6 +62,12 @@ class TagClosing {
clearTimeout(this._timeout);
}
if (this._cancel) {
this._cancel.cancel();
this._cancel.dispose();
this._cancel = undefined;
}
const lastChange = changes[changes.length - 1];
const lastCharacter = lastChange.text[lastChange.text.length - 1];
if (lastChange.rangeLength > 0 || lastCharacter !== '>' && lastCharacter !== '/') {
@@ -77,8 +92,9 @@ class TagClosing {
let body: Proto.TextInsertion | undefined = undefined;
const args: Proto.JsxClosingTagRequestArgs = typeConverters.Position.toFileLocationRequestArgs(filepath, position);
this._cancel = new vscode.CancellationTokenSource();
try {
const response = await this.client.execute('jsxClosingTag', args, null as any);
const response = await this.client.execute('jsxClosingTag', args, this._cancel.token);
body = response && response.body;
if (!body) {
return;