VS Code - Failed to launch external program tsc.exe - visual-studio-code

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
}

Related

How to set up tasks.json file in VSCODE to compile Fortran programs?

I want to set up VScode (OS: Windows 10) to create and then compile programs written in Fortran 90/95. I can do this by typing in the terminal : gfortran -o Example_exe Example.f90 and then ./Example_exe. I don't want to have to write these lines every time, so I tried to set up my tasks.json file to automate a build routine using gfortran as compiler.
I found this tutorial : https://titanwolf.org/Network/Articles/Article?AID=360e0bde-0507-4de4-960c-2eae8fa8c782#gsc.tab=0 but the tasks.json file given is unclear.
Can I have a tasks.json file setup to automate my build routine please ?
I have installed the following extensions : Modern Fortran, Fortran IntelliSense, Code Runner, Fortran Breakpoint Support
Yes you can. Assuming that you want to execute in debug mode, you should create a tasks.json and a launcher.json and place them in .vscode/ at the root of your workspace.
Assuming the following file structure and a debugging mode with GDB for the execution:
root/
.vscode/
code/
Example_exe
This is what your tasks.json should look like:
{
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "gfortran -o Example_exe Example.f90 -g",
"options": {
"cwd": "code/"
}
}
]
}
And then, the launch.json, which will identify tasks.json as a "preLaunchTask".
{
"version": "0.2.0",
"configurations":[
{
"name": "Run my example",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\code\\example_exe.exe",
"args": ["],
"stopAtEntry": false,
"cwd": "${workspaceFolder}\\code",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "compile",
}
]
}
Launch the debugger by pressing F5 (or in the Run menu).
If you don't want to run in debug mode, have a look at this issue.
Sources:
How to build and run C++ code in Visual Studio Code?
awesome tutorial (for ubuntu, working for me with VSCode-gfortran-Win10)
https://www.youtube.com/watch?v=Rj-kYb9nZ3g&ab_channel=LukasLamm.

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

Visual Studio Code launch.json file for JUnit?

Can someone point me toward a sample launch.json file for JUnit 4 so I can run tests from Visual Studio Code? I am unable to find an example of this online and all attempts to create one have failed.
I am able to run tests manually from the command line. (FWIW, I'm using CentOS.) Here's what I do to run them:
cd /opt/ABBYY/FREngine12/Samples/Java/Hello_VSC/src/test/java
java -cp .:/opt/junit/junit-4.12.jar:/opt/junit/hamcrest-core-1.3.jar org.junit.runner.JUnitCore Hello.AppTest
My Java project is set up to support Maven (I'm not really using Maven -- I've only set it up with Maven because Java debugging in Visual Studio Code will not work without it). So in the .classpath file I've added the following entries, which should add the .jar files from my command line call to the code path:
<classpathentry kind="lib" path="/opt/junit/junit-4.12.jar" />
<classpathentry kind="lib" path="/opt/junit/hamcrest-core-1.3.jar" />
When I try to set up the launch.json file, I'm attempting to do something like this:
{
"type": "java",
"name": "Test-<Hello_VSC>",
"request": "launch",
"cwd": "/opt/ABBYY/FREngine12/Samples/Java/Hello_VSC/src/test/java/",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "Hello.AppTest",
"projectName": "Hello_VSC",
"args": "org.junit.runner.JUnitCore Hello.AppTest",
},
However, I get this error message:
Error: Main method not found in class Hello.AppTest, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Even if I change cwd to a completely bogus directory, I get the same error message. I don't know if my type parameter is wrong, my cwd parameter is wrong, or if it's something else.
Any suggestions?
Never mind -- I figured it out. I guess I had everything set up correctly with my project, but didn't realize that the proper way to run tests with the Java extensions for Visual Studio Code was to simply click on the Explorer (file) icon, then expand the "Test Explorer" option, explore down to whatever test(s) you want to run, right-click, and then choose your testing options. There is no need to use the launch.json file to do this.
If you search for tasks.json (instead of launch.json), you will get this example
/*
Example for quick Java compilation and unit tests in VS Code.
Works well with simple BlueJ projects.
Hit Ctrl+Shift+B to compile currently open file with javac.
Hit Ctrl+Shift+T to test currently open test class.
See red wiggles for compilation errors / failed assertions or click exclamation mark in the status bar.
Uses a few workarounds for individual commands per task and filename without extension.
This is written for Windows but it should be easy to adopt for Linux and Mac.
*/
{
"version": "0.1.0",
"isShellCommand": true,
"suppressTaskName": true,
"showOutput": "silent",
"windows": {
"command": "powershell",
"args": ["-Command"],
"tasks": [
{
// tests the currently open test class. java has to be in %PATH% and the jUnit-jar in %CLASSPATH%.
"taskName": "junit",
"args": ["$env:CLASSPATH += ';${fileDirname}'; $class = [System.IO.Path]::GetFileNameWithoutExtension('${fileBasename}'); java org.junit.runner.JUnitCore $class | Select-String -NotMatch -Pattern 'at (?!.+${fileBasename})'"],
"isTestCommand": true,
"problemMatcher": {
"owner": "java",
"fileLocation": ["relative", "${fileDirname}"],
"pattern": [
{
"regexp": "^(.*)$",
"message": 1
},
{
"regexp": "^\\s*at .+\\((.+):([0-9]+)\\)$",
"file": 1,
"line": 2
}
]
}
},
]
}
}
But it is in "0.1.0", so you will have to convert it to 2.0.0 first.

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