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

Automatically run build_runner on VS Code startup, not working #1516

Closed
HerrNiklasRaab opened this issue Mar 7, 2019 · 18 comments
Closed

Automatically run build_runner on VS Code startup, not working #1516

HerrNiklasRaab opened this issue Mar 7, 2019 · 18 comments
Labels
in tasks Relates to VS Code tasks, such as those provided by Task Providers is enhancement
Milestone

Comments

@HerrNiklasRaab
Copy link

An issue for a problem, which came up in this issue: #1211 (comment)

Here is my project: intersect.zip

@DanTup Yes, at least sort of.

I wanted to start the watch task as soon as I open VS Code. So I did the following:

  1. STRG + SHIFT + P
  2. Typed: "Tasks Configure Task" ENTER
  3. Selected, the Task I wanted to configure
  4. Modified generated task.json to the following (only added "runOptions"):

image

Now there is a warning:

Incorrect type. Expected "object".

And when I restart Visual Studio I get an error notification and following output:

Error: The pub task detection didn't contribute a task for the following configuration:
{
"type": "pub",
"command": "watch",
"problemMatcher": [
"dart-pub-build_runner"
],
"runOptions": {
"runOn": "folderOpen"
}
}
The task will be ignored.

Similar to this one:
dart-lang/build#1025 (comment)

Any idea?

@HerrNiklasRaab
Copy link
Author

After the VS Code February 2018 update, this doesn't appear anymore.

@DanTup
Copy link
Member

DanTup commented Mar 8, 2019

VS Code 1.32 has some another serious bug though - see #1518. I would recommend staying on v1.31 until a fix is released (they have a fix, and I've verified from source, but it hasn't been released).

@HerrNiklasRaab
Copy link
Author

HerrNiklasRaab commented Mar 8, 2019

Ok sorry to disturb again, but after I installed this release: https://github.com/Dart-Code/Dart-Code/releases/tag/v2.23.0-beta.2
The error came back.

I then tried to uninstall this beta release and install the stable release again. But this didn't help either.

I have really no idea, what causes this problem. But after the VS Code update, I restarted VS Code several times, because I couldn't believe, that the update fixed this. And it worked every time.

If you need anything else to reproduce this, I am here to help.

@DanTup DanTup reopened this Mar 8, 2019
@DanTup
Copy link
Member

DanTup commented Mar 8, 2019

Are you able to attach the smallest possible folder you can repro it with?

@HerrNiklasRaab
Copy link
Author

@DanTup
Copy link
Member

DanTup commented Mar 11, 2019

@HerrNiklasRaab I can reproduce your issue, but if I add "dart.previewBuildRunnerTasks": true to the .code-workspace file and reload, then it goes away. Can you double-check that you have this set correctly somewhere?

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Mar 11, 2019
@HerrNiklasRaab
Copy link
Author

HerrNiklasRaab commented Mar 11, 2019

Sadly it doesn't work. I tried the following:

  • Set dart.previewBuildRunnerTasks: true only in User Settings
  • Set dart.previewBuildRunnerTasks: true only in Workspace Settings
  • Set dart.previewBuildRunnerTasks: true in both Settings

Anything else that I can try?

@DanTup
Copy link
Member

DanTup commented Mar 11, 2019

@HerrNiklasRaab Two things to check:

  1. Any errors/warnings in the dev console (Help -> Toggle Developer Tools)
  2. If you open a .dart file, then restart/reload, does the error go away? I'm wondering if it happens when the task is found before the extension is activated (or if maybe there's a race there)

For some reason, for me, it only found the task (and prompted to enable auto-running) when I first tried to run it, which means the extension had already had plenty of time to load.

@HerrNiklasRaab
Copy link
Author

Hey @DanTup,

  1. No Errors in Console
  2. I opened a dart file, and then I restarted VS Code, but I get the same error.

For some reason, for me, it only found the task (and prompted to enable auto-running) when I first tried to run it, which means the extension had already had plenty of time to load.

About this, I am not 100% sure what you meant and if I should check and try to confirm this behaviour.

@DanTup
Copy link
Member

DanTup commented Mar 11, 2019

@HerrNiklasRaab I mean, it didn't pop up to say "Hey, this project has auto-start tasks, do you want to let them run?" until I invoked the "Run Task" command (it didn't find the task automatically at startup).

I approved the auto-run but still I can't reproduce the behaviour 🤔

Oh, hangon... If you change type: "pub" to type: "flutter" and reload, does it work?

(you shouldn't need to do that, but let me know if that fixes it, and I can improve it here)

@HerrNiklasRaab
Copy link
Author

Ok, I have news. Only when the a .dart file is open and active (the tab of the .dart file is active) the tasks are starting without any error.

To the result below of my previous post I got, because I opened a .dart file and switched to another tab

I opened a dart file, and then I restarted VS Code, but I get the same error.

Could you try to open my project without any tabs or files open, while restarting?

@DanTup
Copy link
Member

DanTup commented Mar 11, 2019

I did that, but it still runs them. I even collapsed all of the folders in explorer. It seems to always activate the extension (I can see "No devices" in the status bar) despite that.

When you see this issue (eg. no dart files open), do you see "No devices" in the status bar and Dart listed if you run the "Show running extensions" command?

Also - you're testing by opening dev.code-workspace, right? Are you on v1.31 or v1.32 of VS Code?

@DanTup
Copy link
Member

DanTup commented Mar 12, 2019

Ok, I can repro on Windows :)

@DanTup DanTup added is bug on windows in commands Relates to commands (usually invoked from the command Palette) and removed awaiting info Requires more information from the customer to progress labels Mar 12, 2019
@DanTup
Copy link
Member

DanTup commented Mar 12, 2019

Ok, I think I've gotten to the bottom of this. It's a race condition, and it happens because the task may try to run before the extension is loaded. The MS sample for task providers activates with this command:

"onCommand:workbench.action.tasks.runTask"

Adding this fixes it, however this seems like an insane fix to me - it means the extension activates whenever anyone wants to run any task. I'm going to see if I can find a better way - since VS Code knows if the extension is going to contribute tasks (they're in the manifest) I don't see why we should need this.

@DanTup
Copy link
Member

DanTup commented Mar 12, 2019

Ok, I'm waiting to hear back on microsoft/vscode#70303 before doing any more on this. In my opinion this is a bug - it should not be necessary for an extension that uses tasks to have to activate whenever the user runs any task in VS Code (especially given they don't seem to want to give us an activation reason).

I hope we could have a more restricted activation event (eg. onTask:pub).

@HerrNiklasRaab
Copy link
Author

Sounds great! 👍

@DanTup DanTup added the blocked on vs code / lsp / dap Requires a change in VS Code to progress label Jun 11, 2019
@DanTup DanTup added this to the v3.16.0 milestone Oct 1, 2020
@DanTup DanTup modified the milestones: v3.16.0, v3.17.0 Oct 26, 2020
@DanTup DanTup added this to the Backlog milestone Nov 2, 2020
@DanTup
Copy link
Member

DanTup commented Nov 12, 2020

Tidying up open issues - I believe the remaining issue here is entirely VS Code's (linked above) and if/once that's fixed, it should work here to without any changes in the Dart extension.

@DanTup DanTup closed this as completed Nov 12, 2020
@DanTup DanTup added upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries and removed blocked on vs code / lsp / dap Requires a change in VS Code to progress in commands Relates to commands (usually invoked from the command Palette) is bug on windows labels Nov 12, 2020
@DanTup DanTup removed this from the Backlog milestone Nov 12, 2020
@DanTup
Copy link
Member

DanTup commented Dec 8, 2021

I think between a fix made in microsoft/vscode#70303 and microsoft/vscode#126238, this should be fixable now, though requires us to adopt the new onTaskType: activation event.

@DanTup DanTup reopened this Dec 8, 2021
@DanTup DanTup added is enhancement and removed upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries labels Dec 8, 2021
@DanTup DanTup added this to the v3.30.0 milestone Dec 8, 2021
@DanTup DanTup added the in tasks Relates to VS Code tasks, such as those provided by Task Providers label Dec 8, 2021
@DanTup DanTup modified the milestones: v3.30.0, v3.31.0 Dec 8, 2021
@DanTup DanTup modified the milestones: v3.34.0, v3.36.0 Jan 20, 2022
@DanTup DanTup closed this as completed in a730528 Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in tasks Relates to VS Code tasks, such as those provided by Task Providers is enhancement
Projects
None yet
Development

No branches or pull requests

2 participants