Skip to content
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

Merged
merged 12 commits into from
Apr 25, 2019

Conversation

DanTup
Copy link
Contributor

@DanTup DanTup commented Apr 22, 2019

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)
  • The success flag is a simple boolean rather than using the VM-Service 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.
  • Handle all valid URIs (for ex. http:// without the /ws- what was accepted, but failed)
  • Check the method field before processing the incoming message (and provide a useful message if the method is not recognised)

@@ -125,39 +125,57 @@ void serveDevTools({
// }
// }
_stdinCommandStream.listen((Map<String, dynamic> json) async {
final int id = json['id'];
final dynamic id = json['id'];
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

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)

Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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!

DanTup referenced this pull request Apr 22, 2019
* Move server code to devtools_server package
// 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 &&
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DanTup added a commit to DanTup/vm_service_drivers that referenced this pull request Apr 23, 2019
This is to make it easier to reuse in devtools+devtools_server.

See flutter/devtools#563 (comment).
Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

devoncarew pushed a commit to dart-archive/vm_service_drivers that referenced this pull request Apr 23, 2019
* 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) {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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}) {
  ...
}

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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)

Copy link
Contributor

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.

@DanTup
Copy link
Contributor Author

DanTup commented Apr 24, 2019

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.

@DanTup
Copy link
Contributor Author

DanTup commented Apr 24, 2019

Forcing travis now the new build is out. Can someone check with the latest change (347d1c8) this is good to land?

@DanTup DanTup force-pushed the launch-browser-tweaks branch from 347d1c8 to 1890569 Compare April 24, 2019 16:06
@DanTup
Copy link
Contributor Author

DanTup commented Apr 25, 2019

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.

Copy link
Member

@kenzieschmoll kenzieschmoll left a 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']}',
Copy link
Member

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?

DanTup added 12 commits April 25, 2019 16:32
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.
@DanTup DanTup force-pushed the launch-browser-tweaks branch from 0e58d4d to faba3b9 Compare April 25, 2019 15:32
@DanTup
Copy link
Contributor Author

DanTup commented Apr 25, 2019

Fixed the error and rebased to get the flaky test fixes. Will land when (if) it goes green.

@DanTup DanTup merged commit a42f331 into flutter:master Apr 25, 2019
@DanTup DanTup deleted the launch-browser-tweaks branch April 25, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants