How to use vscode-ripgrep - 8 common examples

To help you get started, we’ve selected a few vscode-ripgrep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esrlabs / chipmunk / application / electron / src / rg.ts View on Github external
import { rgPath } from 'vscode-ripgrep';
import { spawn, ChildProcess } from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
import * as Stream from 'stream';
import * as tty from 'tty';

const cmd: string = rgPath.replace(/\bnode_modules\.asar\b/, 'node_modules.asar.unpacked');

const readStream = fs.createReadStream('/Users/dmitry.astafyev/WebstormProjects/logviewer/logs_examples/tm_b.log', { start: 90, end: 999, autoClose: true, encoding: 'utf8' });
readStream.on('open', (fd) => {

    const rg = spawn(cmd, ['-N', '-e', '12:38', '-'], {
        stdio: ['pipe', 'inherit', 'ignore'],
    });
    //process.stdin.write('fdsfds0.9149597fsd\n\r');
    //process.stdin.end('\n\r');
    readStream.pipe(rg.stdin);


    readStream.on('data', (chunk) => {
        // rg.stdin.write('\n\r');
        console.log(`READ: ${chunk}`);
    });
github atom / atom / src / ripgrep-directory-searcher.js View on Github external
searchInDirectory(directory, regexp, options, numPathsFound) {
    // Delay the require of vscode-ripgrep to not mess with the snapshot creation.
    if (!this.rgPath) {
      this.rgPath = require('vscode-ripgrep').rgPath.replace(
        /\bapp\.asar\b/,
        'app.asar.unpacked'
      );
    }

    const directoryPath = directory.getPath();
    const regexpStr = this.prepareRegexp(regexp.source);

    const args = ['--hidden', '--json', '--regexp', regexpStr];
    if (options.leadingContextLineCount) {
      args.push('--before-context', options.leadingContextLineCount);
    }
    if (options.trailingContextLineCount) {
      args.push('--after-context', options.trailingContextLineCount);
    }
    if (regexp.ignoreCase) {
github cdr / code-server / scripts / nbin-shim.js View on Github external
// This file is prepended to loader/entry code (like our main.js or VS Code's
// bootstrap-fork.js). {{ROOT_PATH}} is replaced during the build process.
if (!global.NBIN_LOADED) {
	try {
		const nbin = require("nbin");
		nbin.shimNativeFs("{{ROOT_PATH}}");
		global.NBIN_LOADED = true;
		const path = require("path");
		const rg = require("vscode-ripgrep");
		rg.binaryRgPath = rg.rgPath;
		rg.rgPath = path.join(
			require("os").tmpdir(),
			`code-server/${path.basename(rg.binaryRgPath)}`
		);
	} catch (error) { /*  Not in the binary. */ }
}
github cdr / code-server / scripts / nbin-shim.js View on Github external
// This file is prepended to loader/entry code (like our main.js or VS Code's
// bootstrap-fork.js). {{ROOT_PATH}} is replaced during the build process.
if (!global.NBIN_LOADED) {
	try {
		const nbin = require("nbin");
		nbin.shimNativeFs("{{ROOT_PATH}}");
		global.NBIN_LOADED = true;
		const path = require("path");
		const rg = require("vscode-ripgrep");
		rg.binaryRgPath = rg.rgPath;
		rg.rgPath = path.join(
			require("os").tmpdir(),
			`code-server/${path.basename(rg.binaryRgPath)}`
		);
	} catch (error) { /*  Not in the binary. */ }
}
github atom / fuzzy-finder / lib / load-paths-handler.js View on Github external
/* global emit */

const async = require('async')
const fs = require('fs')
const os = require('os')
const path = require('path')
const {GitRepository} = require('atom')
const {Minimatch} = require('minimatch')
const childProcess = require('child_process')
const { rgPath } = require('vscode-ripgrep')

const PathsChunkSize = 100

// Use the unpacked path if the ripgrep binary is in asar archive.
const realRgPath = rgPath.replace(/\bapp\.asar\b/, 'app.asar.unpacked')

// Define the maximum number of concurrent crawling processes based on the number of CPUs
// with a maximum value of 8 and minimum of 1.
const MaxConcurrentCrawls = Math.min(Math.max(os.cpus().length - 1, 8), 1)

const emittedPaths = new Set()

class PathLoader {
  constructor (rootPath, ignoreVcsIgnores, traverseSymlinkDirectories, ignoredNames, useRipGrep) {
    this.rootPath = rootPath
    this.ignoreVcsIgnores = ignoreVcsIgnores
    this.traverseSymlinkDirectories = traverseSymlinkDirectories
    this.ignoredNames = ignoredNames
    this.useRipGrep = useRipGrep
    this.paths = []
    this.inodes = new Set()
github marktext / marktext / src / renderer / node / paths.js View on Github external
import { rgPath } from 'vscode-ripgrep'
import EnvPaths from 'common/envPaths'

// "vscode-ripgrep" is unpacked out of asar because of the binary.
const rgDiskPath = rgPath.replace(/\bapp\.asar\b/, 'app.asar.unpacked')

class RendererPaths extends EnvPaths {
  /**
   * Configure and sets all application paths.
   *
   * @param {string} userDataPath The user data path.
   */
  constructor (userDataPath) {
    if (!userDataPath) {
      throw new Error('No user data path is given.')
    }

    // Initialize environment paths
    super(userDataPath)

    // Allow to use a local ripgrep binary (e.g. an optimized version).
github malkomalko / searchy / provider.js View on Github external
const vscode = require('vscode')
const querystring = require('querystring')
const rgPath = require('vscode-ripgrep').rgPath
const {
  execSync
} = require('child_process')

const rootPath = vscode.workspace.rootPath

const execOpts = {
  cwd: rootPath,
  maxBuffer: 1024 * 1000
}

class SearchyProvider {
  constructor() {
    this.links = []
    this._subscriptions = vscode.workspace.onDidCloseTextDocument(doc => {
      this.links[doc.uri.toString()] = []
github esrlabs / chipmunk / application / electron / src / controllers / controller.stream.search.rg.ts View on Github external
export interface IMatch {
    text: string;
    index: number;
}

export interface IRegDescription {
    reg: RegExp;
    groups: number;
}

export class RGSearchWrapper {

    private _logger: Logger;
    private _targetFile: string;
    private _resultsFile: string;
    private _cmd: string = rgPath.replace(/\bnode_modules\.asar\b/, 'node_modules.asar.unpacked');
    private _process: ChildProcess | undefined;
    private _last: string | undefined;

    constructor(targetFile: string, resultsFile: string) {
        this._targetFile = targetFile;
        this._resultsFile = resultsFile;
        this._logger = new Logger(`RGSearchWrapper (${path.basename(targetFile)})`);
    }

    public search(regExp: RegExp | RegExp[]): Promise {
        return new Promise((resolve, reject) => {
            if (this._process !== undefined) {
                return new Error(this._logger.warn(`Cannot start new search because previous isn't finished yet.`));
            }
            if (!(regExp instanceof Array)) {
                regExp = [regExp];

vscode-ripgrep

A module for using ripgrep in a Node project

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages