terminal.integrated.defaultProfile.windows should be an object - vscode 1.63 - visual-studio-code

In vscode 1.63 I'm seeing the error
Incorrect type. Expected "object".
for "terminal.integrated.defaultProfile.windows": "PS7"
even though the docs appear to show its a string
"terminal.integrated.profiles.windows": {
"PS7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": [
"-noexit",
"-file",
"${env:APPDATA}PowerShellmy-init-script.ps1"
]
},
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"icon": "terminal-cmd"
},
"GitBash": {
"path": [
"F:\\Program files\\Git\\bin\\bash.exe"
],
"icon": "terminal-bash"
},
"terminal.integrated.defaultProfile.windows": "PS7"
},

Related

VSCODE running conda activate script upon opening cmd terminal

Whenever I open a new cmd or powershell instegrated terminal the terminal runs the following:
D:\..\..\Programming> D:/miniconda3/Scripts/activate
(base) D:\Archive\Bachelor\Programming>conda activate optim
with output:
(optim) D:\Archive\Bachelor\Programming>
I have been searching for the setting to do this for days and can not turn it of.
There seem to be no setting specifing this behavior nor I ever added a configuration to do so.
Can somebody explain where this is coming from?
User Settings
{
"workbench.colorTheme": "Monokai Pro",
"[perl]": {
"editor.defaultFormatter": "cfgweb.vscode-perl"
},
"window.restoreWindows": "none",
"C_Cpp.autocompleteAddParentheses": true,
"editor.accessibilitySupport": "off",
"workbench.iconTheme": "Monokai Pro Icons",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"grunt.autoDetect": "off",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
},
"cmd": {
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": []
}
},
}
.vscode\settings.json
{
"python.analysis.extraPaths": [
"./Bachelor_Thesis_HOTRG"
]
}
.code-workspace
{
"folders": [
{
"path": "."
},
{
"path": "../writing"
}
],
"settings": {
"terminal.integrated.defaultProfile.windows": "Command Prompt",
}
}

How to pass input variable from launch.json to tasks.json in vscode

I can use input variables from launch.json in launch.json.
"configurations": [
{
...
"args": [${input:file_no}]
"preLanuchTask": "runPreTasks"
...
}
],
"inputs": [
{
"id": "file_no",
"type": "promptString"
}
]
Now, I want to get access to the same variable without entering input a second time in tasks.json.
{
"version": "2.0.0",
"tasks":[
{
"label": "runPreTasks",
"type": "shell",
"command": sh,
"args": [
"/path2script/scriptName.sh",
"${input:file_no}" // This does not work, without defining input again
]
}
]
}
Is there a way to pass input variables from launch.json to tasks.json in vscode?
You can use the extension Command Variable v1.21.0
It has a command extension.commandvariable.promptStringRemember that behaves the same as an ${input:name} promptString variable. By adding a key property the result is saved under this key and you can retreive it with the extension.commandvariable.rememberPick command.
The extension.commandvariable.rememberPick command can be used in a different task/launch than the extension.commandvariable.promptStringRemember command
{
"version": "2.0.0",
"tasks": [
{
"label": "Task 1",
"type": "shell",
"command": "dostuff1",
"args": ["-p", "${input:promptPath}"]
},
{
"label": "Task 2",
"type": "shell",
"command": "dostuff2",
"args": ["-p", "${input:rememberPath}"]
},
{
"label": "Do Task 1 and 2",
"dependsOrder": "sequence",
"dependsOn": ["Task 1", "Task 2"],
"problemMatcher": []
}
],
"inputs": [
{
"id": "promptPath",
"type": "command",
"command": "extension.commandvariable.promptStringRemember",
"args": {
"key": "path",
"description": "Enter a path"
}
},
{
"id": "rememberPath",
"type": "command",
"command": "extension.commandvariable.rememberPick",
"args": { "key": "path" }
}
]
}
Following #rioV8 answer, I edited my json files as shown below:
launch.json:
"configurations": [
{
...
"args": [${input:file_no}]
"preLanuchTask": "runPreTasks"
...
}
],
"inputs": [
{
"id": "file_no",
"type": "command",
"command": "extension.commandvariable.promptStringRemember",
"args": {
"key": "lastnumber",
"description": "Enter the number"
}
}
]
tasks.json:
{
"version": "2.0.0",
"tasks":[
{
"label": "runPreTasks",
"type": "shell",
"command": sh,
"args": [
"/path2script/scriptName.sh",
"${input:file_no}"
]
}
]
"inputs": [
{
"id": "file_no",
"type": "command",
"command": "extension.commandvariable.rememberPick",
"args": { "key": "lastnumber" }
}
]
}

Add a folder into a workspace by tasks in Visual Studio Code

Is there a way to add a folder into a workspace by tasks?
Is it possible to add and remove (or hide) folders in a workspace on selecting options from input in tasks.json?
{
"version": "2.0.0",
"inputs": [
{
"id": "selectProject",
"type": "pickString",
"description": "Some decription",
"options":
[
"PROJECT1",
"PROJECT2"
]
}
],
"tasks": [
{
"label": "add into workspace",
"type": "process",
"command": "command-to-add-folder-into-workspace", // what do I need to put here?
"args": [
"${input:selectProject}"
]
}
]
}
I've found a solution using code --add folder in tasks.
File .code-workspace
{
"folders": [
{
"name": "wp",
"path": "../wp" // folder has .code-workspace file
}
],
"settings": { /*...*/ },
"tasks": {
"inputs":[
{
"id": "selectProject",
"type": "pickString",
"description": "select project",
"options":
[
"PROJECT1",
"PROJECT2"
]
}
],
"version": "2.0.0",
"tasks": [
{
"label": "Add project",
"type": "shell",
"command": "code", // usind command code --add folder
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"--add",
"../${input:selectTest}"
],
"presentation": {
"echo": false,
"reveal": "always",
"clear": false,
"showReuseMessage": false
}
}
]
}
}

VSCode open terminal with directory does not appear to work

Having found the VSCode command workbench.action.terminal.newWithCwd
{
"key": "cmd+shift+alt+h",
"command": "workbench.action.terminal.newWithCwd",
"args": {
"cwd": "${fileDirname}"
}
}
I cannot get it to work.
I have inserted the JSON above into the ~\Code\User\keybindings.json file, but how do I actually get it to execute?
This works as a keybinding, using the macro extension multi-command:
{
"key": "alt+k", // whatever you want here
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
{
"command": "workbench.action.terminal.newWithProfile",
"args": {
"profileName": "Git Bash",
"shouldForwardArgs": true,
}
}
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "cd '${fileDirname}'\u000D"
}
}
]
},
"when": "editorTextFocus"
},
What I think should work is this profile in settings.json:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash",
"path": "C:\\Program Files\\Git\\git-bash.exe"
},
"Git Bash at fileDirname": {
"source": "Git Bash",
"path": "C:/Program Files/Git/git-bash.exe",
"args": [
"cd ${fileDirname}" // variables are supported here according to the docs
]
}
},
and then this associated keybinding:
{
"key": "alt+k",
"command": "workbench.action.terminal.newWithProfile",
"args": {
"profileName": "Git Bash at fileDirname",
"shouldForwardArgs": true
}
},
But it doesn't quite work for me. It almost works, but it says no such file exists. I see a couple of issues filed on variable resolution in profiles.

VSCode, Define custom variables to use in tasks, lauch and cpp properties

I am setting up VSCode for Embedded development with Nordic NRF52.
I have noticed that in the nrf_sdk there are examples for several boards and several soft devices.
I have seen that it is possible to reference env variables that have been previously defined both in tasks, launch and extension properties, such as: c_cpp, stm32-for-vscode. But what about having a section in the workspace file defined as my_vars so the workspace file looks like this?
{
"my_vars": {
"BOARD_NAME": "NRF52840_MDK_USB_DONGLE",
"MCU_NAME": "NRF52840",
"SOFT_DEVICE": "S140",
"BOARD_VARIANT_PATH": "/pca10059/mbr"
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc/_build/${my_vars:MCU_NAME}_xxaa.out",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "nrf52",
"interface": "swd",
"ipAddress": null,
"serialNumber": null,
"armToolchainPath": "${env:VSARM}/armcc/bin/"
},
]
},
"folders": [
{
"path": "."
}
],
"settings":{
// "C_Cpp.name": "nRF52840 DK",
"C_Cpp.default.includePath": [
"${workspaceFolder}/**",
"${env:GNU_GCC}/arm-none-eabi/include",
"${env:NRF_SDK}/modules/**",
"${env:NRF_SDK}/components/**"
],
"C_Cpp.default.defines": [
"${my_vars:BOARD_NAME}",
"CONFIG_GPIO_AS_PINRESET",
"INITIALIZE_USER_SECTIONS",
"FLOAT_ABI_HARD",
"NRF52",
"${my_vars:MCU_NAME}_XXAA",
"NRF_SD_BLE_API_VERSION=6",
"${my_vars:SOFT_DEVICE}",
"SOFTDEVICE_PRESENT",
"SWI_DISABLE0"
],
"C_Cpp.default.compilerPath": "${env:GNU_GCC}/bin/arm-none-eabi-gcc",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.intelliSenseMode": "clang-x64"
},
"tasks": {
"version": "2.0.0",
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"tasks": [
{
"label": "nRF52 build",
"type": "shell",
"command": "make",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 build clean",
"type": "shell",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 flash",
"type": "shell",
"command": "make flash",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 dfu upload",
"type": "shell",
"command": "make bootload",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 flash_softdevice",
"type": "shell",
"command": "make flash_softdevice",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "nRF52 sdk_config",
"type": "shell",
"command": "make sdk_config",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": []
},
{
"label": "nRF52 erase",
"type": "shell",
"command": "make erase",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
}
I tried having a task which is set_env, which in my case, since I am in Windows, run a batch script that does:
set BOARD_NAME=NRF52840_MDK_USB_DONGLE
set MCU_NAME=NRF52840
set SOFT_DEVICE=S140
set BOARD_VARIANT_PATH=/pca10059/mbr
This will ease a lot playing around with the SDK examples and could be potential work for a NRF52 VSCode extension, as https://marketplace.visualstudio.com/items?itemName=bmd.stm32-for-vscode does.
You've undoubtedly solved this problem by now, but hopefully I can save someone else some searching.
There is a top-level section called env that holds global variables that you can reference in your configs.
Here's an example from MSDN.
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/gcc-7"
},
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"includePath": ["${myDefaultIncludePath}", "/another/path"],
"macFrameworkPath": ["/System/Library/Frameworks"],
"defines": ["FOO", "BAR=100"],
"forcedInclude": ["${workspaceFolder}/include/config.h"],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "/path/to/compile_commands.json",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Have a look at the extension Command Variable.
It can use the content of a file as key-value pairs.