Unverified Commit ccc0d294 authored by Devon Carew's avatar Devon Carew Committed by GitHub

send 'reloadRecommended' info to IDEs (#13996)

* send 'reloadRecommended' info to IDEs

* rename hint ==> hintMessage
parent 2a07f3f2
...@@ -677,11 +677,14 @@ Stream<Map<String, dynamic>> get stdinCommandStream => stdin ...@@ -677,11 +677,14 @@ Stream<Map<String, dynamic>> get stdinCommandStream => stdin
}); });
void stdoutCommandResponse(Map<String, dynamic> command) { void stdoutCommandResponse(Map<String, dynamic> command) {
final String encoded = JSON.encode(command, toEncodable: _jsonEncodeObject); stdout.writeln('[${jsonEncodeObject(command)}]');
stdout.writeln('[$encoded]');
} }
dynamic _jsonEncodeObject(dynamic object) { String jsonEncodeObject(dynamic object) {
return JSON.encode(object, toEncodable: _toEncodable);
}
dynamic _toEncodable(dynamic object) {
if (object is OperationResult) if (object is OperationResult)
return _operationResultToMap(object); return _operationResultToMap(object);
return object; return object;
...@@ -697,10 +700,17 @@ Future<Map<String, dynamic>> _deviceToMap(Device device) async { ...@@ -697,10 +700,17 @@ Future<Map<String, dynamic>> _deviceToMap(Device device) async {
} }
Map<String, dynamic> _operationResultToMap(OperationResult result) { Map<String, dynamic> _operationResultToMap(OperationResult result) {
return <String, dynamic>{ final Map<String, dynamic> map = <String, dynamic>{
'code': result.code, 'code': result.code,
'message': result.message 'message': result.message,
}; };
if (result.hintMessage != null)
map['hintMessage'] = result.hintMessage;
if (result.hintId != null)
map['hintId'] = result.hintId;
return map;
} }
dynamic _toJsonable(dynamic obj) { dynamic _toJsonable(dynamic obj) {
......
...@@ -843,11 +843,24 @@ abstract class ResidentRunner { ...@@ -843,11 +843,24 @@ abstract class ResidentRunner {
} }
class OperationResult { class OperationResult {
OperationResult(this.code, this.message, { this.hint }); OperationResult(this.code, this.message, { this.hintMessage, this.hintId });
/// The result of the operation; a non-zero code indicates a failure.
final int code; final int code;
/// A user facing message about the results of the operation.
final String message; final String message;
final String hint;
/// An optional hint about the results of the operation. This is used to provide
/// sidecar data about the operation results. For example, this is used when
/// a reload is successful but some changed program elements where not run after a
/// reassemble.
final String hintMessage;
/// A key used by tools to discriminate between different kinds of operation results.
/// For example, a successful reload might have a [code] of 0 and a [hintId] of
/// `'restartRecommended'`.
final String hintId;
bool get isOk => code == 0; bool get isOk => code == 0;
......
...@@ -457,8 +457,8 @@ class HotRunner extends ResidentRunner { ...@@ -457,8 +457,8 @@ class HotRunner extends ResidentRunner {
status.cancel(); status.cancel();
if (result.isOk) if (result.isOk)
printStatus('${result.message} in ${getElapsedAsMilliseconds(timer.elapsed)}.'); printStatus('${result.message} in ${getElapsedAsMilliseconds(timer.elapsed)}.');
if (result.hint != null) if (result.hintMessage != null)
printStatus('\n${result.hint}'); printStatus('\n${result.hintMessage}');
return result; return result;
} catch (error) { } catch (error) {
status.cancel(); status.cancel();
...@@ -678,7 +678,8 @@ class HotRunner extends ResidentRunner { ...@@ -678,7 +678,8 @@ class HotRunner extends ResidentRunner {
return new OperationResult( return new OperationResult(
reassembleAndScheduleErrors ? 1 : OperationResult.ok.code, reassembleAndScheduleErrors ? 1 : OperationResult.ok.code,
reloadMessage, reloadMessage,
hint: unusedElementMessage, hintMessage: unusedElementMessage,
hintId: unusedElementMessage != null ? 'restartRecommended' : null,
); );
} }
......
...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/commands/daemon.dart'; import 'package:flutter_tools/src/commands/daemon.dart';
import 'package:flutter_tools/src/globals.dart'; import 'package:flutter_tools/src/globals.dart';
import 'package:flutter_tools/src/ios/ios_workflow.dart'; import 'package:flutter_tools/src/ios/ios_workflow.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../src/context.dart'; import '../src/context.dart';
...@@ -267,6 +268,23 @@ void main() { ...@@ -267,6 +268,23 @@ void main() {
IOSWorkflow: () => new MockIOSWorkflow(), IOSWorkflow: () => new MockIOSWorkflow(),
}); });
}); });
group('daemon serialization', () {
test('OperationResult', () {
expect(
jsonEncodeObject(OperationResult.ok),
'{"code":0,"message":""}'
);
expect(
jsonEncodeObject(new OperationResult(1, 'foo')),
'{"code":1,"message":"foo"}'
);
expect(
jsonEncodeObject(new OperationResult(0, 'foo', hintMessage: 'my hint', hintId: 'myId')),
'{"code":0,"message":"foo","hintMessage":"my hint","hintId":"myId"}'
);
});
});
} }
bool _notEvent(Map<String, dynamic> map) => map['event'] == null; bool _notEvent(Map<String, dynamic> map) => map['event'] == null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment