From 4af080818a594e607aff35ca66fc18346e848cef Mon Sep 17 00:00:00 2001 From: Gordon Tyler Date: Fri, 1 Jun 2018 08:59:28 -0400 Subject: [PATCH 1/4] Recreate the cancellation token source after cancellation. --- src/goLint.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/goLint.ts b/src/goLint.ts index 229410202..58c3e5155 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -45,6 +45,7 @@ export function lintCode(lintWorkspace?: boolean) { export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, lintWorkspace?: boolean): Promise { if (running) { tokenSource.cancel(); + tokenSource = new vscode.CancellationTokenSource(); } const currentWorkspace = getWorkspaceFolderPath(fileUri); From 2e779e835b6acc1e09e752ee60374fcc5f67fb84 Mon Sep 17 00:00:00 2001 From: Gordon Tyler Date: Sat, 2 Jun 2018 08:15:42 -0400 Subject: [PATCH 2/4] Dispose the token source. --- src/goLint.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/goLint.ts b/src/goLint.ts index 58c3e5155..2c3e701cc 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -45,6 +45,7 @@ export function lintCode(lintWorkspace?: boolean) { export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, lintWorkspace?: boolean): Promise { if (running) { tokenSource.cancel(); + tokenSource.dispose(); tokenSource = new vscode.CancellationTokenSource(); } From cd06f66d29bacacffd9d95f9a974aae2bcf04c41 Mon Sep 17 00:00:00 2001 From: Gordon Tyler Date: Sat, 2 Jun 2018 08:24:12 -0400 Subject: [PATCH 3/4] Dispose and recreate the token source for go vet as well. --- src/goVet.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/goVet.ts b/src/goVet.ts index 11da46ac8..cceebb6b4 100644 --- a/src/goVet.ts +++ b/src/goVet.ts @@ -46,6 +46,8 @@ export function vetCode(vetWorkspace?: boolean) { export function goVet(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, vetWorkspace?: boolean): Promise { if (running) { tokenSource.cancel(); + tokenSource.dispose(); + tokenSource = new vscode.CancellationTokenSource(); } const currentWorkspace = getWorkspaceFolderPath(fileUri); From 7f8e68df058bd69bf7c64313cf5b26234bd6544e Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Sun, 3 Jun 2018 09:40:26 -0700 Subject: [PATCH 4/4] Dispose tokenSource after each use --- src/goLint.ts | 10 ++++++---- src/goVet.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/goLint.ts b/src/goLint.ts index 2c3e701cc..ab53e81e7 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -43,11 +43,13 @@ export function lintCode(lintWorkspace?: boolean) { * @param lintWorkspace If true runs linter in all workspace. */ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, lintWorkspace?: boolean): Promise { - if (running) { - tokenSource.cancel(); + if (tokenSource) { + if (running) { + tokenSource.cancel(); + } tokenSource.dispose(); - tokenSource = new vscode.CancellationTokenSource(); } + tokenSource = new vscode.CancellationTokenSource(); const currentWorkspace = getWorkspaceFolderPath(fileUri); const cwd = (lintWorkspace && currentWorkspace) ? currentWorkspace : path.dirname(fileUri.fsPath); @@ -107,5 +109,5 @@ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurat return lintPromise; } -let tokenSource = new vscode.CancellationTokenSource(); +let tokenSource: vscode.CancellationTokenSource; let running = false; diff --git a/src/goVet.ts b/src/goVet.ts index cceebb6b4..315d32a0e 100644 --- a/src/goVet.ts +++ b/src/goVet.ts @@ -44,11 +44,13 @@ export function vetCode(vetWorkspace?: boolean) { * @param vetWorkspace If true vets code in all workspace. */ export function goVet(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, vetWorkspace?: boolean): Promise { - if (running) { - tokenSource.cancel(); + if (tokenSource) { + if (running) { + tokenSource.cancel(); + } tokenSource.dispose(); - tokenSource = new vscode.CancellationTokenSource(); } + tokenSource = new vscode.CancellationTokenSource(); const currentWorkspace = getWorkspaceFolderPath(fileUri); const cwd = (vetWorkspace && currentWorkspace) ? currentWorkspace : path.dirname(fileUri.fsPath); @@ -89,5 +91,5 @@ export function goVet(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurati return vetPromise; } -let tokenSource = new vscode.CancellationTokenSource(); +let tokenSource: vscode.CancellationTokenSource; let running = false;