Skip to content

Don't show Run/Debug button for files that don't have a main function #4563

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

Closed
suranjum opened this issue May 25, 2023 · 4 comments
Closed
Labels
in debugger Relates to the debug adapter or process of launching a debug session in editor Relates to code editing or language features is enhancement
Milestone

Comments

@suranjum
Copy link

Type: Bug

The Run button used be active only on main.dart. After an update (note sure which on), the Run button is now active on all .dart extension file, which gives error main entry not found. Either the Run button should be active only on main.dart or the extension should locate and run main.dart automatically.

Extension version: 3.64.0
VS Code version: Code 1.78.2 (b3e4e68a0bc097f0ae7907b217c1119af9e03435, 2023-05-10T14:47:05.613Z)
OS version: Linux x64 5.15.0-72-generic
Modes:
Sandboxed: Yes

System Info
Item Value
CPUs Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz (8 x 1800)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 2, 2, 1
Memory (System) 15.52GB (10.32GB free)
Process Argv --unity-launch --crash-reporter-id 1852884f-79c8-474c-9f62-50a1ce6988de
Screen Reader no
VM 0%
DESKTOP_SESSION cinnamon
XDG_CURRENT_DESKTOP X-Cinnamon
XDG_SESSION_DESKTOP cinnamon
XDG_SESSION_TYPE x11
@DanTup
Copy link
Member

DanTup commented May 25, 2023

This is expected. There is no requirement for your entry point to be lib/main.dart so in #4429 the restrictions on when this button should show up were removed.

The button is designed to "run the current file" so it would be confusing to run a different file. There should be no loss of functionality from before, the button simple appears in more places - it will still always behave the same when clicked in a file where it used to appear.

I would recommend using F5, the Run menu, or the buttons on the Debug Sidebar if you want the usual heuristics of which file to run (which takes the open file into account, but will look for a lib/main.dart if it's not a bin/tool/test file.

Hope this makes sense!

@DanTup DanTup added the working as intended Described behaviour is expected. label May 25, 2023
@DanTup DanTup closed this as completed May 25, 2023
@mindnect
Copy link

mindnect commented May 26, 2023

@DanTup
I accidentally clicked the run button several times. I'm new to Flutter, so I spent few hours without knowing why. I ended up hiding the button.

Shouldn't the run button only be visible when there is a main function exist? If I run it on a file without a main function, I get "Could not prepare isolate." error anyway. This change will only confuse users. I'm wondering if I'm missing something.

Thank you.

@DanTup
Copy link
Member

DanTup commented May 30, 2023

I did consider this, but it's a little complicated (because the VS Code plugin doesn't itself parse Dart code and would rely on async information from the analysis server).

However, perhaps we can combine what we had before:

  • if the file is something like lib/main.dart then always show the button
  • otherwise, use the Outline data to see if there's a main() function

@DanTup DanTup reopened this May 30, 2023
@DanTup DanTup added this to the v3.66.0 milestone May 30, 2023
@DanTup DanTup added is enhancement in editor Relates to code editing or language features in debugger Relates to the debug adapter or process of launching a debug session and removed working as intended Described behaviour is expected. labels May 30, 2023
@DanTup DanTup changed the title Run button active on all dart files unlike just on main.dart Don't show Run/Debug button for files that don't have a main function May 30, 2023
@DanTup
Copy link
Member

DanTup commented May 30, 2023

For the original set of files (lib/main.dart, tool/*, bin/*) we'll continue to always show the buttons. But for other files (the ones that only recently started showing the buttons) we'll now only show it if there's a main function:

May-30-2023 10-46-57

@DanTup DanTup closed this as completed in 43fb4a2 May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in debugger Relates to the debug adapter or process of launching a debug session in editor Relates to code editing or language features is enhancement
Projects
None yet
Development

No branches or pull requests

3 participants