提交 e81c1d38 编写于 作者: R Rob Lourens

Fix #35192

上级 85e479f1
...@@ -74,7 +74,7 @@ export class RipgrepEngine { ...@@ -74,7 +74,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); process.once('exit', this.killRgProcFn);
this.ripgrepParser = new RipgrepParser(this.config.maxResults, cwd); this.ripgrepParser = new RipgrepParser(this.config.maxResults, cwd, this.config.extraFiles);
this.ripgrepParser.on('result', (match: ISerializedFileMatch) => { this.ripgrepParser.on('result', (match: ISerializedFileMatch) => {
if (this.postProcessExclusions) { if (this.postProcessExclusions) {
const handleResultP = (<TPromise<string>>this.postProcessExclusions(match.path, undefined, () => getSiblings(match.path))) const handleResultP = (<TPromise<string>>this.postProcessExclusions(match.path, undefined, () => getSiblings(match.path)))
...@@ -170,12 +170,15 @@ export class RipgrepParser extends EventEmitter { ...@@ -170,12 +170,15 @@ export class RipgrepParser extends EventEmitter {
private remainder: string; private remainder: string;
private isDone: boolean; private isDone: boolean;
private stringDecoder: NodeStringDecoder; private stringDecoder: NodeStringDecoder;
private extraSearchFiles: string[];
private numResults = 0; private numResults = 0;
constructor(private maxResults: number, private rootFolder: string) { constructor(private maxResults: number, private rootFolder: string, extraFiles?: string[]) {
super(); super();
this.stringDecoder = new StringDecoder(); this.stringDecoder = new StringDecoder();
this.extraSearchFiles = extraFiles || [];
} }
public cancel(): void { public cancel(): void {
...@@ -229,19 +232,37 @@ export class RipgrepParser extends EventEmitter { ...@@ -229,19 +232,37 @@ export class RipgrepParser extends EventEmitter {
this.onResult(); this.onResult();
} }
this.fileMatch = new FileMatch(path.isAbsolute(r[1]) ? r[1] : path.join(this.rootFolder, r[1])); this.fileMatch = this.getFileMatch(r[1]);
} else { } else {
// Line is empty (or malformed) // Line is empty (or malformed)
} }
} }
} }
private getFileMatch(relativeOrAbsolutePath: string): FileMatch {
const absPath = path.isAbsolute(relativeOrAbsolutePath) ?
relativeOrAbsolutePath :
path.join(this.rootFolder, relativeOrAbsolutePath);
return new FileMatch(absPath);
}
private handleMatchLine(outputLine: string, lineNum: number, text: string): void { private handleMatchLine(outputLine: string, lineNum: number, text: string): void {
if (lineNum === 0) { if (lineNum === 0) {
text = strings.stripUTF8BOM(text); text = strings.stripUTF8BOM(text);
} }
const lineMatch = new LineMatch(text, lineNum); const lineMatch = new LineMatch(text, lineNum);
if (!this.fileMatch) {
// When searching a single file and no folderQueries, rg does not print the file line, so create it here
const singleFile = this.extraSearchFiles[0];
if (!singleFile) {
throw new Error('Got match line for unknown file');
}
this.fileMatch = this.getFileMatch(singleFile);
}
this.fileMatch.addMatch(lineMatch); this.fileMatch.addMatch(lineMatch);
let lastMatchEndPos = 0; let lastMatchEndPos = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册