VSCode problemmatcher regex not matching my error output - visual-studio-code

I am trying to match errors of this format for the VSCode ProblemMatcher...
C:\projects\folder\main.cpp(6) : Error[AA000]: identifier "level2" is undefined
C:\projects\folder\main.cpp(7) : Error[AA000]: identifier "level3" is undefined
With regex101.com I am able to match what I need with this regex...
^([][{} \t#%$~A-Za-z0-9_:+\.-\\]+)\(([0-9]+)\) (:) (Warning|Error)(.*)$
Alas, when put into my tasks.json file with the (hopefully) correct escape slashes I don't receive any output in the Problems tab after running the task that will generate these errors in the terminal of VSCode.
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build simple regex",
"type": "shell",
"command": "iarbuild iar_ewb_build_timer.ewp -make Debug -log errors -parallel 8",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"fileLocation": "absolute",
"pattern": {
"regexp": "^([][{} \\t#%$~A-Za-z0-9_:+\\.-\\\\]+)\\(([0-9]+)\\) (:) (Warning|Error)(.*)$",
"file": 1,
"line": 2,
"severity": 4,
"message": 5
}
}
},
]
}
Perhaps there is a problem with my Regex. Any help?

I was able to get this working for example error codes in my original post. Thank you for the replies!
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build simple regex",
"type": "shell",
"command": "iarbuild iar_ewb_build_timer.ewp -make Debug -log errors -parallel 8",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"fileLocation": "absolute",
"pattern": {
"regexp": "^([#%$~A-Za-z0-9_:+-\\\\]+)[(]([0-9]+)[)] (:) (Warning|Error)(.*)$",
"file": 1,
"line": 2,
"severity": 4,
"message": 5
}
}
},
]
}

Related

How can I show problems detected by vite checker plugin in VS Code?

I am using the checker plugin for vite. It prints errors to the VS Code terminal, like this (example):
ERROR(TypeScript) Property 'foobarasdasdasdas' does not exist on type 'HelloWorld'.
FILE /home/birger/SomeFile.tsx:194:23
192 |
193 | // TODO: fix
> 194 | return helloWorld.foobarasdasdasdas({
| ^^^^^^^^^^^^^^^^^
195 | someprop:args,
196 | asd: "",
197 | dsa: "",
However, the "problems" tab in VS Code is silent.
How can I make VS Code detect the errors that is printed to the terminal?
EDIT: I guess I need to configure the task to pick up the output?
{
"version": "2.0.0",
"tasks": [
{
"label": "client dev",
"type": "npm",
"script": "dev",
"problemMatcher": // WHAT DO I WRITE HERE?
}
]
}
(https://github.com/fi3ework/vite-plugin-checker/issues/95)
// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "client dev",
"type": "npm",
"script": "dev",
"problemMatcher": [
{
"owner": "typescript",
"source": "Typescript",
"fileLocation": "absolute",
"applyTo": "allDocuments",
"background": {
"activeOnStart": true
// "beginsPattern": "sd",
// "endsPattern": " > "
},
"pattern": [
{
"regexp": "(ERROR|WARNING)\\(TypeScript\\) (.*)",
"severity": 1,
"message": 2
},
{
"regexp": "^ FILE (.*):(\\d*):(\\d*)$",
"file": 1,
"line": 2,
"column": 3
}
]
}
]
}
]
}
Add below code to your config file of checker plugin
export default {
plugins: [checker({ typescript: true /** or an object config */ })],
}

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

How to define a squiggle range for the problem matcher in tasks.json (VS Code)?

I have written a problemMatcher in tasks.json that looks like this:
"problemMatcher": {
"owner": "myFileExtension",
"pattern": {
"regexp": "myRegExp",
"file": 1,
"line": 2,
"severity": 3,
"message": 4,
"location": 2
}
}
I am using this problem matcher to squiggle the lines that have problems after I run my build task. However, instead of squiggling the whole line, I would like to squiggle a particular range, based on where the problem actually comes from. After reading the documentation, I am still not sure how this can be done.
How can I squiggle a range in tasks.json?
See last example in the doc.
The location can be 1, 2 or 4 numbers enclosed in ()
1: (line)
2: (line,char)
4: (lineStart,charStart,lineEnd,charEnd)
{
"version": "2.0.0",
"tasks": [
{
"label": "watch",
"command": "tsc",
"args": ["--watch"],
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"fileLocation": "relative",
"pattern": {
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
},
"background": {
"activeOnStart": true,
"beginsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - File change detected\\. Starting incremental compilation\\.\\.\\.",
"endsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - Compilation complete\\. Watching for file changes\\."
}
}
}
]
}```

vscode problemMatcher doesn't not recognize Tasking compiler warnings

The following Tasks.json
Problem matcher regular expression should match the following typical warning. But it doesn't.
ctc W505: ["somedirectory/somefile.c" 350/18] implicit declaration blah blah blah
What is the issue ? I verified the built-in parser matches gcc output errors and warnings.
Thanks,
Satish K
"tasks": [
{
"label": "build.bat",
"type": "shell",
"command": "build.bat",
"problemMatcher": {
"owner": "cpptools",
"fileLocation": [
"relative",
"${env:PWD}"
],
"pattern": {
"regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\\/(\\d+)\\] (.*)$",
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
You add an additional \ to the expression, you only need to escape the " and you don't need to escape /
"tasks": [
{
"label": "build.bat",
"type": "shell",
"command": "build.bat",
"problemMatcher": {
"owner": "cpptools",
"fileLocation": [
"relative",
"${env:PWD}"
],
"pattern": {
"regexp": "^ctc W(\\d+): \\[\"(.*)\" (\\d+)/(\\d+)\\] (.*)$",
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
Edit
This works in regex101 (flavor Javascript)
^ctc W(\d+): \["(.*)" (\d+)\/(\d+)\] (.*)$
To translate it to a JSON string, escape \" and regex also wants you to escape / but that would only be needed if you use the regex in a literal Javascript (like /\d+/g) but we don't do that in VSC, but it won't hurt.
Resulting in:
"^ctc W(\\d+): \\[\"(.*)\" (\\d+)\\/(\\d+)\\] (.*)$"
I couldn't get this to work. But I ran the working regex101 through a json escpare. It did some more escaping of slashes and ended up as:
"regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\/(\\d+)\\] (.*)$",

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