mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1515736 - [release 111] [breakpoints] convert pause points to a list (#7504). r=lsmyth
This commit is contained in:
parent
fdc75be920
commit
50a4e90f5f
@ -7,7 +7,7 @@
|
||||
import { getSourceFromId } from "../../selectors";
|
||||
import * as parser from "../../workers/parser";
|
||||
import { isGenerated } from "../../utils/source";
|
||||
import { mapPausePoints } from "../../utils/pause/pausePoints";
|
||||
import { convertToList } from "../../utils/pause/pausePoints";
|
||||
import { features } from "../../utils/prefs";
|
||||
import { getGeneratedLocation } from "../../utils/source-maps";
|
||||
|
||||
@ -28,20 +28,24 @@ function compressPausePoints(pausePoints) {
|
||||
}
|
||||
|
||||
async function mapLocations(pausePoints, state, source, sourceMaps) {
|
||||
const pausePointList = convertToList(pausePoints);
|
||||
const sourceId = source.id;
|
||||
return mapPausePoints(pausePoints, async ({ types, location }) => {
|
||||
const generatedLocation = await getGeneratedLocation(
|
||||
state,
|
||||
source,
|
||||
{
|
||||
...location,
|
||||
sourceId
|
||||
},
|
||||
sourceMaps
|
||||
);
|
||||
|
||||
return { types, location, generatedLocation };
|
||||
});
|
||||
return Promise.all(
|
||||
pausePointList.map(async ({ types, location }) => {
|
||||
const generatedLocation = await getGeneratedLocation(
|
||||
state,
|
||||
source,
|
||||
{
|
||||
...location,
|
||||
sourceId
|
||||
},
|
||||
sourceMaps
|
||||
);
|
||||
|
||||
return { types, location, generatedLocation };
|
||||
})
|
||||
);
|
||||
}
|
||||
export function setPausePoints(sourceId: SourceId) {
|
||||
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
|
||||
@ -56,6 +60,11 @@ export function setPausePoints(sourceId: SourceId) {
|
||||
|
||||
let pausePoints = await parser.getPausePoints(sourceId);
|
||||
|
||||
if (isGenerated(source)) {
|
||||
const compressed = compressPausePoints(pausePoints);
|
||||
await client.setPausePoints(sourceId, compressed);
|
||||
}
|
||||
|
||||
pausePoints = await mapLocations(
|
||||
pausePoints,
|
||||
getState(),
|
||||
@ -63,11 +72,6 @@ export function setPausePoints(sourceId: SourceId) {
|
||||
sourceMaps
|
||||
);
|
||||
|
||||
if (isGenerated(source)) {
|
||||
const compressed = compressPausePoints(pausePoints);
|
||||
await client.setPausePoints(sourceId, compressed);
|
||||
}
|
||||
|
||||
dispatch(
|
||||
({
|
||||
type: "SET_PAUSE_POINTS",
|
||||
|
@ -25,7 +25,7 @@ import type {
|
||||
BPClients
|
||||
} from "./types";
|
||||
|
||||
import type { PausePoints } from "../../workers/parser";
|
||||
import type { PausePointsMap } from "../../workers/parser";
|
||||
|
||||
import { makePendingLocationId } from "../../utils/breakpoint";
|
||||
|
||||
@ -361,7 +361,7 @@ function disablePrettyPrint(sourceId: SourceId): Promise<*> {
|
||||
return sourceClient.disablePrettyPrint();
|
||||
}
|
||||
|
||||
async function setPausePoints(sourceId: SourceId, pausePoints: PausePoints) {
|
||||
async function setPausePoints(sourceId: SourceId, pausePoints: PausePointsMap) {
|
||||
return sendPacket({ to: sourceId, type: "setPausePoints", pausePoints });
|
||||
}
|
||||
|
||||
|
@ -13,15 +13,10 @@ import * as I from "immutable";
|
||||
import makeRecord from "../utils/makeRecord";
|
||||
import { findEmptyLines } from "../utils/ast";
|
||||
|
||||
import type {
|
||||
AstLocation,
|
||||
SymbolDeclarations,
|
||||
PausePoints,
|
||||
PausePoint
|
||||
} from "../workers/parser";
|
||||
import type { AstLocation, SymbolDeclarations } from "../workers/parser";
|
||||
|
||||
import type { Map } from "immutable";
|
||||
import type { SourceLocation, Source } from "../types";
|
||||
import type { SourceLocation, Source, Position } from "../types";
|
||||
import type { Action, DonePromiseAction } from "../actions/types";
|
||||
import type { Record } from "../utils/makeRecord";
|
||||
|
||||
@ -36,7 +31,18 @@ export type SourceMetaDataType = {
|
||||
};
|
||||
|
||||
export type SourceMetaDataMap = Map<string, SourceMetaDataType>;
|
||||
export type PausePointsMap = Map<string, PausePoints>;
|
||||
|
||||
export type PausePoint = {
|
||||
location: Position,
|
||||
generatedLocation: SourceLocation,
|
||||
types: { break: boolean, step: boolean }
|
||||
};
|
||||
|
||||
export type PausePointsMap = {
|
||||
[line: string]: { [column: string]: PausePoint }
|
||||
};
|
||||
export type PausePoints = PausePoint[];
|
||||
export type PausePointsState = Map<string, PausePoint[]>;
|
||||
|
||||
export type Preview =
|
||||
| {| updating: true |}
|
||||
@ -56,7 +62,7 @@ export type ASTState = {
|
||||
outOfScopeLocations: ?Array<AstLocation>,
|
||||
inScopeLines: ?Array<Number>,
|
||||
preview: Preview,
|
||||
pausePoints: PausePointsMap,
|
||||
pausePoints: PausePointsState,
|
||||
sourceMetaData: SourceMetaDataMap
|
||||
};
|
||||
|
||||
@ -218,12 +224,35 @@ export function getPausePoint(
|
||||
return;
|
||||
}
|
||||
|
||||
const linePoints = pausePoints[String(line)];
|
||||
if (linePoints && column) {
|
||||
return linePoints[String(column)];
|
||||
for (const point of pausePoints) {
|
||||
const { location: pointLocation } = point;
|
||||
if (pointLocation.line == line && pointLocation.column == column) {
|
||||
return point;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getFirstPausePointLocation(
|
||||
state: OuterState,
|
||||
location: SourceLocation
|
||||
): SourceLocation {
|
||||
const { sourceId } = location;
|
||||
const pausePoints = getPausePoints(state, location.sourceId);
|
||||
if (!pausePoints) {
|
||||
return location;
|
||||
}
|
||||
|
||||
const pausesAtLine = pausePoints[location.line];
|
||||
if (pausesAtLine) {
|
||||
const values: PausePoint[] = (Object.values(pausesAtLine): any);
|
||||
const firstPausePoint = values.find(pausePoint => pausePoint.types.break);
|
||||
if (firstPausePoint) {
|
||||
return { ...firstPausePoint.location, sourceId };
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
export function hasPausePoints(state: OuterState, sourceId: string): boolean {
|
||||
const pausePoints = getPausePoints(state, sourceId);
|
||||
return !!pausePoints;
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
import { getSelectedSource } from "../reducers/sources";
|
||||
import { getPausePoints } from "../reducers/ast";
|
||||
import { convertToList } from "../utils/pause/pausePoints";
|
||||
|
||||
export function getVisiblePausePoints(state) {
|
||||
const source = getSelectedSource(state);
|
||||
@ -12,6 +11,5 @@ export function getVisiblePausePoints(state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const pausePoints = getPausePoints(state, source.id);
|
||||
return convertToList(pausePoints);
|
||||
return getPausePoints(state, source.id);
|
||||
}
|
||||
|
@ -5,18 +5,16 @@
|
||||
// @flow
|
||||
|
||||
import { xor, range } from "lodash";
|
||||
import { convertToList } from "./pause/pausePoints";
|
||||
|
||||
import type { SourceLocation, Position } from "../types";
|
||||
import type { Symbols } from "../reducers/ast";
|
||||
|
||||
import type {
|
||||
AstPosition,
|
||||
AstLocation,
|
||||
PausePoints,
|
||||
FunctionDeclaration,
|
||||
ClassDeclaration
|
||||
} from "../workers/parser";
|
||||
import type { PausePoints } from "../reducers/types";
|
||||
|
||||
export function findBestMatchExpression(symbols: Symbols, tokenPos: Position) {
|
||||
if (symbols.loading) {
|
||||
@ -51,9 +49,7 @@ export function findEmptyLines(
|
||||
return [];
|
||||
}
|
||||
|
||||
const pausePointsList = convertToList(pausePoints);
|
||||
|
||||
const breakpoints = pausePointsList.filter(point => point.types.break);
|
||||
const breakpoints = pausePoints.filter(point => point.types.break);
|
||||
const breakpointLines = breakpoints.map(point => point.location.line);
|
||||
|
||||
if (!sourceText || breakpointLines.length == 0) {
|
||||
|
@ -5,13 +5,7 @@
|
||||
// @flow
|
||||
import { reverse } from "lodash";
|
||||
|
||||
import type { PausePoints } from "../../workers/parser";
|
||||
import type { Position } from "../../types";
|
||||
|
||||
type PausePoint = {
|
||||
location: Position,
|
||||
types: { break: boolean, step: boolean }
|
||||
};
|
||||
import type { PausePoints, PausePointsMap } from "../../reducers/types";
|
||||
|
||||
function insertStrtAt(string, index, newString) {
|
||||
const start = string.slice(0, index);
|
||||
@ -19,7 +13,7 @@ function insertStrtAt(string, index, newString) {
|
||||
return `${start}${newString}${end}`;
|
||||
}
|
||||
|
||||
export function convertToList(pausePoints: PausePoints): PausePoint[] {
|
||||
export function convertToList(pausePoints: PausePointsMap): PausePoints {
|
||||
const list = [];
|
||||
for (const line in pausePoints) {
|
||||
for (const column in pausePoints[line]) {
|
||||
@ -30,7 +24,7 @@ export function convertToList(pausePoints: PausePoints): PausePoint[] {
|
||||
}
|
||||
|
||||
export function formatPausePoints(text: string, pausePoints: PausePoints) {
|
||||
const nodes = reverse(convertToList(pausePoints));
|
||||
const nodes = reverse(pausePoints);
|
||||
const lines = text.split("\n");
|
||||
nodes.forEach((node, index) => {
|
||||
const { line, column } = node.location;
|
||||
@ -41,22 +35,3 @@ export function formatPausePoints(text: string, pausePoints: PausePoints) {
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export async function mapPausePoints<T>(
|
||||
pausePoints: PausePoints,
|
||||
iteratee: PausePoint => T
|
||||
) {
|
||||
const results = await Promise.all(convertToList(pausePoints).map(iteratee));
|
||||
let index = 0;
|
||||
|
||||
const newPausePoints = {};
|
||||
for (const line in pausePoints) {
|
||||
const linePoints = pausePoints[line];
|
||||
const newLinePoints = (newPausePoints[line] = {});
|
||||
for (const column in linePoints) {
|
||||
newLinePoints[column] = results[index++];
|
||||
}
|
||||
}
|
||||
|
||||
return newPausePoints;
|
||||
}
|
||||
|
@ -7,10 +7,11 @@
|
||||
import { workerUtils } from "devtools-utils";
|
||||
const { WorkerDispatcher } = workerUtils;
|
||||
|
||||
import type { AstLocation, AstPosition, PausePoints } from "./types";
|
||||
import type { AstLocation, AstPosition } from "./types";
|
||||
import type { SourceLocation, Source, SourceId } from "../../types";
|
||||
import type { SourceScope } from "./getScopes/visitor";
|
||||
import type { SymbolDeclarations } from "./getSymbols";
|
||||
import type { PausePointsMap } from "../../reducers/types";
|
||||
|
||||
const dispatcher = new WorkerDispatcher();
|
||||
export const start = (url: string, win: any = window) =>
|
||||
@ -79,8 +80,9 @@ export const mapExpression = async (
|
||||
export const getFramework = async (sourceId: string): Promise<?string> =>
|
||||
dispatcher.invoke("getFramework", sourceId);
|
||||
|
||||
export const getPausePoints = async (sourceId: string): Promise<PausePoints> =>
|
||||
dispatcher.invoke("getPausePoints", sourceId);
|
||||
export const getPausePoints = async (
|
||||
sourceId: string
|
||||
): Promise<PausePointsMap> => dispatcher.invoke("getPausePoints", sourceId);
|
||||
|
||||
export type {
|
||||
SourceScope,
|
||||
@ -96,7 +98,7 @@ export type {
|
||||
AstLocation,
|
||||
AstPosition,
|
||||
PausePoint,
|
||||
PausePoints
|
||||
PausePointsMap
|
||||
} from "./types";
|
||||
|
||||
export type {
|
||||
|
Loading…
Reference in New Issue
Block a user