VSCode tasks.,json file cannot be excluded - visual-studio-code

I have next tasks.json
"inputs": [
{
"id": "pickBuild",
"type": "command",
"command": "extension.commandvariable.transform",
"args": {
"text": "${pickFile:build}",
"find": ".*(default_.*).py",
"replace": "$1",
"pickFile": {
"build": {
"include": "**/default_*.py",
"exclude": "**/{default_keyboard_*.py, default_mouse_*.py}",
"description": "Select build",
"display": "fileName",
}
}
}
}
]
eventhough default_mouse_*.py excluded, I still can see it in options
expected: default_keyboard_.py and default_mouse_.py should be excluded
Thanks

Should no space inside the brackets.
what I had:
"exclude": "**/{default_keyboard_\*.py, default_mouse_\*.py}"
solution:
"exclude": "**/default_{keyboard_\*,mouse_\*}"

Related

Prevent asynchronous order of command sequence execution in VS Codium

How can I control the execution order of multiCommand extension? It behaves like it executes them in parallel, while I want them to be executed one after another.
I have a project with the following structure:
/home/user/myproject/dir1/problem1.py
/home/user/myproject/dir1/problem1.txt
/home/user/myproject/dir1/problem2.py
/home/user/myproject/dir1/problem2.txt
...
/home/user/myproject/pointer.txt
The pointer.txt contains the text: dir1/problem2.
I want to press a shortcut, and do a sequence of actions:
Create next problem files pair
Modify a pointer.txt to point to new files
Open them in the editor
I setuped the following things.
In settings.json I defined the command sequence named "openPointedProblemLayout" (for being able to easily reuse it):
"multiCommand.commands": [
{
"command": "multiCommand.openPointedProblemLayout",
"sequence": [
{ "command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.py",
"method": "vscode.open",
"viewColumn": 1,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
{ "command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.txt",
"method": "vscode.open",
"viewColumn": 2,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
]
},
]
In tasks.json I created a shell command definition, that creates a new .py and .txt pair and also changes the pointer:
{
"version": "2.0.0",
"tasks": [
{
"label": "create_new_problem_files_pair",
"type": "shell",
"command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
},
],
}
In keybindings.json I defined shortcut numpad2 that executes both actions (creates files and opens them) and a numpad5 (just opens them):
{
"key": "numpad2",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
{
"command": "workbench.action.tasks.runTask",
"args": "create_new_problem_files_pair"
},
{
"command": "multiCommand.openPointedProblemLayout"
},
]
}
},
{
"key": "numpad5",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openPointedProblemLayout" },
},
Now, when I press numpad2, the two new files are created:
/home/user/myproject/dir1/problem3.py
/home/user/myproject/dir1/problem3.txt
And then two files are opened in layout (means the command actually runs), but wrong files. They are problem2.py and problem2.txt, i.e. the previous pointer is used.
I checked the content of the pointer.txt now, and it actually contains dir1/problem3. And when I press numpad5, they are opened correctly.
Why does the VS Codium uses previous content of pointer, while at the moment of command run, it should already take the new content? It looks like VS Code executes the command sequence in parallel, instead of sequence them.
Am I doing something wrong? Is that an issue with configuration or vs code itself or maybe in multiCommand extension?
I have solved the problem by avoiding usage of any extensions. A command sequence can be defined via Tasks. See https://stackoverflow.com/a/72201981/7869636
In keybindings.json I define:
{
"key": "numpad2",
"command": "workbench.action.tasks.runTask",
"args": "create_new_problem_files_pair_and_open_file_pair_in_layout"
},
And in tasks.json I defined the whole things:
{
"version": "2.0.0",
"tasks": [
{
"label": "create_new_problem_files_pair",
"type": "shell",
"command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
},
{
"label": "open_file_pair_in_layout",
"dependsOrder": "sequence",
"dependsOn": [
"open_in_layout_left",
"open_in_layout_right",
],
},
{
"label": "create_new_problem_files_pair_and_open_file_pair_in_layout",
"dependsOrder": "sequence",
"dependsOn": [
"create_new_problem_files_pair",
"open_file_pair_in_layout",
],
},
{
"label": "open_in_layout_left",
"command": "${input:open_in_layout_left}",
},
{
"label": "open_in_layout_right",
"command": "${input:open_in_layout_right}",
},
],
"inputs": [
{
"id": "open_in_layout_left",
"type": "command",
"command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.py",
"method": "vscode.open",
"viewColumn": 1,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
},
{
"id": "open_in_layout_right",
"type": "command",
"command": "htmlRelatedLinks.openFile",
"args": {
"file": "${command:mypointer}.txt",
"method": "vscode.open",
"viewColumn": 2,
"command": {
"mypointer": {
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/pointer.txt"
}
}
}
}
}
]
}
This approach has a benefit that it defines these tasks in a scope of that project's workspace, and not globally in setting.json.

In tasks.json in vscode, Is it possible to reference single elements in an array defined in settings.json?

When writing an extension in vsCode, is it possible to create a configuration (a field in my settings.json) where I can store multiple values and configure an actively selected one?
Say I have an external dependency, which I need to reference in my tasks.json. Through the configuration contribution point of the extension i can provide the following property:
"myextension.dependencyDir": {
"scope": "resource",
"type": "string",
"description": "Path to the external dependency"
}
I can now reference this path in my tasks.json through ${config:myextension.dependencyDir}
However, lets say my dependency comes in various versions, which I would like to switch from the comfort of my settings(UI)
I know that by using an array I can store multiple versions of the dependency.
"myextension.dependencyDir": {
"scope": "resource",
"type": "array",
"items": {
"type": "string"
},
"description": "Path to the external dependency"
},
However, I cannot seem to reference single elements out of this array from my tasks.json.
By calling ${config:myextension.dependencyDir} now, i get the entire array.
I have tried to call
${config:myextension.dependencyDir[0]}
${config:myextension.dependencyDir(0)}
${config:myextension.dependencyDir:0}
... and many other variations
to query the first item in my array. Neigther of those attempts have worked.
${config:myextension.dependencyDir}[0] just appends '[0]' to the
last element.
I know that I can create custom objects and configure them in my settings.
"myextension.dependencyDir": {
"scope": "resource",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of your dependency version"
},
"value": {
"type": "string",
"description": "Path to the specific Dependency version"
}
}
},
"description": "Path to the external dependency"
},
However, just like before, I don't know how to access a single entry in my array, let alone adress the specific fields name and value.
Is what I am trying to do possible? Is it even the proper way of doing this? Does anyone have a solution to my problem or suggestions for a different approach?
Thanks in advance
BioZons
You can use the extension Command Variable v1.30.0
It has a command extension.commandvariable.config.expression. It allows to apply a JavaScript expression to the value of a configuration variable.
If the config variable is an array:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo config var",
"type": "shell",
"command": "echo",
"args": [
"ConfigArray: ${input:configArray}",
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "configArray",
"type": "command",
"command": "extension.commandvariable.config.expression",
"args": {
"configVariable": "myextension.dependencyDir",
"expression": "content[1]"
}
}
]
}
If the config variable is an array and you want to pick the array element:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo config var",
"type": "shell",
"command": "echo",
"args": [
"ConfigArrayPick: ${input:configArrayPick}",
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "configArrayPick",
"type": "command",
"command": "extension.commandvariable.config.expression",
"args": {
"configVariable": "myextension.dependencyDir",
"expression": "content[${pickStringRemember:serverNr}]",
"pickStringRemember": {
"serverNr": {
"description": "Which server to use?",
"options": [
["development", "0"],
["live", "1"]
]
}
}
}
}
]
}
If the config variable is an array of objects:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo config var",
"type": "shell",
"command": "echo",
"args": [
"ConfigObject: ${input:configObject}",
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "configObject",
"type": "command",
"command": "extension.commandvariable.config.expression",
"args": {
"configVariable": "myextension.dependencyDir",
"expression": "content[1].name"
}
}
]
}

Unable to read appsettings.json when debugging .net core webapi in vscode

When debugging in vscode I'm unable to read the appsettings.json in my Startup.cs file of my webapi project. They all return as empty/null.
My launch.json configuration for the webapi was generated by adding the .NET Core Launch (console) configuration. I also tried adding the .NET Core Launch (web) configuration but the same problem occurs.
The only thing I then had to change was the "program" setting to point to the correct dll in my project folder.
Here is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/SATestUtils.API/bin/Debug/netcoreapp3.1/SATestUtils.API.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
And here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/SATestUtils.Api/SATestUtils.API.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/SATestUtils.Api/SATestUtils.API.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/SATestUtils.Api/SATestUtils.API.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
Here is my appsettings.json and appsettings.Development.json file...
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SaTestUtils"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"StorageAccountName": "devstoreaccount1",
"AzureAD": {
"Instance": "https://login.microsoftonline.com",
"Domain": "[Domain]",
"TenantId": "[TenantId]",
"ClientId": "[ClientId]",
"Scope": "[Scope]"
},
"AllowedHosts": "*"
}
When I attempt to debug the following code in my services method in Startup.cs
var connectionString = Configuration["ConnectionStrings:DefaultConnection"];
Console.WriteLine($"Connection string = {connectionString}");
I simply get the following logged to the debug terminal
Connection string =
All the other settings in appsettings.json are also not returning. The correct settings are returned when using dotnet run.
What could be the issue here?
Note that I have a solution file in my working directory, then I have a folder called SATestUtils.API that contains the SATestUtils.API.csproj file for my webapi project.
I experienced the same case, for me, what worked was what has been commented before:
Change the value of 'cwd' property in launch.json to the value of the project directory.
{
...
"cwd": "${workspaceFolder}"
}
to
{
...
"cwd": "${workspaceFolder}/SATestUtils.API"
}
All the credits to Bemm...
Did you try to specify the asp net environment at the launch.json?
Something like this:

How to use the same input string across multiple chained tasks in vscode?

I have multiple tasks that depend on each other and that should all operate on the same folder.
My config looks something like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "first task",
"type": "shell",
"command": "bash",
"args": ["do stuff in ${input:pickFolder}"],
"dependsOn": "second task"
},
{
"label": "second task",
"type": "shell",
"command": "bash",
"args": ["also do stuff in ${input:pickFolder}"]
}
],
"inputs": [
{
"type": "pickString",
"id": "pickFolder",
"options": ["path/to/folder", "path/to/other/folder"]
}
]
}
As you might imagine I want both tasks run in the same folder. Also, I don`t want to have to pick the folder twice. How can I do that?
You can use the extension Command Variable v0.9.
Use the commands:
extension.commandvariable.pickStringRemember
extension.commandvariable.rememberPick

How to launch specific task from input variable in VS Code?

I'm trying to create a launch configuration where an environment variable is dynamically determined by a shell script. Even though a command variable can start a task via workbench.action.tasks.runTask, it doesn't seem to be possible to specify which task to run. Input variables seem to be a little more flexible in that regard, but I can't seem to get it to work. Here is what I got:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"XXX": "${input:foo}"
},
"args": []
}
],
"inputs": [
{
"type": "command",
"id": "foo",
"command": "workbench.action.tasks.runTask",
"args": {
"args": "bar",
}
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "bar",
"type": "shell",
"command": "find /dev -name 'myspecialdevice*' -maxdepth 1"
}
]
}
The issue is that the user is still queried for which task to run. I'm most insecure about the inputs.args section of the launch.json. I don't really know what the key value should be. Perhaps the implementation helps to figure this out?
This answer not really relates to make use of a vscode task, but your introducting sentence offers the motivation/what is intended to be solved.
I was faced to the same question and was wondering about vscode's input type:command. It offers a way to embed a (custom) vscode command -- which looks like a powerfull mechanism to embed a (custom) extension here. But I didn't found a builtin command that simply executes a shell script and returns it stdout. Thus an extension to capture the output of a shell command is imho required todo the trick.
E.g. https://marketplace.visualstudio.com/items?itemName=augustocdias.tasks-shell-input
provides a command shellCommand.execute doing exactly this.
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"XXX": "${input:foo}"
},
"args": []
}
],
"inputs": [
{
"id": "foo",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "find /dev -name 'myspecialdevice*' -maxdepth 1",
"cwd": "${workspaceFolder}",
/* To prevent user from selecting output (if there is just
one line printed by command), un-comment next line */
//"useSingleResult": true
}
}
]
}
(Inspired by https://stackoverflow.com/a/58930746/1903441)
In your launch.json, try replacing
"args": {
"args": "bar",
}
with
"args": "bar"
It seems that in vscode, you cannot pass a return or even an environment variable from task.json to launch.json. But you can use a file as a intermediate.
For example, in task.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "bar",
"type": "shell",
"command": "find /dev -name 'myspecialdevice*' -maxdepth 1 > ${workspaceFolder}/.vscode/temp"
}
]
}
In launch.json you set bar as preLaunchTask, and later access the file using inputs, like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"XXX": "${input:foo}"
},
"args": [],
"preLaunchTask": "bar",
}
],
"inputs": [
{
"id": "foo",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/.vscode/temp",
}
}
]
}
To get the comment working, just install this extension: https://marketplace.visualstudio.com/items?itemName=rioj7.command-variable