<commit_before>// @flow

import { selectSource, ensureParserHasSourceText } from "./sources";
import { PROMISE } from "../utils/redux/middleware/promise";

import {
  getPause,
  pausedInEval,
  getLoadedObject,
  getSource,
  isStepping,
  isPaused,
  getSelectedSource,
  isEvaluatingExpression
} from "../selectors";
import {
  updateFrameLocations,
  updateScopeBindings,
  getPausedPosition
} from "../utils/pause";
import { evaluateExpressions } from "./expressions";

import { addHiddenBreakpoint, removeBreakpoint } from "./breakpoints";
import { getHiddenBreakpointLocation } from "../reducers/breakpoints";
import * as parser from "../workers/parser";
import { features } from "../utils/prefs";

import type { Pause, Frame } from "../types";
import type { ThunkArgs } from "./types";

import { isGeneratedId } from "devtools-source-map";

type CommandType = string;

async function _getScopeBindings(
  { dispatch, getState, sourceMaps },
  generatedLocation,
  scopes
) {
  const { sourceId } = generatedLocation;
  const sourceRecord = getSource(getState(), sourceId);
  if (sourceRecord.get("isWasm")) {
    return scopes;
  }

  await dispatch(ensureParserHasSourceText(sourceId));

  return await updateScopeBindings(scopes, generatedLocation, sourceMaps);
}

/**
 * Redux actions for the pause state
 * @module actions/pause
 */

/**
 * Debugger has just resumed
 *
 * @memberof actions/pause
 * @static
 */
export function resumed() {
  return ({ dispatch, client, getState }: ThunkArgs) => {
    if (!isPaused(getState())) {
      return;
    }

    const wasPausedInEval = pausedInEval(getState());

    dispatch({
      type: "RESUME",
      value: undefined
    });

    if (!isStepping(getState()) && !wasPausedInEval) {
      dispatch(evaluateExpressions());
    }
  };
}

export function continueToHere(line: number) {
  return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
    const source = getSelectedSource(getState()).toJS();

    await dispatch(
      addHiddenBreakpoint({
        line,
        column: undefined,
        sourceId: source.id
      })
    );

    dispatch(command("resume"));
  };
}

/**
 * Debugger has just paused
 *
 * @param {object} pauseInfo
 * @memberof actions/pause
 * @static
 */
export function paused(pauseInfo: Pause) {
  return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
    let { frames, why, loadedObjects } = pauseInfo;

    frames = await updateFrameLocations(frames, sourceMaps);
    const frame = frames[0];

    const frameScopes = await client.getFrameScopes(frame);
    const scopes = !isGeneratedId(frame.location.sourceId)
      ? await _getScopeBindings(
          { dispatch, getState, sourceMaps },
          frame.generatedLocation,
          frameScopes
        )
      : frameScopes;

    dispatch({
      type: "PAUSED",
      pauseInfo: { why, frame, frames },
      frames: frames,
      scopes,
      selectedFrameId: frame.id,
      loadedObjects: loadedObjects || []
    });

    const hiddenBreakpointLocation = getHiddenBreakpointLocation(getState());
    if (hiddenBreakpointLocation) {
      dispatch(removeBreakpoint(hiddenBreakpointLocation));
    }

    if (!isEvaluatingExpression(getState())) {
      dispatch(evaluateExpressions());
    }

    const { line, column } = frame.location;
    dispatch(selectSource(frame.location.sourceId, { line, column }));
  };
}
<commit_msg>fix #4471 - expand the right sidebar on pausing at breakpoint<commit_after>// @flow

import { selectSource, ensureParserHasSourceText } from "./sources";
import { PROMISE } from "../utils/redux/middleware/promise";

import { togglePaneCollapse } from "./ui";
import {
  getPause,
  pausedInEval,
  getLoadedObject,
  getSource,
  isStepping,
  isPaused,
  getSelectedSource,
  isEvaluatingExpression
} from "../selectors";
import {
  updateFrameLocations,
  updateScopeBindings,
  getPausedPosition
} from "../utils/pause";
import { evaluateExpressions } from "./expressions";

import { addHiddenBreakpoint, removeBreakpoint } from "./breakpoints";
import { getHiddenBreakpointLocation } from "../reducers/breakpoints";
import * as parser from "../workers/parser";
import { features } from "../utils/prefs";

import type { Pause, Frame } from "../types";
import type { ThunkArgs } from "./types";

import { isGeneratedId } from "devtools-source-map";

type CommandType = string;

async function _getScopeBindings(
  { dispatch, getState, sourceMaps },
  generatedLocation,
  scopes
) {
  const { sourceId } = generatedLocation;
  const sourceRecord = getSource(getState(), sourceId);
  if (sourceRecord.get("isWasm")) {
    return scopes;
  }

  await dispatch(ensureParserHasSourceText(sourceId));

  return await updateScopeBindings(scopes, generatedLocation, sourceMaps);
}

/**
 * Redux actions for the pause state
 * @module actions/pause
 */

/**
 * Debugger has just resumed
 *
 * @memberof actions/pause
 * @static
 */
export function resumed() {
  return ({ dispatch, client, getState }: ThunkArgs) => {
    if (!isPaused(getState())) {
      return;
    }

    const wasPausedInEval = pausedInEval(getState());

    dispatch({
      type: "RESUME",
      value: undefined
    });

    if (!isStepping(getState()) && !wasPausedInEval) {
      dispatch(evaluateExpressions());
    }
  };
}

export function continueToHere(line: number) {
  return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
    const source = getSelectedSource(getState()).toJS();

    await dispatch(
      addHiddenBreakpoint({
        line,
        column: undefined,
        sourceId: source.id
      })
    );

    dispatch(command("resume"));
  };
}

/**
 * Debugger has just paused
 *
 * @param {object} pauseInfo
 * @memberof actions/pause
 * @static
 */
export function paused(pauseInfo: Pause) {
  return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
    let { frames, why, loadedObjects } = pauseInfo;

    frames = await updateFrameLocations(frames, sourceMaps);
    const frame = frames[0];

    const frameScopes = await client.getFrameScopes(frame);
    const scopes = !isGeneratedId(frame.location.sourceId)
      ? await _getScopeBindings(
          { dispatch, getState, sourceMaps },
          frame.generatedLocation,
          frameScopes
        )
      : frameScopes;

    dispatch({
      type: "PAUSED",
      pauseInfo: { why, frame, frames },
      frames: frames,
      scopes,
      selectedFrameId: frame.id,
      loadedObjects: loadedObjects || []
    });

    const hiddenBreakpointLocation = getHiddenBreakpointLocation(getState());
    if (hiddenBreakpointLocation) {
      dispatch(removeBreakpoint(hiddenBreakpointLocation));
    }

    if (!isEvaluatingExpression(getState())) {
      dispatch(evaluateExpressions());
    }

    const { line, column } = frame.location;
    dispatch(selectSource(frame.location.sourceId, { line, column }));

    dispatch(togglePaneCollapse("end", false));
  };
}

{'fraction_non_alphanumeric': 0.12378362907842015, 'fraction_numerical': 0.0008586147681740126, 'mean_word_length': 3.5590345727332027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6919329', 'n_tokens_mistral': 2074, 'n_tokens_neox': 2029, 'n_words': 485}