<commit_before>import type { Argument, InputOr, RegisterOr } from ".";
import { commands as apiCommands, run as apiRun, command, compileFunction, Context, findMenu, keypressForRegister, Menu, notifyPromptActionRequested, prompt, promptNumber, runIsEnabled, showLockedMenu, showMenu, showMenuAfterDelay, validateMenu } from "../api";
import type { Extension } from "../state/extension";
import type { Register } from "../state/registers";
import { ArgumentError, CancellationError, InputError } from "../utils/errors";

/**
 * Miscellaneous commands that don't deserve their own category.
 *
 * By default, Dance also exports the following keybindings for existing
 * commands:
 *
 * | Keybinding     | Command                                      |
 * | -------------- | -------------------------------------------- |
 * | `s-;` (normal) | `["workbench.action.showCommands", { ... }]` |
 */
declare module "./misc";

/**
 * Cancel Dance operation.
 *
 * @keys `escape` (normal, !recording, "!markersNavigationVisible"), `escape` (input)
 */
export function cancel(extension: Extension) {
  // Calling a new command resets pending operations, so we don't need to do
  // anything special here.
  extension.cancelLastOperation(CancellationError.Reason.PressedEscape);
}

/**
 * Ignore key.
 */
export function ignore() {
  // Used to intercept and ignore key presses in a given mode.
}

const runHistory: string[] = [];

/**
 * Run code.
 *
 * There are two ways to invoke this command. The first one is to provide an
 * `code` string argument. This code must be a valid JavaScript string, and will
 * be executed with full access to the [Dance API](../api/README.md). For
 * instance,
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "code": "Selections.set(Selections.filter(text => text.includes('foo')))",
 *   },
 * },
 * ```
 *
 * If no argument is provided, a prompt will be shown asking for an input.
 * Furthermore, an array of strings can be passed to make longer functions
 * easier to read:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "code": [
 *       "for (const selection of Selections.current) {",
 *       "  console.log(text(selection));",
 *       "}",
 *     ],
 *   },
 * },
 * ```
 *
 * The second way to use this command is with the `commands` argument. This
 * argument must be an array of "command-like" values. The simplest
 * "command-like" value is a string corresponding to the command itself:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       "dance.modes.set.normal",
 *     ],
 *   },
 * },
 * ```
 *
 * But arguments can also be provided by passing an array:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       ["dance.modes.set", { "mode": "normal" }],
 *     ],
 *   },
 * },
 * ```
 *
 * Or by passing an object, like regular VS Code key bindings:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       {
 *         "command": "dance.modes.set",
 *         "args": { "mode": "normal" },
 *       },
 *     ],
 *   },
 * },
 * ```
 *
 * These values can be mixed:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       ["dance.selections.saveText", { "register": "^" }],
 *       {
 *         "command": "dance.modes.set",
 *         "args": { "mode": "normal" },
 *       },
 *       "hideSuggestWidget",
 *     ],
 *   },
 * },
 * ```
 *
 * If both `code` and `commands` are given, Dance will use `code` if arbitrary
 * code execution is enabled, or `commands` otherwise.
 */
export async function run(
  _: Context,
  argument: { code?: string | readonly string[] },
  codeOr: InputOr<"code", string | readonly string[]>,

  count: number,
  repetitions: number,
  register: RegisterOr<"null">,

  commands?: Argument<command.Any[]>,
) {
  if (Array.isArray(commands)) {
    if (typeof argument["code"] === "string" && runIsEnabled()) {
      // Prefer "code" to the "commands" array.
    } else {
      return apiCommands(...commands);<commit_msg>commands: fix argument not being properly passed to .run<commit_after>import type { Argument, InputOr, RegisterOr } from ".";
import { run as apiRun, buildCommands, command, compileFunction, Context, findMenu, keypressForRegister, Menu, notifyPromptActionRequested, prompt, promptNumber, runIsEnabled, showLockedMenu, showMenu, showMenuAfterDelay, validateMenu } from "../api";
import type { Extension } from "../state/extension";
import type { Register } from "../state/registers";
import { ArgumentError, CancellationError, InputError } from "../utils/errors";

/**
 * Miscellaneous commands that don't deserve their own category.
 *
 * By default, Dance also exports the following keybindings for existing
 * commands:
 *
 * | Keybinding     | Command                                      |
 * | -------------- | -------------------------------------------- |
 * | `s-;` (normal) | `["workbench.action.showCommands", { ... }]` |
 */
declare module "./misc";

/**
 * Cancel Dance operation.
 *
 * @keys `escape` (normal, !recording, "!markersNavigationVisible"), `escape` (input)
 */
export function cancel(extension: Extension) {
  // Calling a new command resets pending operations, so we don't need to do
  // anything special here.
  extension.cancelLastOperation(CancellationError.Reason.PressedEscape);
}

/**
 * Ignore key.
 */
export function ignore() {
  // Used to intercept and ignore key presses in a given mode.
}

const runHistory: string[] = [];

/**
 * Run code.
 *
 * There are two ways to invoke this command. The first one is to provide an
 * `code` string argument. This code must be a valid JavaScript string, and will
 * be executed with full access to the [Dance API](../api/README.md). For
 * instance,
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "code": "Selections.set(Selections.filter(text => text.includes('foo')))",
 *   },
 * },
 * ```
 *
 * If no argument is provided, a prompt will be shown asking for an input.
 * Furthermore, an array of strings can be passed to make longer functions
 * easier to read:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "code": [
 *       "for (const selection of Selections.current) {",
 *       "  console.log(text(selection));",
 *       "}",
 *     ],
 *   },
 * },
 * ```
 *
 * The second way to use this command is with the `commands` argument. This
 * argument must be an array of "command-like" values. The simplest
 * "command-like" value is a string corresponding to the command itself:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       "dance.modes.set.normal",
 *     ],
 *   },
 * },
 * ```
 *
 * But arguments can also be provided by passing an array:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       ["dance.modes.set", { "mode": "normal" }],
 *     ],
 *   },
 * },
 * ```
 *
 * Or by passing an object, like regular VS Code key bindings:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       {
 *         "command": "dance.modes.set",
 *         "args": { "mode": "normal" },
 *       },
 *     ],
 *   },
 * },
 * ```
 *
 * These values can be mixed:
 *
 * ```json
 * {
 *   "command": "dance.run",
 *   "args": {
 *     "commands": [
 *       ["dance.selections.saveText", { "register": "^" }],
 *       {
 *         "command": "dance.modes.set",
 *         "args": { "mode": "normal" },
 *       },
 *       "hideSuggestWidget",
 *     ],
 *   },
 * },
 * ```
 *
 * If both `code` and `commands` are given, Dance will use `code` if arbitrary
 * code execution is enabled, or `commands` otherwise.
 */
export async function run(
  _: Context,
  argument: { code?: string | readonly string[] },
  codeOr: InputOr<"code", string | readonly string[]>,

  count: number,
  repetitions: number,
  register: RegisterOr<"null">,

  commands?: Argument<command.Any[]>,
) {
  if (Array.isArray(commands)) {
    if (typeof argument["code"] === "string" && runIsEnabled()) {
      // Prefer "code" to the "commands" array.
    } else {
      return buildCommands(commands, _.extension)(argument, _);
{'fraction_non_alphanumeric': 0.18223732103858287, 'fraction_numerical': 0.0, 'mean_word_length': 2.670080142475512, 'pattern_counts': {'":': 52, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1417763', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2524, 'n_words': 736}