VSCode problemmatcher: Unknown subfolder for file location - visual-studio-code

I have a problem matcher defined like this:
"fileLocation": ["relative", "${workspaceFolder}"],
And I only know the name of the file and NOT the relative path from my compilation output.
Than it only opens files when they are in the root of the workspace.
E.g.
Problem matcher searches for: Package.sql
But the file is under
root
Other Subfolders
PKGs
Package.sql
Is there a setting to let the problem matcher "find" that file, even if it's in a (unknown) subfolder?
(Assumed all filenames are distinct)

You can use "command" string for print file with relative or absolute path like this:
echo FILEBEGIN${relativeFile}FILEEND
or
echo FILEBEGIN${file}FILEEND
And it will be easy to get file by regex.
If you are using oracle and powershell you can try my task:
{
"label": "compile",
"type": "shell",
"command": "echo 'set define off' 'set serveroutput on' '#${file}' 'exit' | sqlplus ${config:plsql-language.connection.activeInfos} | Select-String -Pattern '(\\d+/\\d+.*|.*created.*)' | % {'${relativeFile}:' + $($_.matches.value)}",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "PLSQL",
"severity": "error",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern":
{
"regexp": "^(.*):(\\d+)\\/(\\d+)\\s+((PLS|ORA)-\\d+):(.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 6
}
}
}

The problem matcher should return either absolute path, or path relative to a fixed folder inside the workspace. If you have a filename only, without absolute/relative path, in my understanding Code won't be able to locate the file as the name only is not enough information.
There is also the autodetect option. You can try something like this:
"fileLocation": ["autodetect", "${workspaceFolder}/subfolder1/subfolder2"]

Related

How to configure the executable file name in VS Code?

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.

How to set up VSCode's problem matcher with Linux-style gcc errors

I'm using VSCode on Windows 7 with MSYS2 + mingw-w64-x86_64-gcc + base-devel installed.
I've got tasks.json for my project running make command to build:
{
"tasks": [
{
"type": "shell",
"label": "build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
The problem is GCC generates a error message in the following way:
src/src_file.cpp:773:59: error: comparison of integer expressions of different signedness
while the project path stored in $workspaceFolder variable is D:\myproject.
The real path to the file is D:\myproject\tools\src\src_file.cpp. I have no idea how to set up the problem matcher in this case. I suppose that Linux-style slashes affect the problem, but I'm not sure. I tried to set up regexp for the matcher, however I couldn't get it to work.
UPDATE:
Actually slashes and backslashes don't affect the result.
Use this problem matcher, use $gcc as base and define the file location
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceFolder}/tools"]
}
Edit
Removed the src because it is already part of the error message. (Did not spot it)

C++ custom problem matchers in VS Code not highlighting file paths

I have a bunch of custom build tasks in VS Code and I want a custom problem matcher for the C++ ones.
So I decided to take the default problem matcher example in VS Code docs (https://code.visualstudio.com/Docs/editor/tasks#_defining-a-problem-matcher) and modified it slightly.
"problemMatcher": {
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(\\.\\.\\/+)(.*):(\\d+):(\\d+):\\s+(.*):\\s+(.*)$",
"file": 2,
"line": 3,
"column": 4,
"severity": 5,
"message": 6
}
My error messages have the following structure:
../../../module/src/module/specific/File.cpp:155:31: error: errorMessage
The three directory-up instructions (../../../) bring me back to ${workspaceFolder}. So the idea was to use the second capture group as a relative path from my workspace folder to follow up to the file.
Unfortunately, the file path does not highlight and it doesn't tell me to Ctrl+click to follow the message. I double checked the regex on https://regexr.com/ and it seems to be correct. I tried using the the default problem matcher too, without any luck.
This is the full build task:
{
"label": "build_c++",
"type": "shell",
"command": "${workspaceFolder}/build_command",
"problemMatcher": [ {
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(\\.\\.\\/+)(.*):(\\d+):(\\d+):\\s+(.*):\\s+(.*)$",
"file": 2,
"line": 3,
"column": 4,
"severity": 5,
"message": 6
}
}],
"group": {
"kind": "build",
"isDefault": true
}
},
Any ideas?

Problem in VSCode "$gcc" problem matcher to recognize file path in C++ compiler error reports

I have just set my launch.json and tasks.json as the tutorial on the Internet said. But when I pree F5 compile and find some errors, I cannot click the red words "errors" showed in the "Problems".
If I click, the information will be:
Anyone can help me?
task.json
{
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
The problem is the "$gcc" problem matcher defined in ms-vscode.cpptools-0.XX.0 extension.
It is the same problem matcher as mentioned in the Task documentation about problem matchers.
This matcher uses relative paths. But MinGW with g++ v8 uses absolute file paths in the error when the source file is supplied with absolute file path in the args property of the task.
Solution is to modify the "$gcc" problem matcher and use absolute file path.
"problemMatcher": {
"base": "$gcc",
"fileLocation": "absolute"
},

ProblemMatcher in VS Code using incorrect file for gulp-tslint task

tasks.json in .settings of project root
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"tasks": [
{
"taskName": "dev",
"args": [],
"isBuildCommand": true,
"problemMatcher": [
"$tsc",
"$jshint"
]
},
{
"taskName": "tslint",
"fileLocation": ["absolute"],
"problemMatcher": [
{
"pattern": {
"regexp": "\\[[^\\]]+\\] \\[[^\\]]+\\] (\\S+) \\([^\\)]+\\) ([^\\[]+)\\[(\\d+), (\\d+)\\]: (.+)",
"file": 2,
"line": 3,
"column": 4,
"severity": 1,
"message": 5
}
}
]
}
]
}
Example output of tslint task:
[17:35:12] [gulp-tslint] error (no-unused-variable) C:\repo\IgnitionOne\stable\prototype-coresettings\src\server\controllers\userController.ts[38, 9]: unused variable: 'test'
Unescaped Regex:
\[[^\]]+\] \[[^\]]+\] (\S+) \([^\)]+\) ([^\[]+)\[(\d+), (\d+)\]: (.+)
When I test my regex on online testing tools, its pulling all the groups out properly. When I look at the problems in vs code with CTRL+SHIFT+M I see the error with file path, name, and message all being correct. However when I click on the error, I get:
Error opening 'userController.ts' (File not found).
And if I click Create File from there:
ENOENT: no such file or directory, mkdir
'c:\repo\IgnitionOne\stable\prototype-coresettings\c:'
I've looked it over with a fellow dev and it's not clear why this is happening. It's as if it's using a file location relative to workspace root and matching only 'c:' in the file group. Any ideas on what is not set up correctly?