Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Side by Side Diff: lib/src/script.dart

Issue 1929063002: pkg/vm_service_client: add getSourceReport to VMServiceReference (Closed) Base URL: https://github.com/dart-lang/vm_service_client.git@master
Patch Set: oops Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:math' as math; 6 import 'dart:math' as math;
7 7
8 import 'package:json_rpc_2/json_rpc_2.dart' as rpc; 8 import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
9 import 'package:source_span/source_span.dart'; 9 import 'package:source_span/source_span.dart';
10 10
11 import 'breakpoint.dart'; 11 import 'breakpoint.dart';
12 import 'class.dart'; 12 import 'class.dart';
13 import 'library.dart'; 13 import 'library.dart';
14 import 'object.dart'; 14 import 'object.dart';
15 import 'scope.dart'; 15 import 'scope.dart';
16 import 'source_location.dart'; 16 import 'source_location.dart';
17 import 'source_report.dart';
17 18
18 VMScriptRef newVMScriptRef(Scope scope, Map json) { 19 VMScriptRef newVMScriptRef(Scope scope, Map json) {
19 if (json == null) return null; 20 if (json == null) return null;
20 assert(json["type"] == "@Script" || json["type"] == "Script"); 21 assert(json["type"] == "@Script" || json["type"] == "Script");
21 return new VMScriptRef._(scope, json); 22 return new VMScriptRef._(scope, json);
22 } 23 }
23 24
24 VMScriptToken newVMScriptToken(String isolateId, String scriptId, 25 VMScriptToken newVMScriptToken(String isolateId, String scriptId,
25 int position) { 26 int position) {
26 if (position == null) return null; 27 if (position == null) return null;
27 return new VMScriptToken._(isolateId, scriptId, position); 28 return new VMScriptToken._(isolateId, scriptId, position);
28 } 29 }
29 30
31 VMScriptToken newVMScriptTokenFromScript(VMScriptRef script, int position) {
nweiz 2016/05/04 23:05:51 I think I'd call this "from position" rather than
kevmoo 2016/05/05 20:46:26 Done.
32 if (position == null) return null;
33 return new VMScriptToken._(script._scope.isolateId, script._id, position);
34 }
35
30 /// A reference to a script in the Dart VM. 36 /// A reference to a script in the Dart VM.
31 /// 37 ///
32 /// A script contains information about the actual text of a library. Usually 38 /// A script contains information about the actual text of a library. Usually
33 /// there's only one script per library, but the `part` directive can produce 39 /// there's only one script per library, but the `part` directive can produce
34 /// libraries made up of multiple scripts. 40 /// libraries made up of multiple scripts.
35 class VMScriptRef implements VMObjectRef { 41 class VMScriptRef implements VMObjectRef {
36 final Scope _scope; 42 final Scope _scope;
37 43
38 /// The ID for script library, which is unique relative to its isolate. 44 /// The ID for script library, which is unique relative to its isolate.
39 final String _id; 45 final String _id;
(...skipping 23 matching lines...) Expand all
63 try { 69 try {
64 var response = await _scope.sendRequest("addBreakpoint", params); 70 var response = await _scope.sendRequest("addBreakpoint", params);
65 return newVMBreakpoint(_scope, response); 71 return newVMBreakpoint(_scope, response);
66 } on rpc.RpcException catch (error) { 72 } on rpc.RpcException catch (error) {
67 // Error 102 indicates that the breakpoint couldn't be created. 73 // Error 102 indicates that the breakpoint couldn't be created.
68 if (error.code == 102) return null; 74 if (error.code == 102) return null;
69 rethrow; 75 rethrow;
70 } 76 }
71 } 77 }
72 78
79 /// Generates a set of reports tied to this script.
80 ///
81 /// If [includeCoverageReport] is `true`, the report includes code coverage
82 /// information via [VMSourceReportRange.coverage] in
83 /// [VMSourceReport.ranges].
84 /// Otherwise, [VMSourceReportRange.coverage] is `null`.
85 ///
86 /// If [includePossibleBreakpoints] is `true`, the report includes a list of
87 /// token positions which correspond to possible breakpoints via
88 /// [VMSourceReportRange.possibleBreakpoints] in [VMSourceReport.ranges].
89 /// Otherwise, [VMSourceReportRange.possibleBreakpoints] is `null`.
90 ///
91 /// If [forceCompile] is `true`, all functions in the range of the report
92 /// will be compiled. If `false`, functions that are never used may not appear
93 /// in [VMSourceReportRange.misses].
94 /// Forcing compilation can cause a compilation error, which could terminate
95 /// the running Dart program.
96 ///
97 /// Either or both [start] and [end] may be provided to restrict the analysis
98 /// to a subrange of a script.
nweiz 2016/05/04 23:05:51 What does it mean to pass only "start" or only "en
kevmoo 2016/05/05 20:46:26 I think I cleared it up
99 /// For example, these can be used to restrict the report to the range of a
100 /// particular class or function.
101 Future<VMSourceReport> getSourceReport(
102 {bool includeCoverageReport: false,
103 bool includePossibleBreakpoints: false,
104 bool forceCompile: false,
105 VMScriptToken start,
106 VMScriptToken end}) async {
107 var reports = <String>[];
108 if (includeCoverageReport) {
109 reports.add('Coverage');
110 }
111 if (includePossibleBreakpoints) {
112 reports.add('PossibleBreakpoints');
113 }
114
115 var params = <String, dynamic>{'scriptId': _id, 'reports': reports};
116 if (forceCompile) {
117 params['forceCompile'] = true;
nweiz 2016/05/04 23:05:51 Nit: put the results on the same line as the "if"
kevmoo 2016/05/05 20:46:26 Acknowledged.
118 }
119 if (start != null) {
120 params['tokenPos'] = start._position;
121 }
122 if (end != null) {
123 params['endTokenPos'] = end._position;
124 }
125
126 var json = await _scope.sendRequest('getSourceReport', params);
127 return newSourceReport(_scope, json);
128 }
129
73 bool operator ==(other) => other is VMScriptRef && 130 bool operator ==(other) => other is VMScriptRef &&
74 (_fixedId ? _id == other._id : super == other); 131 (_fixedId ? _id == other._id : super == other);
75 132
76 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; 133 int get hashCode => _fixedId ? _id.hashCode : super.hashCode;
77 134
78 String toString() => uri.toString(); 135 String toString() => uri.toString();
79 } 136 }
80 137
81 /// A script in the Dart VM. 138 /// A script in the Dart VM.
82 class VMScript extends VMScriptRef implements VMObject { 139 class VMScript extends VMScriptRef implements VMObject {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return new _ScriptSpan(_script, startPosition, endPosition, 417 return new _ScriptSpan(_script, startPosition, endPosition,
361 startPosition == this._startPosition ? this._start : other._start, 418 startPosition == this._startPosition ? this._start : other._start,
362 endPosition == this._endPosition ? this._end : other._end); 419 endPosition == this._endPosition ? this._end : other._end);
363 } else { 420 } else {
364 var start = math.min(this.start.offset, other.start.offset); 421 var start = math.min(this.start.offset, other.start.offset);
365 var end = math.max(this.end.offset, other.end.offset); 422 var end = math.max(this.end.offset, other.end.offset);
366 return file.span(start, end); 423 return file.span(start, end);
367 } 424 }
368 } 425 }
369 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698