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

Ensure ripgrep is killed when vscode exits, for #34434

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