<commit_before>/**
 * Find all rename locations for a symbol at location within a file
 */

import { RenameLocation, rename, success, failure, end } from './lib/client';
import { die } from './lib/log';
import { basename } from 'path';

function parseFlags(args: string[]): [string[], any] {
	const flags: any = {};

	while (true) {
		if (args[0] === '--comments' || args[0] === '-c') {
			flags.findInComments = true;
			args.shift();

			continue;
		}
		if (args[0] === '--strings' || args[0] === '-s') {
			flags.findInStrings = true;
			args.shift();

			continue;
		}
		break;
	}

	return [args, flags];
}

const [ args, flags ] = parseFlags(process.argv.slice(2));

if (args.length < 3) {
	const command = basename(process.argv[1]);
	die(`usage: ${command} [-c,--comments] [-s,--strings] filename line offset`);
}

const location: RenameLocation = {
	file: args[0],
	line: Number(args[1]),
	offset: Number(args[2]),
	...flags
};

rename(location)
	.then(success)
	.catch(failure)
	.then(end);<commit_msg>Filter library files out of rename responses<commit_after>/**
 * Find all rename locations for a symbol at location within a file
 */

import { RenameLocation, rename, success, failure, end } from './lib/client';
import { die } from './lib/log';
import { basename, relative } from 'path';

function parseFlags(args: string[]): [string[], any] {
	const flags: any = {};

	while (true) {
		if (args[0] === '--comments' || args[0] === '-c') {
			flags.findInComments = true;
			args.shift();

			continue;
		}
		if (args[0] === '--strings' || args[0] === '-s') {
			flags.findInStrings = true;
			args.shift();

			continue;
		}
		break;
	}

	return [args, flags];
}

const [ args, flags ] = parseFlags(process.argv.slice(2));

if (args.length < 3) {
	const command = basename(process.argv[1]);
	die(`usage: ${command} [-c,--comments] [-s,--strings] filename line offset`);
}

const location: RenameLocation = {
	file: args[0],
	line: Number(args[1]),
	offset: Number(args[2]),
	...flags
};

rename(location)
	.then(response => {
		// Remove any locs that are in node_modules
		response.locs = response.locs.filter(loc => {
			return !(/\bnode_modules\//).test(loc.file);
		});
		// Make all loc files relative to the CWD, which is also what VIM
		// should be doing
		response.locs.forEach(loc => {
			loc.file = relative('.', loc.file);
		});
		return response;
	})
	.then(success)
	.catch(failure)
	.then(end);
{'fraction_non_alphanumeric': 0.19297520661157025, 'fraction_numerical': 0.008264462809917356, 'mean_word_length': 3.5679245283018868, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6385185', 'n_tokens_mistral': 896, 'n_tokens_neox': 835, 'n_words': 224}