<commit_before>import * as vscode from "vscode";

const REGEX_SYMBOL = ":";

function stripRootPath(file: string): string {
  const rootPath = vscode.workspace.rootPath;

  return file.replace(rootPath + "/", "");
}

function currentFile(): string {
  const currentFile = vscode.window.activeTextEditor;

  if (currentFile === undefined) return;

  return stripRootPath(currentFile.document.fileName);
}

function arrayToGlob(matches): string {
  const glob = "{" + matches.join(",") + "}";

  return glob;
}

type Mapping = {
  from: string;
  to: string;
};

type Match = {
  path: string;
} & Mapping;

function generateFilePaths(filePath: string): Match[] {
  const mappings: Mapping[] = vscode.workspace
    .getConfiguration()
    .get("fileswitcher.mappings");

  const matches = [];

  mappings.forEach((mapping) => {
    const regexp = new RegExp(mapping["from"], "i");
    const match = regexp.exec(filePath);

    if (match === null) return;

    let newFilePath = mapping["to"];

    match.forEach((item, index) => {
      newFilePath = newFilePath.replace(REGEX_SYMBOL + index, item);
    });

    matches.push({ from: mapping.from, to: mapping.to, path: newFilePath });
  });

  return matches;
}

function findMatchingFiles(file: string): Thenable<vscode.Uri[]> {
  const matches = generateFilePaths(file);

  return vscode.workspace.findFiles(
    arrayToGlob(matches.map((match) => match.path)),
    ""
  );
}

async function selectFile(files): Promise<vscode.Uri[]> {
  if (files.length <= 1) return files[0];

  const selected = await vscode.window.showQuickPick(files.map((f) => f.path));

  if (!selected) return;

  const selectedFile = files.find((f) => f.path === selected);

  const file = await selectedFile;
  return file;<commit_msg>feat: allow replace to replace multiple instances<commit_after>import * as vscode from "vscode";

const REGEX_SYMBOL = ":";

function stripRootPath(file: string): string {
  const rootPath = vscode.workspace.rootPath;

  return file.replace(rootPath + "/", "");
}

function currentFile(): string {
  const currentFile = vscode.window.activeTextEditor;

  if (currentFile === undefined) return;

  return stripRootPath(currentFile.document.fileName);
}

function arrayToGlob(matches): string {
  const glob = "{" + matches.join(",") + "}";

  return glob;
}

type Mapping = {
  from: string;
  to: string;
};

type Match = {
  path: string;
} & Mapping;

function generateFilePaths(filePath: string): Match[] {
  const mappings: Mapping[] = vscode.workspace
    .getConfiguration()
    .get("fileswitcher.mappings");

  const matches = [];

  mappings.forEach((mapping) => {
    const regexp = new RegExp(mapping["from"], "i");
    const match = regexp.exec(filePath);

    if (match === null) return;

    let newFilePath = mapping["to"];

    match.forEach((item, index) => {
      newFilePath = newFilePath.replace(
        new RegExp(REGEX_SYMBOL + index, "g"),
        item
      );
    });

    matches.push({ from: mapping.from, to: mapping.to, path: newFilePath });
  });

  return matches;
}

function findMatchingFiles(file: string): Thenable<vscode.Uri[]> {
  const matches = generateFilePaths(file);

  return vscode.workspace.findFiles(
    arrayToGlob(matches.map((match) => match.path)),
    ""
  );
}

async function selectFile(files): Promise<vscode.Uri[]> {
  if (files.length <= 1) return files[0];

  const selected = await vscode.window.showQuickPick(files.map((f) => f.path));

  if (!selected) return;

  const selectedFile = files.find((f) => f.path === selected);

  const file = await selectedFile;
  return file;
{'fraction_non_alphanumeric': 0.15226451792164492, 'fraction_numerical': 0.0011114198388441233, 'mean_word_length': 4.006954102920723, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 17, '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': '6669574', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1141, 'n_words': 266}