Added recursion modularity to ripgrep

This commit is contained in:
Sean Meininger 2022-10-09 17:24:00 -07:00
parent ae091b8dea
commit 5c30db838c
2 changed files with 6 additions and 2 deletions

View file

@ -2,11 +2,15 @@ import { rgPath } from "@vscode/ripgrep";
import { spawn } from "child_process"; import { spawn } from "child_process";
import { once } from "events"; import { once } from "events";
// TODO: At present, this function is always called recursively in the current directory via process.cwd()
// I might need to add '--max-depth 1' to account for someone nesting sentinel directories
// syntax is 'rg --max-depth 1'
// TODO: At present there's absolutely no point using typescript for this module. // TODO: At present there's absolutely no point using typescript for this module.
// I need to figure out how returning Promise values works when implemented with `spawn` // I need to figure out how returning Promise values works when implemented with `spawn`
export async function ripGrep(phrase: string) { export async function ripGrep(phrase: string, dir: string=process.cwd(), recursiveSearch:boolean=true) {
try { try {
const rg = spawn(rgPath, [phrase, process.cwd()]); const rg = spawn(rgPath, [phrase, dir]);
let exitCode; let exitCode;
// Capture ripgrep exit code and return it after the process finishes // Capture ripgrep exit code and return it after the process finishes
//exit code for 'no match' is 1 for ripgrep //exit code for 'no match' is 1 for ripgrep

Binary file not shown.