Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fix lint tool cancellation #1704

Merged
merged 4 commits into from
Jun 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
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;