Run a specific launch from task in vscode - visual-studio-code

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}"
},
]
}

Related

How to debug a Singer Tap using VS Code

In creating new Singer Taps using the Meltano SDK, it's not always clear how to setup testing in VS Code.
What's the best way to get the VS Code test features working?
First Method: Unit testing with VS Code "Tests" pane
This method makes unit tests (pytest tests) easy to run in the VS Code "Tests" pane.
Prereqs:
Python is installed on your machine.
The Python VS Code extension is installed.
You've run poetry install at least once.
You've set the Python interpreter to the Poetry environment via: "Command Palette" > "Python: Select Interpreter" and then select the matching Poetry environment.
Once the above are complete, the "tests" pane should populate with the list of unit tests and you'll have an option in the VS Code GUI to "Run" or "Debug" each test.
Second Method: Integration test by actually invoking the tap
This method actually runs your tap and sends the output to target-json or a similar sample target.
Prereqs:
Add a main to the bottom of your tap.py to make it invocable:
if __name__ == "__main__":
TapGoogleAnalytics.cli()
Install target-jsonl via pipx install target-jsonl or similar.
Replace tap_foobar with the actual name of your tap's library and then paste this into VS Code's launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/tap_foobar/tap.py",
"console": "integratedTerminal",
"args": ["--config", ".secrets/config.json", "|", "target-jsonl"],
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}

How to run GNU-Prolog on VSC?

I'm new to using VSCode and also I'm learning Prolog so I want to know how to run it from the editor.
I'm on windows and I already activated the enviroment variable LINEDIT=gui=no so when I call C:\GNU-Prolog\bin\gprolog.exe it runs on the shell.
to open a file you have to run in the prolog terminal:
changedirectory(DirectoryPathName). to go to the file's directory and
[file] to open it.
I don't know how to translate that into the VSC settings so I can use it to run Prolog.
Any help is appreciated!
Something like defining a task in your tasks.json file. For version 1.5.0 of VSC:
{
"version": "1.5.0",
"tasks": [{
"label": "my echo test",
"command": "echo", // Could be any other cmd
"args": ["test"],
"type": "shell"
}]
}

VSCode build task with dependsOn does "nothing" when gulp is installed. No output. How can I find the error?

I'm having problems with my VSCode installation, and I need some help to detect the cause of the error(s).
In one of my projects, I cannot (for some reason) execute any task that have "dependency tasks" defined. This is my .vscode/tasks.json file (created just to illustrate the problem):
{
"version": "2.0.0",
"tasks": [
{
"label": "subtask1",
"type": "shell",
"command": "echo This is a subtask"
},
{
"label": "all",
"dependsOn": [
"subtask1"
]
}
]
}
The task subtask1 runs fine. The output is "This is a subtask".
However, the task all does not run. When I select it from the list of tasks to run, nothing happens. The terminal output remains unchanged (whatever output was already there, remains).
Whatever I name the tasks, doesn't matter. It seems that any task will not execute if it has a "dependsOrder" property defined.
This problem only persists when gulp is installed in the project dir (using npm i gulp).
My question is :
How can I find the cause of this error and how can I fix it?
I've tried deleting the entire dir in %APPDATA%/Code, so the cache seems to be cleared. Then, I restarted VSCode. But the problem persists.

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 to find 'task runner templates' in 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.