-
Notifications
You must be signed in to change notification settings - Fork 339
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
Tweaks to browser-launching service #563
Conversation
@@ -125,39 +125,57 @@ void serveDevTools({ | |||
// } | |||
// } | |||
_stdinCommandStream.listen((Map<String, dynamic> json) async { | |||
final int id = json['id']; | |||
final dynamic id = json['id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What types might we get here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VS Code has always used strings. When I changed this, I thought I checked the spec and it said "any value", however that was actually Wikipedia! The spec says:
An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
I don't think we follow JSON-RPC particularly strictly, but I do think we should support both int+string here (I'm using shared code used for Flutter/analysis server/etc. which used strings, and it was just crashing on this line).
I'm hoping one day we can support int | String
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I've added a comment about the types)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment helps a lot. Thanks!
}); | ||
} | ||
|
||
Future _handleVmRegister(dynamic id, Map<String, dynamic> params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] How about Future<void>
instead of Future<dynamic>
return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I think I used Extract Method and didn't spot it - thanks!
// Lots of things are considered valid URIs (including empty strings | ||
// and single letters) since they can be relative, so we need to do some | ||
// extra checks. | ||
if (uri != null && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you are here we should really be failing if the uri is not valid instead of just quietly pretending everything succeeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot - this code wasn't sending any response back (so if it happened, VS Code would just sit waiting). It also would throw on the Uri.parse
instead of giving a well-formed error, so I've changed that too.
@@ -233,3 +259,17 @@ void printOutput( | |||
}) { | |||
print(machineMode ? jsonEncode(json) : message); | |||
} | |||
|
|||
/// Map the URI (which may already be Observatory web app) to a WebSocket URI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a line break after :"from the VM service."
The title of an comment should be on a separate line from following sentences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
/// Map the URI (which may already be Observatory web app) to a WebSocket URI | ||
/// for the VM service. If the URI is already a VM Service WebSocket URI it | ||
/// will not be modified. | ||
Uri getVmServiceUriFromObservatoryUri(Uri uri) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of duplicating this method from
package:devtools we should add this method to
package:vm_service_lib
so we can use it everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - I've added a TODO, and will open a PR in vm_service_lib
today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR is at dart-archive/vm_service_drivers#232
This is to make it easier to reuse in devtools+devtools_server. See flutter/devtools#563 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add helper to convert Observatory URI to WS URI This is to make it easier to reuse in devtools+devtools_server. See flutter/devtools#563 (comment). * Simplify test * Add changelog + rev version
/// for the VM service. | ||
/// | ||
/// If the URI is already a VM Service WebSocket URI it will not be modified. | ||
Uri getVmServiceUriFromObservatoryUri(Uri uri) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the naming of this method still make sense? Seems odd to me that we have observatory in the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that is a good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what to call it. The banner says "Observatory listening on" and then gives a HTTP URL. The service URI we want is a websocket protocol and has /ws
on the end. What should we call each of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getVmServiceUriFromObservatoryUri()
==> convertToWebsocketUrl()
? Or,
String convertToWebsocketUrl({@required String serviceProtocolUrl}) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me - though I think making it named is a bit overkill, as it's never likely to be a literal string, so we'll always end up with convertToWebSocketUrl(serviceProtocolUrl: serviceProtocolUrl)
.
Also, since the types are Uris, we should probably use Uri?
Uri convertToWebsocketUri(Uri serviceProtocolUri) {
...
}
I still think "serviceProtocolUri" to mean the non-websocket part is weird, but I don't the the specific name is that important as long as it conveys roughly what it does - the doc comments can always be more detailed if required.
@devoncarew I haven't made any code use this yet, so changing it and re-publishing is fine by me. Since I can't merge publish, feel free to just change it if it's easier than waiting for me.
/// for the VM service. | ||
/// | ||
/// If the URI is already a VM Service WebSocket URI it will not be modified. | ||
Uri getVmServiceUriFromObservatoryUri(Uri uri) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should re-read that doc periodically till it sinks in =)
(I'm surprised we don't have a lint for this one - at least, I can't see one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pq We should have a lint and quick fix that catches zero argument methods where the name starts with "get" and quick fixes them to be actual getters.
I've pushed 347d1c8 that removes the method discussed above, in favour of the shared one in vm_service_libs. It won't build until dart-archive/vm_service_drivers#233 lands and is published to pub, but if the code is LGTM'd in the meantime, I can just rebuild when that lands and if it goes green, land it. |
Forcing travis now the new build is out. Can someone check with the latest change (347d1c8) this is good to land? |
347d1c8
to
1890569
Compare
I've reviewed the failures here, and believe they're all the same timing-related flakes we're seeing on master right now. @jacob314 still happy for me to land this? I've removed the helper function that was duplicated (and it's ben renamed in the new place) since your LGTM, but otherwise I think it's the same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved with one nit
break; | ||
default: | ||
printOutput( | ||
'Unknown command ${json['method']}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should this say "Unknown method" to match the 'error' param below it?
JSON-RPC allows for this, and other Flutter services handle strings.
Success() ('type': 'success') seems to be a VM-Service convention but other stdio services like Flutter just have a bool.
Without this, an error occurs if you send a HTTP URI since it tries to connect to it as a websocket. This also adds /ws on the end if it's not there. This makes it valid to send the URL that's printed by the VM directly.
We will remove the `method` one once VS Code has been updated for a while.
Removes both copies of `getVmServiceUriFromObservatoryUri` and calls the shared `convertToWebSocketUrl` method.
0e58d4d
to
faba3b9
Compare
Fixed the error and rebased to get the flaky test fixes. Will land when (if) it goes green. |
I made some tweaks while wiring this up in VS Code.
id
field now supports any type (as per JSON-RPC) - specifically, VS Code was using strings for all the other services (not for any good reason, but it seemed better to support this than fail)Success()
class (since this didn't seem to match the other stdio services we have).Success()
is still used for the response of the VM-Service handler though.http://
without the/ws
- what was accepted, but failed)method
field before processing the incoming message (and provide a useful message if the method is not recognised)