constructor(private maxResults: number, private root: URI, private previewOptions: ITextSearchPreviewOptions) {
this.stringDecoder = new StringDecoder();
}
cancel(): void {
Frontier kind: Code frontier
unlabeled · c_47e7547f21b8
6 tests · 11425 LOC · 47 files · introduces 0 tests · 125 LOC · 2 files
The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.
Introduced files, introduced tests, and structurally relevant concept specialization
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.
Every exact file and test below is linked only from the concept that introduces it.
mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test|title=RipgrepTextSearchEngine RipgrepParser multiple results|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test|title=RipgrepTextSearchEngine RipgrepParser multiple submatches without newline in between (#131507)|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test|title=RipgrepTextSearchEngine RipgrepParser single result|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/charCode.test|title=CharCode has good values|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/path.test|title=Paths (Node Implementation) path|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI File paths containing apostrophes break URI parsing and cannot be opened #276075|occurrence=1mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI URI#file, win-speciale|occurrence=1Every collected test enters the hierarchy at exactly one concept.
No tests are introduced at this concept. Its intent tests are introduced by other concepts.
Every collected source range enters the hierarchy at exactly one concept.
2 files ranked by introduced lines: 125 introduced LOC across 25 ranges. Expand a file to inspect source; the > gutter marks introduced lines.
constructor(private maxResults: number, private root: URI, private previewOptions: ITextSearchPreviewOptions) {
this.stringDecoder = new StringDecoder();
}
cancel(): void {
flush(): void {
}
override on(event: 'hitLimit', listener: () => void): this;
override on(event: string, listener: (...args: any[]) => void): this {
return this;
}
handleData(data: Buffer | string): void {
return;
}
const dataStr = typeof data === 'string' ? data : this.stringDecoder.write(data);
this.handleDecodedData(dataStr);
}
private handleDecodedData(decodedData: string): void {
let newlineIdx = decodedData.indexOf('\n');
// If the previous data chunk didn't end in a newline, prepend it to this chunk
const dataStr = this.remainder + decodedData;
if (newlineIdx >= 0) {
newlineIdx += this.remainder.length;
} else {
// Shortcut
this.remainder = dataStr;
return;
}
let prevIdx = 0;
while (newlineIdx >= 0) {
this.handleLine(dataStr.substring(prevIdx, newlineIdx).trim());
prevIdx = newlineIdx + 1;
newlineIdx = dataStr.indexOf('\n', prevIdx);
}
this.remainder = dataStr.substring(prevIdx);
}
private handleLine(outputLine: string): void {
return;
}
let parsedLine: IRgMessage;
try {
parsedLine = JSON.parse(outputLine);
} catch (e) {
throw new Error(`malformed line from rg: ${outputLine}`);
}
if (parsedLine.type === 'match') {
const matchPath = bytesOrTextToString(parsedLine.data.path);
const uri = URI.joinPath(this.root, matchPath);
const result = this.createTextSearchMatch(parsedLine.data, uri);
this.onResult(result);
if (this.hitLimit) {
this.cancel();
this.emit('hitLimit');
}
const contextPath = bytesOrTextToString(parsedLine.data.path);
const uri = URI.joinPath(this.root, contextPath);
result.forEach(r => this.onResult(r));
}
private createTextSearchMatch(data: IRgMatch, uri: URI): TextSearchMatch2 {
const fullText = bytesOrTextToString(data.lines);
const fullTextBytes = Buffer.from(fullText);
let prevMatchEnd = 0;
let prevMatchEndCol = 0;
let prevMatchEndLine = lineNumber;
// it looks like certain regexes can match a line, but cause rg to not
// emit any specific submatches for that line.
// https://github.com/microsoft/vscode/issues/100569#issuecomment-738496991
if (data.submatches.length === 0) {
data.submatches.push(
fullText.length
);
}
const ranges = coalesce(data.submatches.map((match, i) => {
if (this.hitLimit) {
return null;
}
this.numResults++;
if (this.numResults >= this.maxResults) {
// Finish the line, then report the result below
this.hitLimit = true;
}
const matchText = bytesOrTextToString(match.match);
const inBetweenText = fullTextBytes.slice(prevMatchEnd, match.start).toString();
const inBetweenStats = getNumLinesAndLastNewlineLength(inBetweenText);
const startCol = inBetweenStats.numLines > 0 ?
inBetweenStats.lastLineLength :
const stats = getNumLinesAndLastNewlineLength(matchText);
const startLineNumber = inBetweenStats.numLines + prevMatchEndLine;
const endLineNumber = stats.numLines + startLineNumber;
const endCol = stats.numLines > 0 ?
stats.lastLineLength :
stats.lastLineLength + startCol;
prevMatchEnd = match.end;
prevMatchEndCol = endCol;
prevMatchEndLine = endLineNumber;
return new Range(startLineNumber, startCol, endLineNumber, endCol);
}));
const searchRange = mapArrayOrNot(<Range[]>ranges, rangeToSearchRange);
const internalResult = new TextSearchMatch(fullText, searchRange, this.previewOptions);
return new TextSearchMatch2(
uri,
internalResult.rangeLocations.map(e => (
{
sourceRange: searchRangeToRange(e.source),
previewRange: searchRangeToRange(e.preview),
}
)),
internalResult.previewText);
}
private createTextSearchContexts(data: IRgMatch, uri: URI): TextSearchContext2[] {
private onResult(match: TextSearchResult2): void {
}
}
return obj.bytes ?
Buffer.from(obj.bytes, 'base64').toString() :
}
function getNumLinesAndLastNewlineLength(text: string): { numLines: number; lastLineLength: number } {
ripgrepTextSearchEngine.ts
const re = /\n/g;
let numLines = 0;
let lastNewlineIdx = -1;
let match: ReturnType<typeof re.exec>;
while (match = re.exec(text)) {
numLines++;
lastNewlineIdx = match.index;
}
const lastLineLength = lastNewlineIdx >= 0 ?
text.length - lastNewlineIdx - 1 :
return { numLines, lastLineLength };
}
// exported for testing
export function rangeToSearchRange(range: searchExtTypes.Range): SearchRange {
return new SearchRange(range.start.line, range.start.character, range.end.line, range.end.character);
ripgrepSearchUtils.ts
}
export function searchRangeToRange(range: SearchRange): searchExtTypes.Range {
return new searchExtTypes.Range(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
ripgrepSearchUtils.ts
}
export interface IOutputChannel {