Utils to make it easy to call ripgrep
in VSCode's extensions.
yarn add vscode-ripgrep-utils
VSCode use ripgrep
to search files. There is a rg
binary in VSCode's installation directory, but the location differs on different platforms and different versions. This package provides a getBinPath
function to get the absolute path of the rg
binary.
import * as vscode from "vscode";
import { getBinPath } from "vscode-ripgrep-utils";
await getBinPath(vscode.env.appRoot);
Then you can use the high level search
function to search files, or the low level exec
/execJson
functions to execute ripgrep
with custom arguments.
import * as vscode from "vscode";
import { getBinPath, search, exec, execJson } from "vscode-ripgrep-utils";
const bin = await getBinPath(vscode.env.appRoot);
await search({ bin, folder: "./", regex: "123" });
await exec(bin, "--version");
await execJson(bin, "-e", "123");
Enable debug to see what command is executed.
import { config } from "vscode-ripgrep-utils";
config.debug = true;
This project is inspired by Gruntfuggly/todo-tree and alexlafroscia/ripgrep-js.