提交 37fc885e 编写于 作者: R Rob Lourens

Add rg json output typings

上级 bcc533fe
......@@ -183,7 +183,7 @@ export class RipgrepParser extends EventEmitter {
return;
}
let parsedLine: any;
let parsedLine: IRgMessage;
try {
parsedLine = JSON.parse(outputLine);
} catch (e) {
......@@ -191,8 +191,9 @@ export class RipgrepParser extends EventEmitter {
}
if (parsedLine.type === 'match') {
const uri = URI.file(path.join(this.rootFolder, parsedLine.data.path.text));
const result = this.submatchesToResult(parsedLine, parsedLine.data.submatches, uri);
const matchPath = bytesOrTextToString(parsedLine.data.path);
const uri = URI.file(path.join(this.rootFolder, matchPath));
const result = this.createTextSearchResult(parsedLine.data, uri);
this.onResult(result);
if (this.hitLimit) {
......@@ -202,15 +203,15 @@ export class RipgrepParser extends EventEmitter {
}
}
private submatchesToResult(parsedLine: any, matches: any[], uri: vscode.Uri): vscode.TextSearchResult {
const lineNumber = parsedLine.data.line_number - 1;
const fullText = bytesOrTextToString(parsedLine.data.lines);
private createTextSearchResult(data: IRgMatch, uri: vscode.Uri): vscode.TextSearchResult {
const lineNumber = data.line_number - 1;
const fullText = bytesOrTextToString(data.lines);
const fullTextBytes = Buffer.from(fullText);
let prevMatchEnd = 0;
let prevMatchEndCol = 0;
let prevMatchEndLine = lineNumber;
const ranges = matches.map((match, i) => {
const ranges = data.submatches.map((match, i) => {
if (this.hitLimit) {
return null;
}
......@@ -374,3 +375,24 @@ export function unicodeEscapesToPCRE2(pattern: string): string {
return pattern;
}
interface IRgMessage {
type: 'match' | 'context' | string;
data: IRgMatch;
}
interface IRgMatch {
path: IRgBytesOrText;
lines: IRgBytesOrText;
line_number: number;
absolute_offset: number;
submatches: IRgSubmatch[];
}
interface IRgSubmatch {
match: IRgBytesOrText;
start: number;
end: number;
}
type IRgBytesOrText = { bytes: string } | { text: string };
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册