未验证 提交 969b1d63 编写于 作者: R Rob Lourens

Ensure ripgrep is killed when vscode exits, for #34434

上级 c971716b
......@@ -210,7 +210,11 @@ export class FileWalker {
private cmdTraversal(folderQuery: IFolderSearch, onResult: (result: IRawFileMatch) => void, cb: (err?: Error) => void): void {
const rootFolder = folderQuery.folder;
const isMac = platform.isMacintosh;
let cmd: childProcess.ChildProcess;
const killCmd = () => cmd && cmd.kill();
let done = (err?: Error) => {
process.removeListener('exit', killCmd);
done = () => { };
cb(err);
};
......@@ -219,7 +223,6 @@ export class FileWalker {
const tree = this.initDirectoryTree();
const useRipgrep = this.useRipgrep;
let cmd: childProcess.ChildProcess;
let noSiblingsClauses: boolean;
let filePatternSeen = false;
if (useRipgrep) {
......@@ -230,6 +233,7 @@ export class FileWalker {
cmd = this.spawnFindCmd(folderQuery);
}
process.on('exit', killCmd);
this.collectStdout(cmd, 'utf8', useRipgrep, (err: Error, stdout?: string, last?: boolean) => {
if (err) {
done(err);
......
......@@ -26,6 +26,7 @@ import { ISerializedFileMatch, ISerializedSearchComplete, IRawSearch, IFolderSea
export class RipgrepEngine {
private isDone = false;
private rgProc: cp.ChildProcess;
private killRgProcFn: Function;
private postProcessExclusions: glob.ParsedExpression;
private ripgrepParser: RipgrepParser;
......@@ -33,6 +34,7 @@ export class RipgrepEngine {
private resultsHandledP: TPromise<any> = TPromise.wrap(null);
constructor(private config: IRawSearch) {
this.killRgProcFn = () => this.rgProc && this.rgProc.kill();
}
cancel(): void {
......@@ -44,6 +46,7 @@ export class RipgrepEngine {
// TODO@Rob - make promise-based once the old search is gone, and I don't need them to have matching interfaces anymore
search(onResult: (match: ISerializedFileMatch) => void, onMessage: (message: ISearchLog) => void, done: (error: Error, complete: ISerializedSearchComplete) => void): void {
if (!this.config.folderQueries.length && !this.config.extraFiles.length) {
process.removeListener('exit', this.killRgProcFn);
done(null, {
limitHit: false,
stats: null
......@@ -69,6 +72,7 @@ export class RipgrepEngine {
}
});
this.rgProc = cp.spawn(rgPath, rgArgs.globArgs, { cwd });
process.once('exit', this.killRgProcFn);
this.ripgrepParser = new RipgrepParser(this.config.maxResults, cwd);
this.ripgrepParser.on('result', (match: ISerializedFileMatch) => {
......@@ -87,6 +91,7 @@ export class RipgrepEngine {
});
this.ripgrepParser.on('hitLimit', () => {
this.cancel();
process.removeListener('exit', this.killRgProcFn);
done(null, {
limitHit: true,
stats: null
......@@ -115,6 +120,7 @@ export class RipgrepEngine {
if (!this.isDone) {
this.isDone = true;
let displayMsg: string;
process.removeListener('exit', this.killRgProcFn);
if (stderr && !gotData && (displayMsg = this.rgErrorMsgForDisplay(stderr))) {
done(new Error(displayMsg), {
limitHit: false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册