diff --git a/src/goLint.ts b/src/goLint.ts index 229410202..ab53e81e7 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -43,9 +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(); const currentWorkspace = getWorkspaceFolderPath(fileUri); const cwd = (lintWorkspace && currentWorkspace) ? currentWorkspace : path.dirname(fileUri.fsPath); @@ -105,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 11da46ac8..315d32a0e 100644 --- a/src/goVet.ts +++ b/src/goVet.ts @@ -44,9 +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(); const currentWorkspace = getWorkspaceFolderPath(fileUri); const cwd = (vetWorkspace && currentWorkspace) ? currentWorkspace : path.dirname(fileUri.fsPath); @@ -87,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;