Closed kingwill101 closed 5 years ago
When running hover run
you should get a line:
[...]
flutter: Observatory listening on http://127.0.0.1:50300/xzxoXvGyLX0=/
[...]
With this Observatory url, follow the FDE/Debugging.md ~Attaching instructions.
I'm not a VSCode user; please let me know if the above instructions are still correct.
Yes that works, thank you.
note that the observatory seems to expect you to have a main.dart
file when reloading
any update on this? vscode support is for forcing me to use flutter's native solution for now
To have hot-reload in vs-code you must:
hover run
you should get a line:
[...]
flutter: Observatory listening on http://127.0.0.1:50300/xzxoXvGyLX0=/
[...]
It's to this Observatory that the VSCode extension will connect to.
{
"name": "go-flutter desktop",
"request": "attach",
"deviceId": "flutter-tester",
"observatoryUri": "${command:dart.promptForVmService}",
"type": "dart",
"program": "lib/main_desktop.dart" // Dart-Code v3.3.0 required
}
Edit: davidmartos explained how to configure vscode so that it works without an observatoryURL. https://github.com/go-flutter-desktop/go-flutter/issues/129#issuecomment-550249279
There's a beta of the upcoming VS Code release that adds support for setting "program":
on attach configs here:
https://github.com/Dart-Code/Dart-Code/issues/1881#issuecomment-513747167
@DanTup @Drakirus Any chance extension can hook up debugger also?
@jascodes I'm not sure I understand the question. The Dart/Flutter extensions to fully support debugging for launched and attached apps, however I'm not familiar with the setup here with Go. What is it that doesn't work for you?
If you raise an issue at Dart-Code with details and a log file I can take a look.
@DanTup Check out direction for hot-reloading of this project in vscode by @Drakirus above in this thread. I am attaching it below. go-flutter generates Observatory url that one need to attach to manually for debugging.
To have hot-reload in vs-code you have to:
- ~Use
lib/main.dart
as your app entry-point. hover default the entry-point tolib/main_desktop.dart
, it's not supported by VSCode, Dart-Code/Dart-Code#1881, in order to get hover run with VSCode you have to run:hover run --target=lib/main.dart
. (cough: don't forget thedebugDefaultTargetPlatformOverride
in main.dart wink)~Get the 'Observatory url'. When running
hover run
you should get a line:[...] flutter: Observatory listening on http://127.0.0.1:50300/xzxoXvGyLX0=/ [...]
It's to this Observatory that the VSCode extension well connect to.
- Add a VSCode launch configuration like the following:
{ "name": "go-flutter desktop", "request": "attach", "deviceId": "flutter-tester", "observatoryUri": "${command:dart.promptForVmService}", "type": "dart", "program": "lib/main_desktop.dart" // Dart-Code v3.3.0 required }
- Start Debugging (F5)
- Paste in the popup prompt the 'Observatory url'
- Enjoy hot-reloading and the other feature that the VSCode extension provide!
Oh, sorry, you're asking for a way to automatically attach?
I'm not familiar with how you're launching the app so I don't know how easy it'd be. I presume you're using the standard Go extension in VS Code to launch the Go app, and then attaching the Dart debugger? You would probably need a VS Code extension that understands how both of these work and can glue them together.
@jascodes you're leadin' us around in circles...
The extension made by @DanTup works in 2 modes: launch
and attach
.
I'm sure you are familiar with the launch
mode, you click a button an everything is handled for you.
go-flutter isn't part of the flutter tool-chain, we came up with hover
to automate the maximum of the painful setup. We are not supporting VSCode launch
mode, and will certainly never support it.
hover
, when running the the hover run
command mode exposes the dart VM "Observatory url" (Not generated by go-flutter, it's a dart VM feature) in which you can connect yourself to interact with.. the dart VM.
The steps:
Get the 'Observatory url'. When running
hover run
you should get a line:[...] flutter: Observatory listening on http://127.0.0.1:50300/xzxoXvGyLX0=/ [...]
It's to this Observatory that the VSCode extension well connect to.
- Add a VSCode launch configuration like the following:
{ "name": "go-flutter desktop", "request": "attach", "deviceId": "flutter-tester", "observatoryUri": "${command:dart.promptForVmService}", "type": "dart", "program": "lib/main_desktop.dart" // Dart-Code v3.3.0 required }
- Start Debugging (F5)
- Paste in the popup prompt the 'Observatory url'
- Enjoy hot-reloading and the other feature that the VSCode extension provide!
Are require to connect VScode to the 'go-flutter' instance, and it allows you to have fully support for debugging
in VSCode, have you tried it yet?
@Drakirus Yup I have tried and it works well.
We are not supporting VSCode launchmode, and will certainly never support it.
Gotcha
@Drakirus Proposal: how about making hover save the last observatory URI in a hidden file? https://github.com/go-flutter-desktop/hover/blob/4751a8e61e1d43372bf6c94639bf13e92f30bf23/cmd/run.go#L61
I have been looking into VS Code extensions and it would not be hard to make one that reads the URI from a file and automatically attaches with the Dart VS Code extension debugger.
I have been looking into VS Code extensions and it would not be hard to make one that reads the URI from a file and automatically attaches with the Dart VS Code extension debugger.
I don't know the details of how hover
works, but you could probably also make a VS Code extension that runs it for you and regexes the URL out of stdout, then spawns a Dart debug session (here's how you can start a Dart debug session programatically - you'd want to use attach
and incude the observatoryUri
).
@DanTup I was kinna thinking along same line, I was taken a back lil when @Drakirus put it like We are not supporting VSCode launchmode, and will certainly never support it.
That certainly shut me up :stuck_out_tongue_closed_eyes:
To be fair, if this project doesn't already have a VS Code extension, then I'm not sure it can really support this. It would need to be built as a VS Code extension specifically to glue the two things together - and I think that would work better if done by having it launch Hover and read the output than writing to a file (since it would all be streamlined into a single button press).
I think @Drakirus meant support for the existing flutter launch extension??
As @davidmartos96 and @DanTup propose, I think nothing holds us back from creating a hover extension for vscode, basically just a GUI arround the hover cli.
I think @Drakirus meant support for the existing flutter launch extension??
Exactly, the existing flutter/dart extension cannot support hover at the moment. Nothing holds us back from creating a hover extension for VSCode, you are right. And as @DanTup said:
It would need to be built as a VS Code extension specifically to glue the two things (hover and the existing VSCode extension) together.
The hover VSCode extension would only be glue.
For now, I don't see any value in creating our extension to support launch mode. To me, opening a terminal, executing one command and one copy-paste isn't worth automating (and time creating/maintaining such extension).
To me, opening a terminal, executing one command and one copy-paste isn't worth automating
I prefer to use terminal as well. That said, lots of people like the GUI buttons, so it would be awesome if a glue-like extension is made. Anyone, feel free to pick this up! :rocket:
Is anyone else getting Error 1001 received from application: File system already exists
when attaching with the configuration @Drakirus provided above?
It attaches fine, with breakpoints, but all Flutter output is missing. The Debug Console is empty.
I am using the Dart extension version 3.3.0 Beta 3
I ended up finding a way to debug Go-Flutter apps within VSCode in the latest beta version v1.10.7 without copy pasting the Observatory URL and I wanted to share it with you.
flutter config --enable-linux-desktop
If you are not in the master branch and do flutter devices
only Android and iOS devices will appear by default. A way to change this is checking out the latest commit in the beta branch of flutter instead of checking out the beta branch itself, to let flutter think you are in master. Hopefully this step won't be required in the future, when flutter-desktop-embedding is more mature.
In your flutter installation directory with beta branch installed:
git checkout HEAD~0
The commit checked out for the beta branch v1.10.7 should be e70236e36
flutter devices
tasks.json
{
"label": "hover build linux",
"type": "shell",
"command": "hover build linux --debug",
"problemMatcher": [
"$go"
]
}
Change the command according to your desktop.
launch.json
{
"name": "Flutter Desktop App",
"type": "dart",
"request": "launch",
"program": "lib/main_desktop.dart",
"args": ["--use-application-binary", "go/build/outputs/linux/example_flutter"],
"preLaunchTask": "hover build linux"
}
Change the output path accordingly to your desktop.
Place a breakpoint in your Dart code and run the new launch configuration.
Let me know if you have any questions
@davidmartos96 thanks for sharing, this is absolutely amazing. 👍
@davidmartos96 thanks for sharing. I followed the step above.
flutter device
list mac os as a device.
12:49:13 › flutter devices
1 connected device:
macOS • macOS • darwin-x64 • Mac OS X 10.14.6 18G1012
But VSCode dose not detect any device.
And when I try to run go-flutter apps from VSCode, it requires me to start a device.
Here are my VSCode json files task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "hover build darwin",
"type": "shell",
"command": "cd example && hover build darwin --debug",
"problemMatcher": [
"$go"
]
}
]
}
launch.json
{
"version": "0.2.1",
"configurations": [
{
"name": "Flutter Desktop App",
"type": "dart",
"request": "launch",
"program": "example/lib/main_desktop.dart",
"args": ["--use-application-binary", "go/build/outputs/darwin/fijkplayer_example"],
"preLaunchTask": "hover build darwin"
}
]
}
settings.json
{
"dart.env": {
"ENABLE_FLUTTER_DESKTOP": true,
}
}
@befovy If launching flutter devices from the console works, then make sure that VSCode is using the same flutter binary as your PATH. Also, restart VSCode so that it refreshes the available devices. Another thing you can try is to remove the dart.env settings, that step is not necessary anymore for Flutter desktop. Now you can set it up with flutter config
as above.
If you run flutter config --enable-mac-desktop
while VS Code is open, you'll need to restart it as the config changes are only read at startup (and VS Code runs the device daemon in the background). There's another potential reason for the device to not show up, and that's if there isn't a macOS desktop project in the current folder (VS Code asks the device daemon which of the devies are valid for the project in a given folder).
If neither of these seem to explain it, please file an issue at https://github.com/Dart-Code/Dart-Code and include a Flutter device daemon log file and we can debug further.
Thanks for your answers @DanTup @davidmartos96
There's another potential reason for the device to not show up, and that's if there isn't a macOS desktop project in the current folder
After I created an empty macos
folder in project, VS Code show the macOS device.
But I got another error when running go-flutter examples pointer_demo ( press F5 ).
BYW hover run
works OK.
After I created an empty
macos
folder in project, VS Code show the macOS device.
Sorry I wasn't very clear with this - it can't be an empty folder, it needs to contain the macOS parts of the app. For example if you run flutter create --macos
in a new folder, it will include macos
folder with the necessary files. I think you can probably just copy that folder over into your project, but I'm not familiar enough with the desktop work to be certain. Running flutter create . --macos
in the existing project may also work.
@DanTup Since the goal is just to pass the Flutter daemon's check that the project supports the desktop platform, an empty folder should work, as that's all the daemon checks (currently, although there's no guarantee that won't change in the future). The build for go-flutter doesn't use the Flutter desktop embedding or runner.
That error just looks like the result of supplying a binary, rather than the .app, as the prebuilt path on macOS.
The build for go-flutter doesn't use the Flutter desktop embedding or runner.
Ah - it didn't occur to me this might work differently - thanks for clarifying! :-)
To me, opening a terminal, executing one command and one copy-paste isn't worth automating (and time creating/maintaining such extension).
I think it awesome if hover run
is watching folder lib
, detecting files changed, and auto hot-reload if detected. It can be implemented by receiving system file events, there're several Go libraries of file system notification. I would get tired of typing r
in my heart.
@chengxuncc I'm not 100% sure hover is the right place for baking such functionality. I've managed to create a proof-of-concept, it doesn't require any hover modification.
Hot reload is trigger when the flutter attach
receives a SIG USR1
signal source.
By it's own, hover spawn a flutter attach
cmd, it's on this one that we forward key-presses like r.
My opinion is, the editor should implement such feature, not hover. Because it has a much better understanding of what is modified or not.
Here is my POC (obtaining the flutter attach
is very ugly and, adaptation to your system is require, not all system have the same label for USR1
).
$ inotifywait -q -m -e modify lib |
while read -r filename event; do
kill -USR1 $(pgrep -f "attach") && echo 'reload flutter...'
done
I agree with @pchampio, I think this is not hover's responsibility, this should be implemented in a VSCode extension, where it calls hover in background and optionally allow to bind some keys to auto-reload like hover.el does for emacs.
For anyone still interested, I made a fork of hover where I added hover run --watch
to get hot reloading. It's just a "proof of concept", and only watches the libs
folder for now (no recursive watch). It also removes the ability to press r or R in the terminal to reload without having to press Enter after.
@Nohac please open a PR on hover, discussion about this feature can properly take place in the PR.
Has anything happened regarding the PR? (Here is the change, by the way)
@solarkraft Sadly, no. I use neovim + https://github.com/iamcco/coc-flutter that recently got support for go-flutter: https://github.com/iamcco/coc-flutter/commit/02238b28e2f5ffcf2526820ce9522fdabc416b2f so I personally don't need the file watcher anymore. Feel free to take my changes and open a PR if you want :+1:
Now that it is possible to get automatic hot reload working using https://github.com/google/flutter-desktop-embedding and vscode is there a way now to get it working with hover?