microsoft/vscode

Shared configuration (tasks/settings)

nevir opened this issue ยท 35 comments

nevir commented

I have a suite of projects that I'd like to have a shared configuration (e.g. all the repos at my company).

Currently we have duplicate .vscode/settings.json files, and several common .vscode/tasks.json tasks. Some projects have additional tasks defined beyond the common ones.


I'm unsure what the right approach to take here is. I'd love some input

  • Can extensions apply user settings, or define tasks/problem matchers? The docs don't seem to indicate that.
  • Can a project declare a VS Code extension as a dependency? (seems unlikely, but hey :P)
  • We're toying with the idea of a common package with a postinstall script that symlinks the configuration in (and just over-defining tasks) - but it's pretty ugly.

We have gaps when it comes to managing many projects and sharing among them and the answer to your question is currently not supported, sorry, but we have it on the backlog to improve this.

Are your tasks/problem matchers mostly for supporting build tasks for a particular language?

Having support for workspace - extension dependencies is on our radar.

When it comes to sharing across projects you can consider something similar as we do for extensions. A yeoman generator generates the initial setup and shared tooling code comes from a node module in our case the vscode node module.

nevir commented

Are your tasks/problem matchers mostly for supporting build tasks for a particular language?

Yeah - currently we've got ESLint, TAP problem matchers - the thing is that we're running them via a custom gulp task that wraps each task and only runs a subset of checks at a time. It necessitates somewhat heavy watching.beginsPattern/watching.endsPattern and other settings.

(using off the shelf problem matchers doesn't save much)

Having support for workspace - extension dependencies is on our radar

Awesome!

What isTAP?

CC @dbaeumer

Currently you cannot contribute problem matchers through an extension, so if the problem matchers are generally useful we could add them to set. Could you consider a PR?

TAP is a test runner. ava is what I'm using now. ๐Ÿ‘ , over mocha

[Addressed in new terminal runner]

This will largely be addressed with the new runner. There extension can contribute tasks which makes creating a tasks.json file for standard tasks unnecessary. For example the C# extension can contribute a standard task to compile C# files.

Since 1.10 extensions can also contribute probem patterns and problem matchers.

Since a longer time workspaces can prereq extensions using extension recommendations.

Has this been addressed already? My concern is defining "global" tasks in extensions, but in a broader sense is:

Can extensions apply user settings, or define tasks/problem matchers?

With the May release an extension can defined problem matchers and tasks (problem matchers is already available sine Feb.)

I am not sure if this is the correct issue to post my comment but it seems pretty close.

I am looking for something like what Sublime Text does. In Sublime Text, you can define a "build system" which may be associated with a file extension. The build system is a user-defined shell command. You can then build a file with your build system without having to have a project or workspace set up. However when I try to do the same thing in vscode using "build tasks", I get an error saying "Tasks are only available on a workspace folder". I don't want to have to create/open a workspace folder if I want to build a simple script.

Could you possibly imitate the functionality of Sublime Text?

@kodos84 Please follow https://github.com/Microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions to submit a new feature request.

@kodos84 Did you file the feature request as suggested by @mikelward ? I'm also interested in this functionality, so I'd be grateful if you let me know. Thanks.

@sumproxy I created the feature request here: #32429

@kodos84 thank you

stnwk commented

Is there any progress on this?

16 updates from #9664.

It would be nice to put a few common simple tasks in a tasks.json file located in the Users settings folder that could be merged with the workspace tasks.json file. An example would be to run a NodeJS script from anywhere using a common keystroke binding, e.g.

{  
    "label"  : "Run NodeJS Script",  
    "type"   : "shell",  
    "program": "node \"${file}\""  
     }  

with a keybinding of:

{
    "key"    : "cmd+shift+n",
    "command": "workbench.action.tasks.runTask",
    "args"   : "Run NodeJS Script"
    "when"   : "editorTextFocus"
     }

BTW: It seems that VSCode does attempt to merge tasks from subfolders. I tried the dubious scenario of putting my .code-workspace file in my home directory on Windows, causing it to search through the symbolic links (yes, Windows has them) that I have in my Desktop and Documents folders. It took awhile to search many node_module folders, before it found this "task", i.e. file, .\build\assets\vendors\moment\typing-tests\tsconfig.json, 13 times as a result of it being embedded in a node module, named CleanUI from Mediatec Software, a few years back.

When picking the Run Task... menu item, or running the task, "Run NodeJS Script", with "cmd-shift-n", it took over 2 minutes for VSCode to obey my command.

@robinmattern: Yes, I agree. To support a global tasks.json file located in the Users settings folder would be very handy!

I can think of several levels of configs:

  • Environment global config:
    • useful when multiple users login to the same environment and these configs are common to all workspace/project
  • User global config
  • Workspace user config
  • Project user config
  • Workspace team config
  • Project team config

I'd love to be able to define global tasks (such as the global launch.json) in the user settings as well.

Got fed up copying the same files to each workspace, so I've created the following extension:
https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.global-config

Hopefully others might find it useful in the short term...

Yeah, I often create Docker containers for my web projects or for scripting languages like Ruby and so often times I use the same docker commands to run the project-specific Dockerfile and Docker-compose.yml files and so to have a global task that just builds and runs the Docker-compose.yml file or Dockerfile in the project directory would be extremely useful. rather than have to copy virtually identical tasks.json files into each projects .vscode/ folder.

sipi commented

My use case :

  • I defined a default build task for exporting my org-mode (.org) file into pdf
  • I would like this task available for all my .org files without having to create an extension

If I understand well this discussion, it's not available yet. I should create an extension, is that right?
From the documentation, I need to know something about node.js to build an extension. It seems complicated for something which could be done by declaring this task.json global.

I'm really not a Microsoft addict, but I must say that VSCode is a great editor. I said bye to Emacs because of it. I liked it, but it was a pain to configure...

Thanks

It would be really useful if it was possible to run tasks from other project folders from within a workspace, i.e. dependency management.

For example, if I have Application and Library as two project folders within a workspace, I would like to be able to tell the Application build task that it "dependsOn" : [ "_Library_":"MyLibBuildTask" ] where _Library_ is the project folder name in the workspace. Something along those lines anyway.

If I have missed something and this is already possible, please let me know how!

Thanks

Xjs commented

I'm confused by the discussion here. Are global tasks still on the agenda, or should they be provided by extensions now? Can we get an official statement on this? From me, +1 for global tasks.json!

Global tasks in a task.json file are still on the agenda (to get parity with launch.json). However it is a matter of priorities when they will come.

I am having quite a lot of bash/python/scala files which is just a single independant file.
Sublime Text's Build System works perfectly for this purpose, with just a simple Cmd/Ctrl + B to run any file. Making tasks in VScode for every of those files is just annoying.

Definitely, it is necessary as oxygen

My use case is Rust development. I keep copying tasks.json in every crates I'm working on just to have cargo check and cargo test available.

Technically It can be made with VSCode Active Buttons extension (https://github.com/SeunLanLege/vscode-action-buttons.git) since settings.json is a global file. But you will get extra GUI buttons which maybe not cool for some developers.

I really can't wait for it. Global tasks will be very useful. I miss this

Maybe it would be a good idea?
#38162

If not, maybe something similar?
I think that's a good direction. You can be inspired by this.

A tasks.json next to your user settings.json is now supported! No commands to create this for you yet, but I'll add something. It only supports tasks version 2.0.0 and type shell and process tasks.

A tasks.json next to your user settings.json is now supported! No commands to create this for you yet, but I'll add something. It only supports tasks version 2.0.0 and type shell and process tasks.
@alexr00 is this in:
Version: 1.41.0 (system setup)
Commit: 9579eda
Date: 2019-12-11T18:37:42.077Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.17763

This will be available in the next VS Code Insiders build: https://code.visualstudio.com/insiders/

@daniladyabin thanks for trying this feature in insiders and reporting the problem! I've pushed a fix to master and it should be in the next insiders build. Let me know if you have any other issues with this!