Related
I have a VS Code project based on a CMakeLists.txt file, and using the CMakeTools extension I can successfully build the target executable.
However, I need to run the executable in a different directory to the build directory. I cannot find a setting to either:
The built executable is placed in a different directory to the build directory and then run from there
The build executable is run from a different working directory
How can I achieve my goal?
You can change the output directory for the executable using the RUNTIME_OUTPUT_DIRECTORY property. When debugging, the executable is run in that directory. For example:
set_target_properties(my_target
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
If you only want to change the current working directory (cwd), you can create your custom .vscode/launch.json. The content may depend on your OS and compiler:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run CMake Target",
"type": "cppvsdbg", // use cppdbg on linux
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"cwd": "${workspaceFolder}/bin"
}
]
}
I am a complete beginner with C and to VSCode. I am trying to configure the task and launch jsons but have no idea where to begin. I have tried googling the answers but I keep getting the same errors. I want to be able to step through the code line by line so I can see what it is doing.
I haven't changed the tasks.json from the original that VSCode sets. The launch.json I have changed by putting in the debugger path and the path of the executable. I have included the task.json, launch.json and the error that keeps popping up. Any help is appreciated.
tasks.json
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/scheduler.c",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
I've recently had the same issues. Here is the procedure that I follow, that seem to work:
Download and install msys2 (1)
Download MSYS2 from https://www.msys2.org/
Install folder is typically C:\msys64
Go to C:\msys64 and open mingw64.ini
Change ‘#MSYS2_PATH_TYPE=inherit’ to ‘MSYS2_PATH_TYPE=inherit’ i.e. enable PATH variable.
Add PATH environment variables (2)
Type “environment” in Windows search field, and select “Edit environment variables …”
Add path to gcc.exe and g++.exe:
— Add: “C:\msys64\mingw64\bin” to PATH variable.
Add path to VS Code to PATH variable as well:
— This is usually the folder:
C:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\
Run “msys2 mingw64” and test access to compilers and debugger (3)
In Windows Search field, type “msys2” and select “msys2 mingw64” and run the following:
To install gcc, the Gnu C compiler: pacman -S mingw-w64-ucrt-x86_64-gcc
To install gdb, the Gnu GDB debugger:
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
To test that you can run compilers and debugger, run:
gcc --version
g++ --version
gdb --version
Start development in VSC (4)
Open “msys mingw64” terminal and run:
cd <common projects folder>
mkdir <projname>
cd <projname>
Above changes current directory to a projects folder. I use C:\Users<username>\src\projects, i.e. this is my but you may want to use something else.
In the folder you can make a subfolder per C coding project you want to run. This is what “mkdir ” does.
You will need a little Unix Bash shell command skills here, here is an ultrashort summary:
cd – change directory to
mkdir – makes a new directory called
in the current folder.
cd .. – change directory one up.
_ cd ~ – changes directory to your home folder, I have C:\Users<username> where is my … username.
pwd – shows current directory.
Now, if you did above you are currently in the specific projects folder (you can verify this with pwd), and you should start VSC from there by typing:
code .
And accept Workspace trust.
Create a C source file (5)
Open folder view, click on + icon, and select ‘new file’, type “hello.c”, go into the file and add the contents:
include
int main() {
printf("Hello World\n");
return 0;
}
Configure VSC for building – tasks.json (6)
Press “ctrl+shift+B” to build target (or menu: -> Terminal -> Run Build Task… or press green play icon)
Select “C/C++: gcc.exe build and debug active file”
Now it tries to build, using an autogenerated tasks.json file, located in project-folder, in subfolder .vscode:
.vscode/tasks.json
An example of a tasks.json file is shown below:
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\apps\msys64\mingw64\bin\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-Wall",
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
The important section is:
"command": "C:\msys64\mingw64\bin\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-Wall",
"-g",
"${workspaceFolder}/*.c", OR TODO "${file}"
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
“command” is the Gnu C compiler, gcc.exe and the full path to it.
“args” are arguments for the compiler:
-Wall means warn about everyting.
-g means compiler must prepare for debugging.
“${file}” is current file.
-o is output file which is specified in the next line with .exe extension.
Sometimes we have to build multi-file projects and it will break the default build-functionality in tasks.json in VSC. In some cases this can be solved by changing:
${file},
to
"${workspaceFolder}/*.c",
Configure VSC for Debugging – launch.json (7)
Go to source file hello.c, and set a break point,
Click left to the line numbers to set red circle.
Select play/bug icon
Select “Debug C/C++ File”
Choose “C/C++ gcc build and debug active file” from list of automatically detected compilers.
This will autogenerate a file, launch.json in the projects folder, in subfolder .vscode:
.vscode/launch.json
An example of a launch.json file is shown below:
{
"configurations": [
{
"name": "C/C++: gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
]
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
The most important parts are:
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
and
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
The “program” is the program generated when building the project. I.e. the output from running the task as specified in Tasks.json.
The miDebuggerPath is the path to gdb, the GNU gdb debugger.
If these does not match with your Tasks.json settings and your installation chances are slim to make it work.
Test it by pressing the Play/Bug icon button and notice if there are errors. If not you should be able to step through the code and watch variables etc.
Configure VSC for intellisense (8)
Install extension: “C/C++ extension for VS Code” by Microsoft.
Now this extension will assist when you type code. By example you can type for to get the basics of a for-loop. Similar for if, while etc. Cool!
Save work when creating new projects (9)
Instead of having to create the tasks.json and launch.json files for each project, I copy them to a templates folder, say:
C:\Users\username\src\templates\.vscode\
Copy the newly created tasks.json and launch.json files to the .vscode subfolder.
Now, say you want to create a new project, e.g. hello2, and you create a folder for it:
C:\Users\<username>\src\projects\hello2\
Go to the templates folder by
cd C:\Users<username>\src\templates
and copy the .json files to the new project by:
cp -Rp .vscode/ ../hello2/
And now the new project has the .json files.
Optional (10)
Later you may want to update msys2. To do this, open “msys2 mingw64” and type
pacman -Suy
Done (11)
Finally done … Not the easiest thing to get going, but I still think it is worth it.
I am working on a proof-of-concept app, written in Rust, with the end goal being to produce a shared library (.dll/.so) callable via C ABI from a number of other languages (C++, C#, etc). I have two simple components; poc is a Rust console app, which references poclib which exposes some simple functions. The app itself builds and runs fine so far, but I am stuck on how to debug it in VSCode using CodeLLDB.
I have a top level "workspace" like this:
[workspace]
members = [
"poc",
"poclib"
]
poc/cargo.toml looks like this:
[package]
name = "poc"
version = "0.1.0"
edition = "2018"
[dependencies.poclib]
path = "../poclib"
[dependencies]
And poclib/cargo.toml looks like this:
[package]
name = "poclib"
version = "0.1.0"
edition = "2018"
[lib]
crate_type = ["cdylib"]
[dependencies]
unicode-segmentation = "1.7.1"
My launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'poc'",
"cargo": {
"args": [
"build",
"--bin=poc",
"--package=poc"
],
"filter": {
"name": "poc",
"kind": "bin"
}
},
"args": [ ],
"cwd": "${workspaceFolder}"
}
]
}
When I try to launch and debug in VSCode with the CodeLLDB extension installed, the app builds but then raises an error: /home/username/src/rustpoc/target/debug/poc: error while loading shared libraries: libpoclib.so: cannot open shared object file: No such file or directory. If I just do cargo run instead, it builds and runs fine, and I can verify that libpoclib.so is being built and placed in the ./target/debug folder.
If I comment out the crate_type option in the poclib/cargo.toml, it launches fine and I can hit breakpoints, but the shared library is no longer created.
I've tried adding an LD_LIBRARY_PATH setting to the launch.json, like this:
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/target/debug"
},
That doesn't fix anything, but it does change the error message - with that setting I get /home/username/src/rustpoc/target/debug/poc: error while loading shared libraries: libstd-0a9489cf400f65e4.so: cannot open shared object file: No such file or directory
How can I enable debugging Rust in VSCode while still producing shared libraries?
I don't understand why it worked at all initially, but the solution was to fix the crate_type option so that I'm producing both C ABI libraries and native Rust libraries.
crate_type = ["cdylib","lib"]
With that setting the build output contains both a libpoclib.so for use from C, and a libpoclib.rlib which the poc binary can link statically against, and LLDB debugging works as expected.
I switch from Sublime to VS Code because it anymore PHP and SASS support. I mostly use CSS & SASS & JS & PHP.
I set up a SASS compiler from VS Code documentation. As follows:
// Sass configuration
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sass Compile",
"type": "shell",
"command": "node-sass style.scss style.css",
"group": "build",
"problemMatcher": [
"$eslint-compact"
]
}
]
}
I tested it working properly. But I have 2 problems:
First of all, it focuses on "style.scss" file. I mean, whatever we mentioned in ".json".
Actually what I want is: Focus on all ".scss" files without searching for a name.
When I run an compile with the "a.scss" editor open, it compiles only names in the ".json" file. But there not contain "a.scss"!
Actually what I want is: If I press the "CTRL + SHIFT + B" key and select the corresponding option, the currently active editor is the "a.scss" compilation.
Are there any settings for these?
Note: "command": "node-sass .scss .css", it will give error.
Actual the situation is, that SASS actualized to a new version Dart SASS. There are new rules like #use in it ... so the used compilers needs to be updated.
As I know up to now Node Sass did not.
The better way to use SASS in VS Code is to use an extension.
As we had this several times:
If you are interessted in it you may look here https://stackoverflow.com/a/66207572/9268485
Note: if you decide to use one of the extensions your settings may change. Have a look to the extensions descriptions.
I'am using Visual Studio Code Version 1.6.0.
Is there any possibility to show errors and warnings of all files in the current root folder?
At the moment it shows only errors and warnings for open files.
UPDATE 2019
ES-Lint has introduced a new task in VS Code. You have to enable it in the workspace setings.
"eslint.lintTask.enable": true
Just go to terminal menu and select run task, then choose
eslint: lint whole folder
You can also auto-fix most problems by running the following command in the terminal:
.\node_modules\.bin\eslint.cmd --fix .
Reference: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
While we still await the problem scanner in VS Code, this is a good enough alternative if you use eslint.
OLD ANSWER
Here is how you can see all problems in less than 10 seconds.
You use a little trick.
Open replace all in files Ctrl + Shift + H.
Replace ; with ;
Hit replace all. That's it. Now, check Problems.
The assumption here is that all files have at least one semicolon. For
bigger projects, if you get a warning asking you to refine your
search, just enter something that is common in all files but is not
present a lot.
Very important: Make sure to check the Super cool! But i don't use eslint section! Wich provide a global solution! By setting up tasks! And explained in details!
Note: If you feel the document is blottered! Make sure to skim and get to the titles that catch you! Even though every section may matter! (TLDS (TOO LONG DO SKIM)).
Javascript and Eslint
To add upon #Ajay Raghav answer!
This section show how to run the task on question! And the output of the execution!
For javascript, Vscode Eslint extension provide such a feature! Which if you are using Eslint (and not jshint) then you are having it already installed!
Usage as described on #Ajay Raghav answer! Are explained on the Eslint extension page!
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
eslint.lintTask.enable: whether the extension contributes a lint task to lint a whole workspace folder.
eslint.lintTask.options: Command line options applied when running the task for linting the whole workspace (https://eslint.org/docs/user-guide/command-line-interface). An example to point to a custom .eslintrc.json file and a custom .eslintignore is:
{
"eslint.lintTask.options": "-c C:/mydirectory/.eslintrc.json --ignore-path C:/mydirectory/.eslintignore ."
}
Using the extension with VS Code's task running
From the doc:
The extension is linting an individual file only on typing. If you want to lint the whole workspace set eslint.lintTask.enable to true and the extension will also contribute the eslint: lint whole folder task. There is no need anymore to define a custom task in tasks.json.
If you are not familiar with task! Here how you use the above!
Go to Command pallet (CTRL + P + SHIFT)
> tasks run
Hit Tasks: run Task
You'll find eslint: lint whole folder
Hit and that's it
If eslint have no configuration setup! You'll get the following error!
If as such, Run eslint --init
And follow the interactive terminal!
Note if you don't have eslint command avaialble globally!
Intall it globally by running npm i -g eslint!
Result of the run
First the task run on the terminal!
You can see a detailed report! You can use the click link on terminal feature (CTRL + CLICK)! To directly open the file in question!
You can see too that the problems will automatically be listed in the problems tab! Which is cool!
Super cool! But i don't use eslint
Typescript and TSLINT
If you are a typescript user and you use TSLINT!
Then we need to go to the global way! And that's by creating a task!
Just like eslint did! (problemMatcher: $tsc) [you'll get to know what that is just a bit bellow].
(Make sure to check TSLINT is deprecated title)!
I use a complete other language (c#, java, c++, php, python ...)
Yup yup! We need a global way! And the global way is through creating a task!
Creating a task (The global way)
(Support all languages (to be configured for each))
We need to create a task!
The vscode documentation explains it pretty awesomely and in details!
https://code.visualstudio.com/docs/editor/tasks
Check the documentation!
Now in short! I would resume what a task is in:
A vscode tool and feature! That allow us to setup tasks based on tools and scripts and run them within vscode! Analyse there output within vscode! And activating and profiting from other vscode features! That includes Click link navigation on terminal! And problems listing on problem tab! Auto fixing and suggestions! Integration with the debugging tool! ...etc! It depends on the task type!
A task get set through a setting file (task.json)! For a workspace or the whole user! (Some tasks types need to be set for only a workspace! They depends on the variables of a workspace)!
Also the task feature contains a lot of options and features! And is a big piece! For more just check the documentation!
Back to our problem!
We want linting of a whole project! And errors detection!
We need to have the errors listed on the problems tab! And preferably too with fixes suggestions!
All this gonna be done through a task.
Setting up the task! And core elements
Through vscode task features and integration! We need to configure it to allow good output! And integration with the problems tab!
The config will go as such:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "lint",
"problemMatcher": ["$eslint-stylish"]
}
]
}
(Here eslint through npm run lint)
The most important thing here to see! Is the type which determine the category and the task handling and launch setup! The script which define what get executed! And lastly and importantly problemMatcher!
For the whole tasks setting up! And options you can check the doc!
Here another example for typescript:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
TSLINT is deprecated
Yo ! You just shown how, a line above! Yea there is something important!
We can see typescript problems through tsc compile process! Or Through TSLINT! TSLINT will support code style rules and so on! BUT mmmm TSLINT is deprecated! And ESLINT is taking on! And in simple words use Eslint! And so we can use Eslint for Typescript! And that can be more rich!
Check the link bellow from the official link:
https://code.visualstudio.com/api/advanced-topics/tslint-eslint-migration
And humor face: Don't be affraid to do this
Already did!
Should i migrate Tslint to eslint
Another reason would be: TSLint is a linter that can only be used for TypeScript, while ESLint supports both JavaScript and TypeScript.
Reason for the choice and deprecation is:
In the TypeScript 2019 Roadmap, the TypeScript core team explains that ESLint has a more performant architecture than TSLint and that they will only be focusing on ESLint when providing editor linting integration for TypeScript.
Check it here and how to setup .eslintrc.js without the migration tool!
or https://www.npmjs.com/package/#typescript-eslint/eslint-plugin
Which in short would be like:
module.exports = {
"parser": "#typescript-eslint/parser", // set eslint parser
"parserOptions": {
"ecmaVersion": 12, // latest ecma script features
"sourceType": "module" // Allows for the use of imports
},
"plugins": [
"#typescript-eslint"
],
extends: [
"plugin:#typescript-eslint/recommended" // Uses the recommended rules from the #typescript-eslint/eslint-plugin
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "#typescript-eslint/explicit-function-return-type": "off",
}
};
And sure : npm install --save-dev eslint #typescript-eslint/parser #typescript-eslint/eslint-plugin
Make sure to use eslint --ext .js,.ts when executing eslint! Since by default eslint will only search for .js files.
Make sure to use the code styles versions that support typescript like this one for airbnb:
https://www.npmjs.com/package/eslint-config-airbnb-typescript
(The next section is the most important)!
Processing task output with problem matchers
https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers
VS Code can process the output from a task with a problem matcher. Problem matchers scan the task output text for known warning or error strings, and report these inline in the editor and in the Problems panel. VS Code ships with several problem matchers 'in-the-box':
TypeScript: $tsc assumes that file names in the output are relative to the opened folder.
TypeScript Watch: $tsc-watch matches problems reported from the tsc compiler when executed in watch mode.
JSHint: $jshint assumes that file names are reported as an absolute path.
JSHint Stylish: $jshint-stylish assumes that file names are reported as an absolute path.
ESLint Compact: $eslint-compact assumes that file names in the output are relative to the opened folder.
ESLint Stylish: $eslint-stylish assumes that file names in the output are relative to the opened folder.
Go: $go matches problems reported from the go compiler. Assumes that file names are relative to the opened folder.
CSharp and VB Compiler: $mscompile assumes that file names are reported as an absolute path.
Lessc compiler: $lessc assumes that file names are reported as absolute path.
Node Sass compiler: $node-sass assumes that file names are reported as an absolute path.
OK but you said JAVA, C/C++, PHP, Python ...
=> We need to write our own problemMatcher
C/C++ (GCC)
The c/c++ support in vscode is added through the official ms extension ms-vscode.cpptools
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
The extension provide $gcc problemMatcher!
A task will go as:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build all",
"command": "/usr/bin/g++",
"args": ["${workspaceFolder}/src/*.cpp", "-o", "${workspaceFolder}/build"],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Note that i just made the compilation to go for files in src (one level)
One can use cmake to build!
May like to check :
https://code.visualstudio.com/docs/cpp/config-linux#_build-helloworldcpp
Defining a problem matcher
You can check the doc section bellow:
https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
An example for gcc was given for c/c++!
A compilation outcome will be like:
helloWorld.c:5:3: warning: implicit declaration of function ‘prinft’
We set a matcher by the following
{
// The problem is owned by the cpp language service.
"owner": "cpp",
// The file name for reported problems is relative to the opened folder.
"fileLocation": ["relative", "${workspaceFolder}"],
// The actual pattern to match problems in the output.
"pattern": {
// The regular expression. Example to match: helloWorld.c:5:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
// The first match group matches the file name which is relative.
"file": 1,
// The second match group matches the line on which the problem occurred.
"line": 2,
// The third match group matches the column at which the problem occurred.
"column": 3,
// The fourth match group matches the problem's severity. Can be ignored. Then all problems are captured as errors.
"severity": 4,
// The fifth match group matches the message.
"message": 5
}
}
Directly in the task config that can go as:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "g++",
"args": ["${workspaceFolder}/src/*.cpp", "-o", "${workspaceFolder}/build"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
You can see how staight forward the setting is!
You can check the doc link above for more details!
Defining multiple line problem matcher
https://code.visualstudio.com/docs/editor/tasks#_defining-a-multiline-problem-matcher
Some tools spread problems found in a source file over several lines, especially if stylish reporters are used. An example is ESLint; in stylish mode it produces output like this:
test.js
1:0 error Missing "use strict" statement strict
✖ 1 problems (1 errors, 0 warnings)
I'll not go about the details check the doc! it explains it well (check the loop property too!
{
"owner": "javascript",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
Modifying an existing problem matcher
https://code.visualstudio.com/docs/editor/tasks#_modifying-an-existing-problem-matcher
Simply check the doc!
JAVA
oK now we know, how to make problems matchers! We didn't do java yet! So let's do that for it! (Wait i just googled and here someone that did it)
{
// compiles all files in the folder of the currently opened file
"taskName": "javac all",
"args": ["$env:CLASSPATH += ';${fileDirname}'; javac ${fileDirname}\\*.java -Xlint"],
"showOutput": "silent",
"problemMatcher": {
"owner": "java",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):([0-9]+): (error|warning): (.*)$",
"file": 1,
"line": 2,
"severity": 3,
"message": 4
}
}
}
PHP
Here a php task too that use code sniff!
src (googling again): https://github.com/bmewburn/vscode-intelephense/issues/1102
{
"version": "2.0.0",
"tasks": [
{
"label": "PHP: CodeSniff Workspace",
"type": "shell",
"command": "${config:phpcs.executablePath}",
"args": [
"--standard=${config:phpcs.standard}",
"--extensions=module,inc,install,php,theme,test,js,css",
"--report=csv",
"--basepath=${workspaceFolder}",
"web/modules/custom"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": {
"owner": "php",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\"(.*?)\",(\\d+),(\\d+),(error|warning),\"(.*)\",.*$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Problem matcher and auto fixing
Ok so how the problem matcher make the auto fixing suggestions? The answer is it doesn't! It can be clear! Or you may said at the first time you get to see the problem matcher, hey it may have a relation!
It isn't! The languages support or linters extensions are what provide such a feature! And that through using vscode Action api!
Check
https://code.visualstudio.com/api/references/vscode-api#CodeAction
https://code.visualstudio.com/api/references/vscode-api#CodeActionKind
https://code.visualstudio.com/api/references/vscode-api#CodeActionProvider%3CT%3E
So simply: The problemMatcher set how the output of a task run is parsed and outputed on the problems tab!
And the languages support extension implement the auto fixes! Or linters! (Extensions) [I can make a play ground extension if i want]!
To note too that the yellow bulbe in the problems tab! Works and allow auto fixing! Because the problem matcher provide the line for the problem! That get mapped with the output of the extension fixing suggestions range! That get precised on the CodeActionProvider!
Is not possible right now, the VSCode team have a request for that feature that they are working in, so we must wait.
An alternative is to use a task runner to lint all errors in the project like the one created in this guide.
Visual code has an Extention for ESLINT to integrate the lint errors into the IDE. Whenever you save file, it will show its lint errors. See it: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
For any like me who have encountered this question dozens of times with variations on the google search "c# vs code show all errors in all files", my issue was that I had too many files associated with my project – the C# extension by default starts error checking only open files when you exceed 1000 files total.
Go to Settings => Workspace => Max Project File Count For Diagnostic Analysis, and increase the value to wherever you think is reasonable.
Equivalently, add the following line to your existing settings.json, which increases the file count cutoff to 10,000.
{
// Rest of settings.json file here
"csharp.maxProjectFileCountForDiagnosticAnalysis": 10000,
}
Just run:
npx eslint --init
And configure it as needed