I have recently discovered that there a gms extension in visual studio code so you can write your GAMS code there. The description of the extension says following:
Provides syntax highlighting for .gms and .inc files and shortcuts for running GAMS models
I wonder if it is possible to actually run your GAMS code from Visual Studio Code?
Yes. You have to do this from the terminal.
You can set up a default build task (shown below) for the current opened file (${fileBasename}) and run with ctrl+shift+b. It's possible to add arguments to the "args" array, i.e. gdx=default etc.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run this file with GAMS",
"type": "shell",
"command": "gams",
"args": [
"${fileBasename}"
],
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"env": {
"PATH": "/opt/gams:${env:PATH}"
}
}
}
]
}
Related
How can I see the values of the Variable References in Visual Studio Code (e.g ${workspaceFolder}/${workspaceFolderBasename} and so on) - the full path of them?
It is in the Variables doc page.
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo ${workspaceFolder}"
}
]
}
I had a custom build system in sublime for C++ which takes input from one file and redirects the output to another.
My sublime build system is as follows :
{
"cmd": ["g++.exe","-std=c++14", "${file}", "-o", "${file_base_name}.exe", "&&" , "${file_base_name}.exe<inputf.in>outputf.in"],
"selector":"source.cpp",
"shell":true,
"working_dir":"$file_path"
}
this helped in taking input from "inputf.in" file and print the output in "outputf.in" whenever i ran my program.
I want similar functionality in vs code but dont know how to configure build-task.
Here is a build task for a Node addon, you have to put it in .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "npx node-pre-gyp build -j max",
"problemMatcher": {
"base": "$gcc",
"fileLocation": [
"relative",
"${workspaceFolder}/build"
]
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
You can press Ctrl-Shift-P to bring the command palette and select configure build task.
The problem matcher allows VSCode to highlight the compiler errors in your editor.
The default build task is the one you launch with a hotkey.
As, my title suggests I want to hard-code my output file name, instead of the default one, where it is named after the file.
This is my tasks.json file in VS Code:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
From this documentation https://code.visualstudio.com/docs/cpp/config-clang-mac, I found a method of doing it, i.e. by replacing "${fileDirname}/${fileBasenameNoExtension}" with a hard-coded filename (for example "${workspaceFolder}/myProgram.out"). But, this is not working for me, I still get the default one. Should I be changing someother configuration along with this?
This executable with file name fills the VS Code Explorer section with repeatitive stuffs and this creates confusion. I found some methods to hide files with certain extensions like .out, .json etc, but the issue is executable file in VS Code(Mac) doesn't have any file extension.
I'm working on a C project that should compile under both Linux and MacOS using their respective compilers. I have installed the C/C++ extension in VS Code and I would like the compilation task in tasks.json to pick up the right compiler based on the OS I'm currently on.
If, in my c_cpp_properties.json file I have the following (I removed the irrelevant elements):
{
"configurations": [
{
"name": "Mac",
"compilerPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
},
{
"name": "Linux",
"compilerPath": "/usr/bin/gcc",
}
],
"version": 4
}
Would it be possible to refer to the compilerPath variable in tasks.json? And especially without having to state which OS-based configuration? What I 'd like to do is this:
"tasks": [
{
"label": "compilation",
"type": "shell",
"command": "${config:compilerPath} -g main.c"
}
]
I am trying to define a VSCode task in tasks.json that would adapt to the specific architecture where VSCode runs. To do this, I want to get the architecture as uname --m (e.g. "aarch64" or "amd64"). My goal is to interpolate the output of uname into an environment variable like so
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cmake",
"args": [
"-DMYLIB_INCLUDE_DIR=$MYLIB/include",
"-DMYLIB_LIBRARY=$MYLIB/lib"
],
"options": {
"env": {
"MYLIB": "${workspaceFolder}/mylib/${command:get_arch}"
}
},
}
]
In my case, I will have architecture-specific versions of mylib under mylib/aarch64, mylib/amd64, etc.
My attempt so far as been to define a second get_arch task used in the environment definition of MYLIB, that simply runs uname.
{
"label": "get_arch",
"type": "shell",
"command": "uname --m"
}
Of course, this task is not a proper command and so it isn't detected by VSCode and my build task fails. I checked out the documentation on variable substition, but they don't mention if it's possible to substitute a shell command. I guess this would be possible from within an extension, but I want to keep things as simple as possible.
This extension provides a way to launch arbitrary shell commands as a VS Code command:
"tasks": [
{
"label": "test_arch",
"type": "shell",
"command": "echo",
"args": [
"${MYARCH}"
],
"options": {
"env": {
"MYARCH": "${input:get_arch}"
}
},
"problemMatcher": []
},
],
"inputs": [
{
"id": "get_arch",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "uname -m"
}
}
]
One disadvantage I discovered is that you have to press Enter once more when the result of the command is prompted in picker. Aside of this, this is the straightest way to implement what you want, and yet it can be utilized in many similar situations.
Alternatively, you can add pickString input with arch picker or create an extension that adds only single command GetArch.
If you don't want to press enter every time, you can add the option useFirstResult: true in the args section.