Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 0b4a946

Browse files
committed
Pause Points (#5537)
1 parent 9f5d10e commit 0b4a946

File tree

22 files changed

+313
-176
lines changed

22 files changed

+313
-176
lines changed

src/actions/ast.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
import { setInScopeLines } from "./ast/setInScopeLines";
1515
import {
1616
getSymbols,
17-
getEmptyLines,
1817
findOutOfScopeLocations,
19-
getFramework
18+
getFramework,
19+
getPausePoints
2020
} from "../workers/parser";
2121
import { PROMISE } from "./utils/middleware/promise";
2222

@@ -64,30 +64,8 @@ export function setSymbols(sourceId: SourceId) {
6464
[PROMISE]: getSymbols(source.id)
6565
});
6666

67-
dispatch(setEmptyLines(sourceId));
68-
dispatch(setSourceMetaData(sourceId));
69-
};
70-
}
71-
72-
export function setEmptyLines(sourceId: SourceId) {
73-
return async ({ dispatch, getState }: ThunkArgs) => {
74-
const sourceRecord = getSource(getState(), sourceId);
75-
if (!sourceRecord) {
76-
return;
77-
}
78-
79-
const source = sourceRecord.toJS();
80-
if (!source.text || source.isWasm) {
81-
return;
82-
}
83-
84-
const emptyLines = await getEmptyLines(source.id);
85-
86-
dispatch({
87-
type: "SET_EMPTY_LINES",
88-
source,
89-
emptyLines
90-
});
67+
await dispatch(setPausePoints(sourceId));
68+
await dispatch(setSourceMetaData(sourceId));
9169
};
9270
}
9371

@@ -113,3 +91,24 @@ export function setOutOfScopeLocations() {
11391
dispatch(setInScopeLines());
11492
};
11593
}
94+
95+
export function setPausePoints(sourceId: SourceId) {
96+
return async ({ dispatch, getState }: ThunkArgs) => {
97+
const sourceRecord = getSource(getState(), sourceId);
98+
if (!sourceRecord) {
99+
return;
100+
}
101+
102+
const source = sourceRecord.toJS();
103+
if (!source.text || source.isWasm) {
104+
return;
105+
}
106+
107+
const pausePoints = await getPausePoints(source.id);
108+
dispatch({
109+
type: "SET_PAUSE_POINTS",
110+
source,
111+
pausePoints
112+
});
113+
};
114+
}

src/actions/sources/prettyPrint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import assert from "../../utils/assert";
88
import { remapBreakpoints } from "../breakpoints";
99

10-
import { setEmptyLines, setSymbols } from "../ast";
10+
import { setPausePoints, setSymbols } from "../ast";
1111
import { prettyPrint } from "../../workers/pretty-print";
1212
import { setSource } from "../../workers/parser";
1313
import { getPrettySourceURL, isLoaded } from "../../utils/source";
@@ -103,7 +103,7 @@ export function togglePrettyPrint(sourceId: string) {
103103

104104
await dispatch(remapBreakpoints(sourceId));
105105
await dispatch(mapFrames());
106-
await dispatch(setEmptyLines(newPrettySource.id));
106+
await dispatch(setPausePoints(newPrettySource.id));
107107
await dispatch(setSymbols(newPrettySource.id));
108108

109109
return dispatch(

src/actions/tests/__snapshots__/ast.spec.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ Array [
4040
]
4141
`;
4242

43-
exports[`ast setEmptyLines scopes 1`] = `
43+
exports[`ast setPausePoints scopes 1`] = `
4444
Array [
4545
1,
4646
2,
4747
7,
48-
12,
4948
]
5049
`;
5150

src/actions/tests/ast.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ const evaluationResult = {
5555
};
5656

5757
describe("ast", () => {
58-
describe("setEmptyLines", () => {
58+
describe("setPausePoints", () => {
5959
it("scopes", async () => {
6060
const store = createStore(threadClient);
6161
const { dispatch, getState } = store;
6262
const source = makeSource("scopes.js");
6363
await dispatch(actions.newSource(source));
6464
await dispatch(actions.loadSourceText(I.Map({ id: "scopes.js" })));
65-
await dispatch(actions.setEmptyLines("scopes.js"));
65+
await dispatch(actions.setPausePoints("scopes.js"));
6666
await waitForState(store, state => {
6767
const lines = getEmptyLines(state, source);
6868
return lines && lines.length > 0;

src/actions/types.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ import type {
1717
} from "../types";
1818

1919
import type { State } from "../reducers/types";
20+
2021
import type {
2122
ActiveSearchType,
2223
OrientationType,
2324
SelectedPrimaryPaneTabType
2425
} from "../reducers/ui";
25-
import type { MatchedLocations } from "../reducers/file-search";
2626

27-
import type { AstLocation, SymbolDeclaration } from "../workers/parser";
27+
import type { MatchedLocations } from "../reducers/file-search";
28+
import type {
29+
SymbolDeclaration,
30+
AstLocation,
31+
PausePoint
32+
} from "../workers/parser";
2833
import type { SourceMetaDataType } from "../reducers/ast.js";
2934

3035
/**
@@ -318,6 +323,11 @@ type ASTAction =
318323
source: Source,
319324
value: SymbolDeclaration[]
320325
}
326+
| {
327+
type: "SET_PAUSE_POINTS",
328+
source: Source,
329+
pausePoints: PausePoint[]
330+
}
321331
| {
322332
type: "SET_EMPTY_LINES",
323333
source: Source,

src/actions/utils/middleware/log.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isTesting } from "devtools-config";
77

88
const blacklist = [
99
"SET_POPUP_OBJECT_PROPERTIES",
10+
"SET_PAUSE_POINTS",
1011
"SET_SYMBOLS",
1112
"OUT_OF_SCOPE_LOCATIONS",
1213
"MAP_SCOPES",

src/components/Editor/GutterMenu.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class GutterContextMenuComponent extends Component {
143143
bp => bp.location.line === line
144144
);
145145

146-
if (props.emptyLines.includes(line)) {
146+
if (props.emptyLines && props.emptyLines.includes(line)) {
147147
return;
148148
}
149149

@@ -164,9 +164,7 @@ export default connect(
164164
breakpoints: getVisibleBreakpoints(state),
165165
isPaused: getIsPaused(state),
166166
contextMenu: getContextMenu(state),
167-
emptyLines: selectedSource
168-
? getEmptyLines(state, selectedSource.toJS())
169-
: []
167+
emptyLines: getEmptyLines(state, selectedSource.toJS())
170168
};
171169
},
172170
dispatch => bindActionCreators(actions, dispatch)

src/reducers/ast.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import * as I from "immutable";
1313

1414
import makeRecord from "../utils/makeRecord";
15+
import { findEmptyLines } from "../utils/ast";
16+
1517
import type { SymbolDeclarations, AstLocation } from "../workers/parser/types";
1618

1719
import type { Map } from "immutable";
@@ -29,6 +31,7 @@ export type SourceMetaDataType = {
2931
};
3032

3133
export type SourceMetaDataMap = Map<string, SourceMetaDataType>;
34+
export type PausePointsMap = Map<string, any>;
3235

3336
export type Preview =
3437
| {| updating: true |}
@@ -49,6 +52,7 @@ export type ASTState = {
4952
outOfScopeLocations: ?Array<AstLocation>,
5053
inScopeLines: ?Array<Number>,
5154
preview: Preview,
55+
pausePoints: PausePointsMap,
5256
sourceMetaData: SourceMetaDataMap
5357
};
5458

@@ -60,6 +64,7 @@ export function initialASTState() {
6064
outOfScopeLocations: null,
6165
inScopeLines: null,
6266
preview: null,
67+
pausePoints: I.Map(),
6368
sourceMetaData: I.Map()
6469
}: ASTState)
6570
)();
@@ -77,9 +82,14 @@ function update(
7782
}
7883
return state.setIn(["symbols", source.id], action.value);
7984
}
80-
case "SET_EMPTY_LINES": {
81-
const { source, emptyLines } = action;
82-
return state.setIn(["emptyLines", source.id], emptyLines);
85+
86+
case "SET_PAUSE_POINTS": {
87+
const { source, pausePoints } = action;
88+
const emptyLines = findEmptyLines(source, pausePoints);
89+
90+
return state
91+
.setIn(["pausePoints", source.id], pausePoints)
92+
.setIn(["emptyLines", source.id], emptyLines);
8393
}
8494

8595
case "OUT_OF_SCOPE_LOCATIONS": {
@@ -170,15 +180,23 @@ export function isEmptyLineInSource(
170180
selectedSource: Source
171181
) {
172182
const emptyLines = getEmptyLines(state, selectedSource);
173-
return emptyLines.includes(line);
183+
return emptyLines && emptyLines.includes(line);
174184
}
175185

176186
export function getEmptyLines(state: OuterState, source: Source) {
177187
if (!source) {
178-
return [];
188+
return null;
189+
}
190+
191+
return state.ast.getIn(["emptyLines", source.id]);
192+
}
193+
194+
export function getPausePoints(state: OuterState, source: Source) {
195+
if (!source) {
196+
return null;
179197
}
180198

181-
return state.ast.getIn(["emptyLines", source.id]) || [];
199+
return state.ast.getIn(["pausePoints", source.id]);
182200
}
183201

184202
export function getOutOfScopeLocations(state: OuterState) {

src/test/mochitest/browser_dbg-breakpoints-cond.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function setConditionalBreakpoint(dbg, index, condition) {
4949
add_task(async function() {
5050
const dbg = await initDebugger("doc-scripts.html");
5151
await selectSource(dbg, "simple2");
52+
await waitForSelectedSource(dbg, "simple2");
5253

5354
await setConditionalBreakpoint(dbg, 5, "1");
5455
await waitForDispatch(dbg, "ADD_BREAKPOINT");

src/utils/ast.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
// @flow
66

7-
import type { Position } from "../types";
8-
import type { SymbolDeclarations } from "../workers/parser";
7+
import { without, range } from "lodash";
8+
9+
import type { Source, Position } from "../types";
10+
import type { PausePoint, SymbolDeclarations } from "../workers/parser";
911

1012
export function findBestMatchExpression(
1113
symbols: SymbolDeclarations,
@@ -25,5 +27,24 @@ export function findBestMatchExpression(
2527
}
2628

2729
return found;
28-
}, {});
30+
}, null);
31+
}
32+
33+
export function findEmptyLines(
34+
selectedSource: Source,
35+
pausePoints: PausePoint[]
36+
) {
37+
if (!pausePoints || !selectedSource) {
38+
return [];
39+
}
40+
41+
const breakpoints = pausePoints.filter(point => point.types.breakpoint);
42+
const breakpointLines = breakpoints.map(point => point.location.line);
43+
44+
if (!selectedSource.text) {
45+
return [];
46+
}
47+
const lineCount = selectedSource.text.split("\n").length;
48+
const sourceLines = range(1, lineCount);
49+
return without(sourceLines, ...breakpointLines);
2950
}

0 commit comments

Comments
 (0)