Skip to content

Commit

Permalink
Hook up search cancellation - #47058
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Apr 20, 2018
1 parent 5a47ebc commit b14b626
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions extensions/search-rg/src/ripgrepTextSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export class RipgrepTextSearchEngine {
process.once('exit', this.killRgProcFn);
}

cancel(): void {
this.ripgrepParser.cancel();
this.rgProc.kill();
}

provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Thenable<void> {
return new Promise((resolve, reject) => {
let isDone = false;
token.onCancellationRequested(e => {
this.ripgrepParser.cancel();
this.rgProc.kill();
});

const rgArgs = getRgArgs(query, options);

const cwd = options.folder.fsPath;
Expand Down Expand Up @@ -74,14 +75,18 @@ export class RipgrepTextSearchEngine {
});

this.rgProc.on('close', code => {
// Trigger last result
this.ripgrepParser.flush();
this.rgProc = null;
let displayMsg: string;
if (stderr && !gotData && (displayMsg = rgErrorMsgForDisplay(stderr))) {
reject(new Error(displayMsg));
} else {
if (isDone) {
resolve();
} else {
// Trigger last result
this.ripgrepParser.flush();
this.rgProc = null;
let displayMsg: string;
if (stderr && !gotData && (displayMsg = rgErrorMsgForDisplay(stderr))) {
reject(new Error(displayMsg));
} else {
resolve();
}
}
});
});
Expand Down

0 comments on commit b14b626

Please sign in to comment.