Skip to content

Enable globs on tasks otherwise fallback to default - fixes #88106#141230

Merged
alexr00 merged 14 commits intomicrosoft:mainfrom
jasonwilliams:addGlob
May 3, 2022
Merged

Enable globs on tasks otherwise fallback to default - fixes #88106#141230
alexr00 merged 14 commits intomicrosoft:mainfrom
jasonwilliams:addGlob

Conversation

@jasonwilliams
Copy link
Copy Markdown
Contributor

@jasonwilliams jasonwilliams commented Jan 23, 2022

This PR fixes #88106

VSCode supports isDefault which is useful when working on a single project but begins to fail on a monorepo or workspaces. Developers want to be able to change the default task depending on what part of the project they're in, and doing this in settings can get cumbersome. This provides the ability to switch default task based on the matching glob of the active file.
Previous behaviour is the same if no glob is provided or no glob matches.

This PR isn't perfect but its 90% of the way there, im sure there's areas I haven't properly covered.
I needed to comment out some of the schema because it kept moaning when I added glob to group.

Gif
glob

In this gif I set a glob,

  • if the glob matches it will run that task automatically (globs have a higher priority than defaults).
  • Then I remove the glob and it falls back to asking which task to run because there's 2 build tasks set.
  • Then I remove "build" from the top task and it runs "blah" because its the only build task there

@alexr00 feel free to modify this if you need to add changes for it to go in.

Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I've added some comments. This will need to go through our API review process first, as the Tasks json schema is partially mirrored in the Tasks extension API, meaning that anything added to the schema has the potential of one day becoming extension API. I will start that process in February.

@alexr00 alexr00 added this to the February 2022 milestone Jan 24, 2022
@jasonwilliams
Copy link
Copy Markdown
Contributor Author

@alexr00 thanks for reviewing. In your opinion do you think glob is in the right place? Or should it be at the top level task Object?

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Jan 24, 2022

@jasonwilliams I'm on the fence. On the one hand, the glob is a grouping mechanism. On the other hand, group has only ever meant build and test. I lean slightly toward having it on the task object; however, I would recommend you wait to make any changes to where glob is until we have started the API review process since that will help determine where glob should be.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

@alexr00 I've added in the changes you've asked for

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Feb 3, 2022

Thanks for the changes! I noticed that runBuildCommand and runTestCommand have diverged (not your fault), so I refactored them to reduce the code to review. No further changes requested right now. I'll have a new update for you on the API next week.

@alexr00 alexr00 modified the milestones: February 2022, March 2022 Feb 22, 2022
@jasonwilliams
Copy link
Copy Markdown
Contributor Author

Hey @alexr00 im guessing this will hopefully role into the march release. Do you know when it gets reviewed?

Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@jasonwilliams thank you for your patience! I have had a lot of API to work on recently and we haven't had time to go through all of them every week. I have added a comment based on the API feedback I received.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

Hey @alexr00 I've rebased and added updates. I've tested and it's still working as expected.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

jasonwilliams commented Mar 25, 2022

@alexr00 i do need your help on something. https://github.com/microsoft/vscode/runs/5694971126?check_suite_focus=true fails because I needed to change this check to be triple equals on true. Otherwise all tasks with isDefault will return (even if the value is a glob string). I have a feeling this is not behaviour we want.

However the test seems to use a stringified "true" statement.
I don't know why anyone would ever pass through true as a string and want it to work.

So do we change the test or the code? I could remove that triple equals and the functionality should still work but wondered if that approach is a good idea.

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Mar 28, 2022

@jasonwilliams that's a bug in the test, it should not be 'true', but true as you said.

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Mar 28, 2022

I've removed the API changes since we didn't go through full API review and the original feature request doesn't include a request for the API changes.

Everything else looks good. I will test this week and merge.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

Sounds good @alexr00 I'm guessing now v1.66 is shipped it's is a good time for this to go in. Let me know if i need to write up any documentation for the release notes or anywhere.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

jasonwilliams commented Apr 6, 2022

Rebased, and did some final checks, I actually found a bug.
If there are 2 tasks with globs matching and 1 task which has default: true, the default task would run ignoring the glob.
My latest change fixes that.

So order of precedence is (for both test and build):

  1. globs have highest priority (assuming there's a match)
  2. If 2 glob tasks match the quickPicker will show tasks you can run
  3. If 2 glob tasks don't match the quickPicker will show tasks you can run
  4. "isDefault": true has second highest priority (if there's no glob match)
  5. if none of the glob tasks match then the isDefault task will be ran as a fallback
  6. "isDefault: glob|true" if there's no other task matching the same build type. In other words, even if the glob doesn't match this task will run if its the only task set

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

pings @alexr00

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Apr 25, 2022

I'm not going to be able to get to this for April. I will look at it first thing after we have branched for release next week though.

@alexr00 alexr00 modified the milestones: April 2022, May 2022 Apr 25, 2022
@alexr00
Copy link
Copy Markdown
Member

alexr00 commented May 2, 2022

@jasonwilliams I reviewed and tested today. I found an issue where the glob doesn't work when there's only one glob that matches. I fixed it with 1bbc930. My test tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo txt",
            "type": "shell",
            "command": "echo TextFile",
            "group": {
                "kind": "build",
                "isDefault": "**.txt"
            }
        },
        {
            "label": "echo js",
            "type": "shell",
            "command": "echo JavascriptFile",
            "group": {
                "kind": "build",
                "isDefault": "**.js"
            },
        }
    ]
}

Then I opened a folder with a file.txt and file.js in it. If you have a chance, please take a look at that commit and make sure it's still consistent with what you're expecting. I plan to merge the PR tomorrow.

Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Tested and made a few style/name changes, as well as one bugfix.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

Thanks @alexr00
Are there any blockers to this being merged? Or has the release not been cut yet?

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented May 3, 2022

@jasonwilliams nope, no blockers. Just wanted to give you a chance to review my changes if you wanted.

@alexr00 alexr00 merged commit e19f097 into microsoft:main May 3, 2022
@jasonwilliams
Copy link
Copy Markdown
Contributor Author

jasonwilliams commented May 3, 2022

@jasonwilliams nope, no blockers. Just wanted to give you a chance to review my changes if you wanted.

@alexr00 my apologies, I missed your message above so I didn't test it. But i can take a look at insiders and test there. Thanks for helping me put this feature through.

@jasonwilliams
Copy link
Copy Markdown
Contributor Author

@alexr00 I was surprised to see no mention of this feature in https://code.visualstudio.com/updates/v1_68#_engineering or the documentation for tasks https://code.visualstudio.com/docs/editor/tasks

Will it be added there? It seems a bit of a hidden feature at the moment

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Jun 10, 2022

@jasonwilliams thanks for the ping. Not including this in the release notes was an oversight: microsoft/vscode-docs#5401

I will update the docs to include this feature soon.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to set default tasks based on file extension (or glob)

2 participants