Skip to content

Conversation

@kenzieschmoll
Copy link
Member

@kenzieschmoll kenzieschmoll commented Jan 5, 2021

This PR:

  • Serves DevTools at app run / attach
  • Adds a link to DevTools to terminal output (right after the existing Observatory link)
  • Removes the 'v' terminal hotkey, since the DevTools uri is now printed to CLI
  • Adds a run flag --devtools-server-address so that an existing DevTools server can be passed to flutter_tools (this will be used by VS Code @DanTup)

Fixes #70129
Fixes #71688

FYI @helin24 @DanTup

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 5, 2021
@google-cla google-cla bot added the cla: yes label Jan 5, 2021
Comment on lines 75 to 78
await Future.wait(<Future<void>>[
connectToServiceProtocol(),
serveDevToolsGracefully(),
]);
Copy link
Member Author

Choose a reason for hiding this comment

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

attach wasn't being called from flutter run for profile mode like it was for debug mode, so I had to add this to run in addition to attach for the cold runner

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when we attach to a running profile mode app?

Copy link
Member Author

Choose a reason for hiding this comment

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

attach is called in run_cold.dart

@kenzieschmoll kenzieschmoll marked this pull request as ready for review January 6, 2021 16:22
status.cancel();
_logger.printError('Error running `pub global activate '
'devtools`:\n${_devToolsActivateProcess.stderr}');
await http.head('https://pub.dev');
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
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

https://pub.dev won't be accessible though, so one of these will always fail. Instead you should look up if there is a pub url override in the environment variable (the user could have some arbitrary pub mirror configured) and use that if present, falling back to pub.dev

@jonahwilliams jonahwilliams self-requested a review January 7, 2021 21:48
@kenzieschmoll
Copy link
Member Author

@DanTup see the latest commit for --devtools-server-address flag

status.cancel();
_logger.printError('Error running `pub global activate '
'devtools`:\n${_devToolsActivateProcess.stderr}');
await http.head('https://pub.dev');
Copy link
Contributor

Choose a reason for hiding this comment

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

https://pub.dev won't be accessible though, so one of these will always fail. Instead you should look up if there is a pub url override in the environment variable (the user could have some arbitrary pub mirror configured) and use that if present, falling back to pub.dev

} else {
try {
return await _devToolsLauncher.serve(openInBrowser: openInBrowser);
} catch (e) { // ignore: avoid_catches_without_on_clauses
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ignore errors here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want a failed devtools serve to halt a flutter run / attach process, so we swallow the error to fail gracefully. Do you have another suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes but you are catching all errors, including things like TypeError. What exceptions are you expecting here - could the _devToolsLauncher handle that instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Friendly ping here - please don't ignore avoid_catches_without_on_clauses

Copy link
Member Author

Choose a reason for hiding this comment

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

removed try catch from resident_runner and pushed exception swallowing into devtools_launcher

@kenzieschmoll
Copy link
Member Author

Done addressing review comments PTAL


Future<void> serveDevToolsGracefully({
Uri devToolsServerAddress,
bool openInBrowser = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the functionality of openInBrowser now? Can we let the user click on the link themselves so they get their preferred browser/existing instance

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I'm following up with @helin24 on this to see what we do from IntelliJ.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a TODO to remove this in a cleanup CL, as it will require a g3fix, and I'd like to get this landed sooner than later to start working on iterative CLs. AFAIK the 'v' hotkey was the only place using this functionality openInBrowser: true, so removing the param should be safe

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable!

} else {
try {
return await _devToolsLauncher.serve(openInBrowser: openInBrowser);
} catch (e) { // ignore: avoid_catches_without_on_clauses
Copy link
Contributor

Choose a reason for hiding this comment

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

Friendly ping here - please don't ignore avoid_catches_without_on_clauses

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@DanTup
Copy link
Contributor

DanTup commented Jan 11, 2021

@kenzieschmoll are there any existing deep-links generated by Flutter that I can use to test --devtools-server-address when spawned by VS Code?

@kenzieschmoll
Copy link
Member Author

@DanTup No, not yet. But if you pass a server address with a port number different than the default 9100, you should be able to verify that devtools is running on the port you specified, like 9105 for example.

@DanTup
Copy link
Contributor

DanTup commented Jan 11, 2021

@kenzieschmoll that seems to work great. I was mainly curious about how the links would appear in VS Code - for example wondering if we could route them to the internal embedded view in future if that's enabled. I'll come back to that once there are some links. Thanks!

@kenzieschmoll kenzieschmoll merged commit 1cb0a24 into flutter:master Jan 13, 2021
@kenzieschmoll kenzieschmoll deleted the devtools-launch branch January 13, 2021 05:39
jmagman added a commit that referenced this pull request Jan 13, 2021
jmagman added a commit that referenced this pull request Jan 13, 2021
jmagman added a commit that referenced this pull request Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tool]: support launching DevTools from command line links Link to DevTools more prominently than Observatory from flutter run

3 participants