OLD | NEW |
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) { |
| 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 21 matching lines...) Expand all Loading... |
61 try { | 67 try { |
62 var response = await _scope.sendRequest("addBreakpoint", params); | 68 var response = await _scope.sendRequest("addBreakpoint", params); |
63 return newVMBreakpoint(_scope, response); | 69 return newVMBreakpoint(_scope, response); |
64 } on rpc.RpcException catch (error) { | 70 } on rpc.RpcException catch (error) { |
65 // Error 102 indicates that the breakpoint couldn't be created. | 71 // Error 102 indicates that the breakpoint couldn't be created. |
66 if (error.code == 102) return null; | 72 if (error.code == 102) return null; |
67 rethrow; | 73 rethrow; |
68 } | 74 } |
69 } | 75 } |
70 | 76 |
| 77 /// Generates a set of reports tied to this script. |
| 78 /// |
| 79 /// If [includeCoverageReport] is `true`, the report includes code coverage |
| 80 /// information via [VMSourceReportRange.coverage] in |
| 81 /// [VMSourceReport.ranges]. |
| 82 /// Otherwise, [VMSourceReportRange.coverage] is `null`. |
| 83 /// |
| 84 /// If [includePossibleBreakpoints] is `true`, the report includes a list of |
| 85 /// token positions which correspond to possible breakpoints via |
| 86 /// [VMSourceReportRange.possibleBreakpoints] in [VMSourceReport.ranges]. |
| 87 /// Otherwise, [VMSourceReportRange.possibleBreakpoints] is `null`. |
| 88 /// |
| 89 /// If [forceCompile] is `true`, all functions in the range of the report |
| 90 /// will be compiled. |
| 91 /// Forcing compilation can cause a compilation error, which could terminate |
| 92 /// the running Dart program. |
| 93 /// |
| 94 /// Set [forceCompile] to `true` to force compilation of all functions in |
| 95 /// the range of the report. |
| 96 /// Forcing compilation can cause a compilation error, which could terminate |
| 97 /// the running Dart program. |
| 98 /// |
| 99 /// Either or both of the [tokenPos] and [endTokenPos] may be |
| 100 /// provided to restrict the analysis to a subrange of a script |
| 101 /// (for example, these can be used to restrict the report to the range of a |
| 102 /// particular class or function). |
| 103 Future<VMSourceReport> getSourceReport( |
| 104 {bool includeCoverageReport: false, |
| 105 bool includePossibleBreakpoints: false, |
| 106 bool forceCompile: false, |
| 107 int tokenPos, |
| 108 int endTokenPos}) async { |
| 109 var reports = <String>[]; |
| 110 if (includeCoverageReport) { |
| 111 reports.add('Coverage'); |
| 112 } |
| 113 if (includePossibleBreakpoints) { |
| 114 reports.add('PossibleBreakpoints'); |
| 115 } |
| 116 |
| 117 var params = <String, dynamic>{'scriptId': _id, 'reports': reports}; |
| 118 if (forceCompile) { |
| 119 params['forceCompile'] = true; |
| 120 } |
| 121 if (tokenPos != null) { |
| 122 params['tokenPos'] = tokenPos; |
| 123 } |
| 124 if (endTokenPos != null) { |
| 125 params['endTokenPos'] = endTokenPos; |
| 126 } |
| 127 |
| 128 var json = await _scope.sendRequest('getSourceReport', params); |
| 129 return newSourceReport(_scope, json); |
| 130 } |
| 131 |
71 bool operator ==(other) => other is VMScriptRef && | 132 bool operator ==(other) => other is VMScriptRef && |
72 (_fixedId ? _id == other._id : super == other); | 133 (_fixedId ? _id == other._id : super == other); |
73 | 134 |
74 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; | 135 int get hashCode => _fixedId ? _id.hashCode : super.hashCode; |
75 | 136 |
76 String toString() => uri.toString(); | 137 String toString() => uri.toString(); |
77 } | 138 } |
78 | 139 |
79 /// A script in the Dart VM. | 140 /// A script in the Dart VM. |
80 class VMScript extends VMScriptRef implements VMObject { | 141 class VMScript extends VMScriptRef implements VMObject { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 var start = math.min(this._start, other._start); | 368 var start = math.min(this._start, other._start); |
308 var end = math.max(this._end, other._end); | 369 var end = math.max(this._end, other._end); |
309 return new _ScriptSpan(_script, start, end); | 370 return new _ScriptSpan(_script, start, end); |
310 } else { | 371 } else { |
311 var start = math.min(this._start, other.start.offset); | 372 var start = math.min(this._start, other.start.offset); |
312 var end = math.max(this._end, other.end.offset); | 373 var end = math.max(this._end, other.end.offset); |
313 return file.span(start, end); | 374 return file.span(start, end); |
314 } | 375 } |
315 } | 376 } |
316 } | 377 } |
OLD | NEW |