Skip to content

Commit 5c7cdfe

Browse files
committed
Revert "Replace ScriptPicker with ProgramExplorer on DebuggerScreen (flutter#3227)" and associated follow-on PRs
1 parent 1a0a0fa commit 5c7cdfe

29 files changed

+323
-1587
lines changed

packages/devtools_app/lib/src/common_widgets.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ class AreaPaneHeader extends StatelessWidget implements PreferredSizeWidget {
676676
this.needsLeftBorder = false,
677677
this.leftActions = const [],
678678
this.rightActions = const [],
679-
this.leftPadding = defaultSpacing,
680679
this.rightPadding = densePadding,
681680
this.tall = false,
682681
}) : super(key: key);
@@ -688,7 +687,6 @@ class AreaPaneHeader extends StatelessWidget implements PreferredSizeWidget {
688687
final bool needsLeftBorder;
689688
final List<Widget> leftActions;
690689
final List<Widget> rightActions;
691-
final double leftPadding;
692690
final double rightPadding;
693691
final bool tall;
694692

@@ -707,7 +705,7 @@ class AreaPaneHeader extends StatelessWidget implements PreferredSizeWidget {
707705
),
708706
color: theme.titleSolidBackgroundColor,
709707
),
710-
padding: EdgeInsets.only(left: leftPadding, right: rightPadding),
708+
padding: EdgeInsets.only(left: defaultSpacing, right: rightPadding),
711709
alignment: Alignment.centerLeft,
712710
child: Row(
713711
children: [

packages/devtools_app/lib/src/debugger/codeview.dart

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class CodeView extends StatefulWidget {
4242
const CodeView({
4343
Key key,
4444
this.controller,
45-
this.initialPosition,
4645
this.scriptRef,
4746
this.parsedScript,
4847
this.onSelected,
@@ -58,7 +57,6 @@ class CodeView extends StatefulWidget {
5857
static double get assumedCharacterWidth => scaleByFontFactor(16.0);
5958

6059
final DebuggerController controller;
61-
final ScriptLocation initialPosition;
6260
final ScriptRef scriptRef;
6361
final ParsedScript parsedScript;
6462

@@ -91,15 +89,6 @@ class _CodeViewState extends State<CodeView>
9189
textController = verticalController.addAndGet();
9290
horizontalController = ScrollController();
9391

94-
if (widget.initialPosition != null) {
95-
final location = widget.initialPosition.location;
96-
// Lines are 1-indexed. Scrolling to line 1 required a scroll position of
97-
// 0.
98-
final lineIndex = location.line - 1;
99-
final scrollPosition = lineIndex * CodeView.rowHeight;
100-
verticalController.jumpTo(scrollPosition);
101-
}
102-
10392
addAutoDisposeListener(
10493
widget.controller.scriptLocation,
10594
_handleScriptLocationChanged,
@@ -135,29 +124,18 @@ class _CodeViewState extends State<CodeView>
135124
}
136125

137126
void _updateScrollPosition({bool animate = true}) {
138-
if (widget.controller.scriptLocation.value?.scriptRef?.uri !=
139-
scriptRef?.uri) {
127+
if (widget.controller.scriptLocation.value?.scriptRef != scriptRef) {
140128
return;
141129
}
142130

143-
if (!verticalController.hasAttachedControllers) {
144-
// TODO(devoncarew): I'm uncertain why this occurs.
145-
log('LinkedScrollControllerGroup has no attached controllers');
131+
final location = widget.controller.scriptLocation.value?.location;
132+
if (location?.line == null) {
146133
return;
147134
}
148135

149-
final location = widget.controller.scriptLocation.value?.location;
150-
if (location?.line == null) {
151-
// Default to scrolling to the top of the script.
152-
if (animate) {
153-
verticalController.animateTo(
154-
0,
155-
duration: longDuration,
156-
curve: defaultCurve,
157-
);
158-
} else {
159-
verticalController.jumpTo(0);
160-
}
136+
if (!verticalController.hasAttachedControllers) {
137+
// TODO(devoncarew): I'm uncertain why this occurs.
138+
log('LinkedScrollControllerGroup has no attached controllers');
161139
return;
162140
}
163141

@@ -167,11 +145,10 @@ class _CodeViewState extends State<CodeView>
167145
// TODO(devoncarew): Adjust this so we don't scroll if we're already in the
168146
// middle third of the screen.
169147
if (parsedScript.lineCount * CodeView.rowHeight > extent) {
148+
// Scroll to the middle of the screen.
170149
final lineIndex = location.line - 1;
171-
final scrollPosition = lineIndex * CodeView.rowHeight -
172-
(widget.controller.shouldCenterScrollLocation
173-
? ((extent - CodeView.rowHeight) / 2)
174-
: 0);
150+
final scrollPosition =
151+
lineIndex * CodeView.rowHeight - (extent - CodeView.rowHeight) / 2;
175152
if (animate) {
176153
verticalController.animateTo(
177154
scrollPosition,
@@ -663,7 +640,7 @@ class _LinesState extends State<Lines> with AutoDisposeMixin {
663640

664641
if (isOutOfViewTop || isOutOfViewBottom) {
665642
// Scroll this search token to the middle of the view.
666-
final targetOffset = math.max<double>(
643+
final targetOffset = math.max(
667644
activeSearch.position.line * CodeView.rowHeight - widget.height / 2,
668645
0.0,
669646
);

packages/devtools_app/lib/src/debugger/controls.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import '../common_widgets.dart';
1212
import '../theme.dart';
1313
import '../ui/label.dart';
1414
import 'debugger_controller.dart';
15+
import 'scripts.dart';
1516

1617
class DebuggingControls extends StatefulWidget {
1718
const DebuggingControls({Key key}) : super(key: key);
@@ -117,14 +118,13 @@ class _DebuggingControlsState extends State<DebuggingControls>
117118

118119
Widget _librariesButton() {
119120
return ValueListenableBuilder(
120-
valueListenable: controller.fileExplorerVisible,
121+
valueListenable: controller.librariesVisible,
121122
builder: (context, visible, _) {
122-
const libraryIcon = Icons.insert_chart;
123123
return RoundedOutlinedBorder(
124124
child: Container(
125125
color: visible ? Theme.of(context).highlightColor : null,
126126
child: DebuggerButton(
127-
title: 'File Explorer',
127+
title: 'Libraries',
128128
icon: libraryIcon,
129129
onPressed: controller.toggleLibrariesVisible,
130130
),

packages/devtools_app/lib/src/debugger/debugger_controller.dart

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import '../ui/search.dart';
2020
import '../utils.dart';
2121
import '../vm_service_wrapper.dart';
2222
import 'debugger_model.dart';
23-
import 'program_explorer_controller.dart';
2423
import 'syntax_highlighter.dart';
2524

2625
// TODO(devoncarew): Add some delayed resume value notifiers (to be used to
@@ -41,7 +40,6 @@ class DebuggerController extends DisposableController
4140
_showScriptLocation(ScriptLocation(scriptsHistory.current.value));
4241
};
4342
scriptsHistory.current.addListener(_scriptHistoryListener);
44-
programExplorerController.initialize(currentScriptRef.value);
4543

4644
if (_service != null) {
4745
initialize();
@@ -122,8 +120,6 @@ class DebuggerController extends DisposableController
122120
Map<LibraryRef, Future<Set<String>>>
123121
libraryMemberAndImportsAutocompleteCache = {};
124122

125-
final programExplorerController = ProgramExplorerController();
126-
127123
final ScriptCache _scriptCache = ScriptCache();
128124

129125
final ScriptsHistory scriptsHistory = ScriptsHistory();
@@ -165,11 +161,8 @@ class DebuggerController extends DisposableController
165161
final _showFileOpener = ValueNotifier<bool>(false);
166162

167163
/// Jump to the given ScriptRef and optional SourcePosition.
168-
void showScriptLocation(
169-
ScriptLocation scriptLocation, {
170-
bool centerLocation = true,
171-
}) {
172-
_showScriptLocation(scriptLocation, centerLocation: centerLocation);
164+
void showScriptLocation(ScriptLocation scriptLocation) {
165+
_showScriptLocation(scriptLocation);
173166

174167
// Update the scripts history (and make sure we don't react to the
175168
// subsequent event).
@@ -180,11 +173,7 @@ class DebuggerController extends DisposableController
180173

181174
/// Show the given script location (without updating the script navigation
182175
/// history).
183-
void _showScriptLocation(
184-
ScriptLocation scriptLocation, {
185-
bool centerLocation = true,
186-
}) {
187-
_shouldCenterScrollLocation = centerLocation;
176+
void _showScriptLocation(ScriptLocation scriptLocation) {
188177
_currentScriptRef.value = scriptLocation?.scriptRef;
189178

190179
_parseCurrentScript();
@@ -193,8 +182,6 @@ class DebuggerController extends DisposableController
193182
// set to null to ensure that happens.
194183
_scriptLocation.value = null;
195184
_scriptLocation.value = scriptLocation;
196-
197-
programExplorerController.selectScriptNode(scriptLocation.scriptRef);
198185
}
199186

200187
Future<Script> getScriptForRef(ScriptRef ref) async {
@@ -295,9 +282,6 @@ class DebuggerController extends DisposableController
295282
/// Return the sorted list of ScriptRefs active in the current isolate.
296283
ValueListenable<List<ScriptRef>> get sortedScripts => _sortedScripts;
297284

298-
bool get shouldCenterScrollLocation => _shouldCenterScrollLocation;
299-
bool _shouldCenterScrollLocation = true;
300-
301285
final _breakpoints = ValueNotifier<List<Breakpoint>>([]);
302286

303287
ValueListenable<List<Breakpoint>> get breakpoints => _breakpoints;
@@ -320,7 +304,7 @@ class DebuggerController extends DisposableController
320304

321305
final _librariesVisible = ValueNotifier(false);
322306

323-
ValueListenable<bool> get fileExplorerVisible => _librariesVisible;
307+
ValueListenable<bool> get librariesVisible => _librariesVisible;
324308

325309
/// Make the 'Libraries' view on the right-hand side of the screen visible or
326310
/// hidden.
@@ -624,6 +608,7 @@ class DebuggerController extends DisposableController
624608

625609
void _handleIsolateEvent(Event event) {
626610
if (event.isolate.id != isolateRef?.id) return;
611+
627612
switch (event.kind) {
628613
case EventKind.kIsolateReload:
629614
_updateAfterIsolateReload(event);
@@ -878,12 +863,25 @@ class DebuggerController extends DisposableController
878863
_populateScriptAndShowLocation(mainScriptRef);
879864
}
880865

866+
SourcePosition calculatePosition(Script script, int tokenPos) {
867+
final List<List<int>> table = script.tokenPosTable;
868+
if (table == null) {
869+
return null;
870+
}
871+
872+
return SourcePosition(
873+
line: script.getLineNumberFromTokenPos(tokenPos),
874+
column: script.getColumnNumberFromTokenPos(tokenPos),
875+
tokenPos: tokenPos,
876+
);
877+
}
878+
881879
Future<BreakpointAndSourcePosition> _createBreakpointWithLocation(
882880
Breakpoint breakpoint) async {
883881
if (breakpoint.resolved) {
884882
final bp = BreakpointAndSourcePosition.create(breakpoint);
885883
return getScript(bp.scriptRef).then((Script script) {
886-
final pos = SourcePosition.calculatePosition(script, bp.tokenPos);
884+
final pos = calculatePosition(script, bp.tokenPos);
887885
return BreakpointAndSourcePosition.create(breakpoint, pos);
888886
});
889887
} else {
@@ -900,8 +898,7 @@ class DebuggerController extends DisposableController
900898
}
901899

902900
final script = await getScript(location.script);
903-
final position =
904-
SourcePosition.calculatePosition(script, location.tokenPos);
901+
final position = calculatePosition(script, location.tokenPos);
905902
return StackFrameAndSourcePosition(frame, position: position);
906903
}
907904

@@ -1006,7 +1003,7 @@ class DebuggerController extends DisposableController
10061003
for (SourceReportRange range in report.ranges) {
10071004
if (range.possibleBreakpoints != null) {
10081005
for (int tokenPos in range.possibleBreakpoints) {
1009-
positions.add(SourcePosition.calculatePosition(script, tokenPos));
1006+
positions.add(calculatePosition(script, tokenPos));
10101007
}
10111008
}
10121009
}

packages/devtools_app/lib/src/debugger/debugger_model.dart

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,10 @@ class ScriptLocation {
9494
String toString() => '${scriptRef.uri} $location';
9595
}
9696

97+
/// A line, column, and an optional tokenPos.
9798
class SourcePosition {
98-
const SourcePosition({
99-
@required this.line,
100-
@required this.column,
101-
this.file,
102-
this.tokenPos,
103-
});
104-
105-
factory SourcePosition.calculatePosition(Script script, int tokenPos) {
106-
if (script.tokenPosTable == null) {
107-
return null;
108-
}
109-
110-
return SourcePosition(
111-
line: script.getLineNumberFromTokenPos(tokenPos),
112-
column: script.getColumnNumberFromTokenPos(tokenPos),
113-
tokenPos: tokenPos,
114-
);
115-
}
99+
SourcePosition({@required this.line, @required this.column, this.tokenPos});
116100

117-
final String file;
118101
final int line;
119102
final int column;
120103
final int tokenPos;
@@ -530,9 +513,7 @@ List<Variable> _createVariablesForAssociations(
530513
isolateRef: isolateRef,
531514
);
532515
variables.add(
533-
Variable.text('[Entry $i]')
534-
..addChild(key)
535-
..addChild(value),
516+
Variable.text('[Entry $i]')..addChild(key)..addChild(value),
536517
);
537518
}
538519
return variables;

packages/devtools_app/lib/src/debugger/debugger_screen.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import 'controls.dart';
2626
import 'debugger_controller.dart';
2727
import 'debugger_model.dart';
2828
import 'key_sets.dart';
29-
import 'program_explorer.dart';
29+
import 'scripts.dart';
3030
import 'variables.dart';
3131

3232
class DebuggerScreen extends Screen {
@@ -102,10 +102,7 @@ class DebuggerScreenBodyState extends State<DebuggerScreenBody>
102102

103103
void _onLocationSelected(ScriptLocation location) {
104104
if (location != null) {
105-
controller.showScriptLocation(
106-
location,
107-
centerLocation: location.location == null,
108-
);
105+
controller.showScriptLocation(location);
109106
}
110107
}
111108

@@ -140,7 +137,7 @@ class DebuggerScreenBodyState extends State<DebuggerScreenBody>
140137
);
141138

142139
final codeArea = ValueListenableBuilder(
143-
valueListenable: controller.fileExplorerVisible,
140+
valueListenable: controller.librariesVisible,
144141
builder: (context, visible, _) {
145142
if (visible) {
146143
// TODO(devoncarew): Animate this opening and closing.
@@ -149,10 +146,17 @@ class DebuggerScreenBodyState extends State<DebuggerScreenBody>
149146
initialFractions: const [0.70, 0.30],
150147
children: [
151148
codeView,
152-
ProgramExplorer(
153-
debugController: controller,
154-
onSelected: _onLocationSelected,
155-
)
149+
ValueListenableBuilder(
150+
valueListenable: controller.sortedScripts,
151+
builder: (context, scripts, _) {
152+
return ScriptPicker(
153+
key: DebuggerScreenBody.scriptViewKey,
154+
controller: controller,
155+
scripts: scripts,
156+
onSelected: _onLocationSelected,
157+
);
158+
},
159+
),
156160
],
157161
);
158162
} else {
@@ -389,7 +393,7 @@ class _DebuggerStatusState extends State<DebuggerStatus> with AutoDisposeMixin {
389393
final fileName = ' at ' + frame.location.script.uri.split('/').last;
390394
final script = await widget.controller.getScript(frame.location.script);
391395
final pos =
392-
SourcePosition.calculatePosition(script, frame.location.tokenPos);
396+
widget.controller.calculatePosition(script, frame.location.tokenPos);
393397

394398
return 'paused$reason$fileName $pos';
395399
}

0 commit comments

Comments
 (0)