How to find 'task runner templates' in Visual Studio Code? - visual-studio-code

Sorry if I am missing the obvious, but in the help page for Visual Studio Code tasks here: https://code.visualstudio.com/docs/editor/tasks the text says:
Select the Tasks: Configure Task Runner command and you will see a list of task runner templates. Select Others to create a task which runs an external command.
I don't see 'Others', I just see the following in tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "c:/Windows/sysnative/bash.exe",
"isShellCommand": true,
"args": ["-c 'cd /mnt/c/SVNProj/Leda/trunk/software/Source/LedaAP_win_linux; make'"],
"showOutput": "always"
}
How do I get to see the task templates?

I think it is bad behavior on vscode's part but I can only get the options presented after clicking on "Configure task runner" if there is NO tasks.json file. So if you already have a tasks.json file, rename it and try again. Then the templates will appear.

Related

Run a specific launch from task in vscode

When I open the project on vscode, I want it to start running in debug mode.
I have a lunch configuration in the launch.json file which starts the project in debug mode when I hit "F5".
In addition, I have a vscode task with the "runOptions": {"runOn":"folderOpen"} option.
the problem is: as much as I can tell, tasks can only run commands or other tasks.
is it possible to configure a command to run a specific "launch from the launch.json?
You can use the extension Launch Configs
In the extension settings (settings.json) you setup a command to start a launch config
"launches": {
"StartLaunch": "Start Launch (Project Folder)"
}
In you tasks.json call this task with a variable ${command:commandID} somewhere in the task strings.
${command:launches.StartLaunch}
You can use a dummy shell echo task
This can work if you're happy to launch the currently selected one just as F5 would do when you aren't already debugging:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "my-debug-trigger-task",
"type": "shell",
"command": "${command:workbench.action.debug.start}"
},
]
}

Visual Studio Code SASS compiler

I switch from Sublime to VS Code because it anymore PHP and SASS support. I mostly use CSS & SASS & JS & PHP.
I set up a SASS compiler from VS Code documentation. As follows:
// Sass configuration
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sass Compile",
"type": "shell",
"command": "node-sass style.scss style.css",
"group": "build",
"problemMatcher": [
"$eslint-compact"
]
}
]
}
I tested it working properly. But I have 2 problems:
First of all, it focuses on "style.scss" file. I mean, whatever we mentioned in ".json".
Actually what I want is: Focus on all ".scss" files without searching for a name.
When I run an compile with the "a.scss" editor open, it compiles only names in the ".json" file. But there not contain "a.scss"!
Actually what I want is: If I press the "CTRL + SHIFT + B" key and select the corresponding option, the currently active editor is the "a.scss" compilation.
Are there any settings for these?
Note: "command": "node-sass .scss .css", it will give error.
Actual the situation is, that SASS actualized to a new version Dart SASS. There are new rules like #use in it ... so the used compilers needs to be updated.
As I know up to now Node Sass did not.
The better way to use SASS in VS Code is to use an extension.
As we had this several times:
If you are interessted in it you may look here https://stackoverflow.com/a/66207572/9268485
Note: if you decide to use one of the extensions your settings may change. Have a look to the extensions descriptions.

Configure Visual Studio Code to have a default Build Task based on file extension

I would like to know if there is a way to define a default Build Task for VSCode depending on file extension.
When working in some folder of Python code, I define the following Build Task:
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"showOutput": "always",
"args": ["${file}"]
}
Then if next time I go to another Python folder, I have to redefine it again.
Is it possible to configure VSCode in such a way that if it detects the current file as a Python script, then it will automatically define the above Build Task?
Thank you in advance for your help!
Update for latest vscode
The following will create a default "build" script, so you can use the keyboard shortcut to build your project. (Below for a javascript project, but shows general outline for other languages/projects.)
(1) Assuming you have a script named "build.js" at the root of your project.
(2) Create a file named "tasks.json" in root of project (workspace) with the following contents:
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "mybuildscript", // use same name as in package.json
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
(3) In your package.json, add "scripts" as:
// package.json
{
"name": "my",
"version": "1.0.0",
"description": "",
"scripts": {
"mybuildscript": "node ./build.js"
},
"dependencies": {
"myfs": "^1.0.22"
}
}
I created a rudimentary vscode extension that does all this for you:
https://marketplace.visualstudio.com/items?itemName=gieson.make-build-task
The extension isn't perfect (doesn't cover all the possible ways a project/workspace can be configured), but it's a good starting point.
Here's the repo:
https://github.com/bobtherobot/make-build-task
This is possible, but it requires writing an extension (unless somebody has already written one with a tasks provider for Python). Since 1.14.0, there's a new API which allows extensions to dynamically provide tasks. Check out the Task Provider Example.
Alternatiely, the Code Runner extension probably does the trick in this case as well. It doesn't use the Tasks system though.

How automatically compile jsx or tsx to js into visual studio code?

How automatically compile react jsx or tsx to js into visual studio code?
Is a task runner needed? or just a configuration into jsconfig.json?
What I already tried:
I already tried to create a jsconfig.json with jsx parameter without success.
I configured a TS compiler, however it compiles only TS to JS, not JSX to JS.
I'm wondering if there any configuration that makes this conversion without need to configura a run task. , for instance "compile on save" like the Full Visual Studio.
You may add
[
{
"key": "ctrl+s",
"command": "workbench.action.tasks.build"
}
]
to keybindings.json
and create file tasks.json
{
"version": "0.1.0",
"command": "webpack",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}

VS Code - Failed to launch external program tsc.exe

I keep getting the "Failed to launch external program tsc.exe" in VS Code. I have installed typescript and set my path to where tsc.exe is located. Any suggestions
Here is my task file
// The command is tsc.
"command": "tsc",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
"command": "tsc.exe"
},
// args is the HelloWorld program to compile.
"args": ["HelloWorld.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
You should try to install tsc this way:
npm install -g typescript
And then change tasks.json to:
...
"windows": {
"command": "tsc.cmd"
},
"args" : ["Myfilename.ts"]
...
And everything should work as expected, also, try to read this:
https://code.visualstudio.com/Docs/tasks
Well,
I came up with my own solution to generate modified version of tasks.json each time you config task runner(CTR), but I don't know if this is a really good pratice as VSCode is brand new I've not found a better solution, If anyone knows how to change CTR in the proper way PLEASE let me know!
There is a file called taskSampleConfig.json that is parsed everytime CTR runs, and this file is inside VSCode folder, so you may change it to:
...
"windows": {
"command": "tsc.cmd"
},
...
Since I can't comment yet I post it as an answer:
Since tsc.cmd must be executed in a command interpreter you need to configure it like this:
"windows": {
"command": "tsc",
"isShellCommand": true
}
The taskSampleConfig.json file is basically used as a template if VSCode can't auto detect a task runner. There is currently no support to customize the templating.
For me it works that way (Using VSCode in Admin-Mode on Win8):
Installing Typescript via npm (as jrabello wrote)
Setting up the task like this:
"version": "0.1.0",
"command": "tsc",
"showOutput": "silent",
"isShellCommand": true
Creating a tsconfig.json for your project with the compiler-options you need:
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true
}