-
Notifications
You must be signed in to change notification settings - Fork 87
Created a debugger for Dart Debug Extension. #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:built_collection/built_collection.dart'; | ||
| import 'package:dwds/data/extension_request.dart'; | ||
| import 'package:sse/server/sse_handler.dart'; | ||
| import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; | ||
|
|
||
| import '../../data/serializers.dart'; | ||
|
|
||
| /// A debugger backed by the Dart Debug Extension. | ||
| class ExtensionDebugger implements WipDebugger { | ||
| @override | ||
| WipConnection get connection => throw UnimplementedError(); | ||
|
|
||
| /// A connection between the debugger and the background of | ||
| /// Dart Debug Extension | ||
| final SseConnection _connection; | ||
|
|
||
| /// A map from id to a completer associated with an [ExtensionRequest] | ||
| final _completers = <int, Completer>{}; | ||
|
|
||
| var _completerId = 0; | ||
|
|
||
| ExtensionDebugger(this._connection) { | ||
| _connection.stream.listen((data) { | ||
pisimulation marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var message = serializers.deserialize(jsonDecode(data)); | ||
| if (message is ExtensionResponse) { | ||
| var encodedResult = json.decode(message.result); | ||
| if (_completers[message.id] == null) { | ||
| throw StateError('Missing completer.'); | ||
| } | ||
| _completers[message.id] | ||
| .complete(WipResponse(encodedResult as Map<String, dynamic>)); | ||
| } | ||
| }, onError: (e) { | ||
| close(); | ||
| }); | ||
| } | ||
|
|
||
| /// Sends a [command] with optional [params] to Dart Debug Extension | ||
| /// over the SSE connection. | ||
| @override | ||
| Future<WipResponse> sendCommand(String command, | ||
| {Map<String, dynamic> params}) { | ||
| var completer = Completer<WipResponse>(); | ||
| var id = newId(); | ||
| _completers[id] = completer; | ||
| _connection.sink.add(jsonEncode(serializers.serialize(ExtensionRequest( | ||
| (b) => b | ||
| ..id = id | ||
| ..command = command | ||
| ..commandParams = | ||
| BuiltMap<String, Object>(params ?? {}).toBuilder())))); | ||
| return completer.future; | ||
| } | ||
|
|
||
| int newId() => _completerId++; | ||
|
|
||
| Future<void> close() async { | ||
| await _connection.sink.close(); | ||
| } | ||
|
|
||
| @override | ||
| Future disable() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future enable() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<T> eventStream<T>(String method, WipEventTransformer<T> transformer) => | ||
| throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future<String> getScriptSource(String scriptId) => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<WipDomain> get onClosed => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<GlobalObjectClearedEvent> get onGlobalObjectCleared => | ||
| throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<DebuggerPausedEvent> get onPaused => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<DebuggerResumedEvent> get onResumed => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Stream<ScriptParsedEvent> get onScriptParsed => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future pause() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future resume() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Map<String, WipScript> get scripts => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future setPauseOnExceptions(PauseState state) => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future stepInto() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future stepOut() => throw UnimplementedError(); | ||
|
|
||
| @override | ||
| Future stepOver() => throw UnimplementedError(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
pisimulation marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import 'dart:convert'; | ||
|
|
||
| import 'package:dwds/data/extension_request.dart'; | ||
| import 'package:dwds/data/serializers.dart'; | ||
| import 'package:dwds/src/servers/extension_debugger.dart'; | ||
| import 'package:pedantic/pedantic.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| import 'fixtures/fakes.dart'; | ||
|
|
||
| FakeSseConnection connection; | ||
| ExtensionDebugger extensionDebugger; | ||
|
|
||
| void main() async { | ||
| setUp(() async { | ||
| connection = FakeSseConnection(); | ||
| extensionDebugger = ExtensionDebugger(connection); | ||
| }); | ||
|
|
||
| test('can send a command & receive a response', () async { | ||
| var extensionResponse = ExtensionResponse((b) => b | ||
| ..result = jsonEncode({ | ||
| 'result': {'value': 3.14} | ||
| }) | ||
| ..id = 0 | ||
| ..success = true); | ||
| var resultCompleter = Completer(); | ||
| unawaited(extensionDebugger.sendCommand('Runtime.evaluate', | ||
| params: {'expression': '\$pi'}).then((response) { | ||
| resultCompleter.complete(response); | ||
| })); | ||
| connection.controller | ||
| .add(jsonEncode(serializers.serialize(extensionResponse))); | ||
| var response = await resultCompleter.future; | ||
| expect(response.result['value'], 3.14); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.