Skip to content

Commit

Permalink
Fix lint tool cancellation (golang#1704)
Browse files Browse the repository at this point in the history
* Recreate the cancellation token source after cancellation.

* Dispose the token source.

* Dispose and recreate the token source for go vet as well.

* Dispose tokenSource after each use
  • Loading branch information
doxxx authored and ramya-rao-a committed Jun 3, 2018
1 parent 9ea349b commit 7922389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICheckResult[]> {
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);
Expand Down Expand Up @@ -116,5 +120,5 @@ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurat
return lintPromise;
}

let tokenSource = new vscode.CancellationTokenSource();
let tokenSource: vscode.CancellationTokenSource;
let running = false;
10 changes: 7 additions & 3 deletions src/goVet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICheckResult[]> {
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);
Expand Down Expand Up @@ -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;

0 comments on commit 7922389

Please sign in to comment.