to the top
close form
To get a trial key
fill out the form below
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement

close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS-Studio license for Microsoft MVP specialists
** By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
** By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
** By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
Using the PVS-Studio extension for Visu…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Diagnosis of micro-optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

Using the PVS-Studio extension for Visual Studio Code

Nov 30 2022

You can view PVS-Studio reports in Visual Studio Code with the help of a special PVS-Studio extension. This documentation explains how to install the extension, upload the PVS-Studio report, and handle it.

Note. You cannot run the analysis with the help of PVS-Studio directly from Visual Studio Code. To analyze the code and get the analyzer report you can use:

Installing the PVS-Studio extension

To install the PVS-Studio extension, open Visual Studio Code and click the 'Extensions' tab. Then, type 'PVS-Studio' in the search box and click 'Install':

VSCodeExtension/image1.png

When installing the analyzer on Windows, you can select 'Integration with Visual Studio Code' and then the extension will be added to Visual Studio Code automatically.

VSCodeExtension/image2.png

You can also install the extension on Windows with the help of the pvs-studio-vscode-*.vsix file located in the PVS-Studio directory (%PROGRAMFILES(x86)%\PVS-Studio by default).

To install the plugin from the .vsix file, click the three dots in the upper right corner of the 'Extensions' tab. Then, select 'Install from VSIX...':

VSCodeExtension/image3.png

Select the .vsix file of the PVS-Studio plugin in the appeared window. After installing the plugin, restart Visual Studio Code.

You can also install the extension or download the .vsix file from the PVS-Studio page in the Visual Studio Marketplace.

Handling analysis results

Converting a PVS-Studio report to the JSON format

Note: the PVS-Studio extension for Visual Studio Code supports reports in JSON format only. Depending on the type of checked project and the method of running the analysis, PVS-Studio can generate a report in several formats. To display the report in the extension, you need to convert it to JSON format.

To convert it, you can use command-line utilities: PlogConverter.exe for Windows and plog-converter for Linux and macOS. These utilities allow not only to convert the PVS-Studio report to different formats but also to additionally process it. For example, to filter warnings. You can read more about this here.

Here's an example of a command used to convert the PVS-Studio report to JSON format with the help of PlogConverter.exe (Windows):

PlogConverter.exe path\to\report.plog -t json ^
                                      -n PVS-Studio

Here's an example of a command used to convert the PVS-Studio report to JSON format with the help of plog-converter (Linux and macOS):

plog-converter path/to/report/file.json -t json \
                                        -o PVS-Studio.json

Viewing a converted PVS-Studio report in VS Code

To view the report in Visual Studio Code, click 'Open report' on the PVS-Studio panel and select the required file. You can also open the report using the keyboard shortcut 'Ctrl+Shift+]', or press 'Ctrl+Shift+P' and type 'PVS-Studio: Show Report'.

VSCodeExtension/image4.png

After that, the warnings from the report will be displayed on the panel:

VSCodeExtension/image5.png

For convenient work with the table, attach it to the panel. To do this, right-click the panel header and select "Keep 'PVS-Studio'".

VSCodeExtension/image7.png

To handle a report containing relative paths, you need to use the 'Source Tree Root' setting. To do this, open the Settings panel, choose the 'Other tab', click 'Browse', and select the directory relative to which all paths in the report file will be expanded.

VSCodeExtension/image8.png

Filtering warnings

PVS-Studio output window filtering mechanisms allow to quickly find and display diagnostic messages. They can be displayed separately and in groups. The toolbar of the window contains a number of buttons that allow to enable or disable the display of warnings from their corresponding groups.

All buttons can be divided into 3 groups: filters by the warnings' levels of certainty, message filters by diagnostic groups, filters by keywords. You can filter warnings by the message code, by the message text, and by the file containing the analyzer message.

You can find a detailed description of the levels of certainty and groups of diagnostic rules in the following documentation section: "Getting acquainted with the PVS-Studio static code analyzer on Windows".

To open the filtering panel by groups, click 'Show filters' on the window toolbar.

VSCodeExtension/image9.png

You can combine all of these warning filtering mechanisms with each other. For example, you can filter messages by the level and groups of displayed warnings, or exclude messages marked as false alarms, etc.

Navigation and sorting

The PVS-Studio output window is primarily designed for easier code navigation. It also simplifies jumping to code fragments containing potential errors. Double-clicking on any of the warnings in the list will automatically open the file for which the analyzer issued a message.

To mark interesting warnings, for example, those that you want to view later, you can use the "asterisk" in the corresponding column.

Right-clicking on the table header opens a context menu where you can customize the displayed columns.

VSCodeExtension/image11.png

Other features

The table supports multiple selection with the help of standard 'Ctrl' and 'Shift' combinations. The context menu of the warning table contains several items:

VSCodeExtension/image12.png
  • Mark as Favorite — marks selected messages as favorites;
  • Mark as False Alarm — marks selected messages as false alarms and adds a special comment to the source code;
  • Copy message — copies the diagnostic number, the warning message, and the file for which the warning is issued to the clipboard;
  • Exclude diagnostic — excludes the display of all warnings with the same diagnostic number as the highlighted one;
  • Exclude paths — allows to exclude the path to the selected file or a part of this path. All warnings issued for files containing the selected path will not be shown.
VSCodeExtension/image13.png

The items on the right side of the panel are designed, respectively, to save the report, open a new report, open the extension settings. If a report contains some changes, the save report item will become red, as shown in the screenshot below.

VSCodeExtension/image14.png

Plugin settings

To open the settings window, click on the rightmost item of the panel, or use 'Ctrl+Shift+P' and enter 'PVS-Studio: Show Settings'.

The 'Save settings' item saves the settings in JSON format. To load the saved settings, use the 'Load settings' item.

False alarms

In the False Alarms tab, you can choose whether to:

  • show False alarms or not;
  • save the source files automatically when the warning is marked as False Alarm;
  • add an additional message to false alarm commentary.
VSCodeExtension/image16.png

Columns

This tab allows you to mark columns that should be displayed in the table of warnings.

Diagnostics

The Diagnostics tab allows to mark the warnings that should be displayed in the table of warnings. All warnings are divided into groups. To search for a specific diagnostic rule, you can use the 'Code and Messages' field. 'Check all/Uncheck all' are designed to enable/disable the display of all diagnostic rules from a certain group. When disabling all diagnostic rules from the corresponding group, the button of this group is removed from the filtering panel.

VSCodeExtension/image17.png

Exclude paths

The Exclude paths tab allows to enter paths or path masks in the 'New excluded path' field. Messages issued for files that meet the mask conditions will not be displayed in the warnings panel.

Other

Documentation language. The setting allows to set the language for the built-in documentation of PVS-Studio diagnostic rules available on our website.

This setting does not change the interface language of the PVS-Studio extension or the diagnostic messages issued by the analyzer.

Source Tree Root. To handle the PVS-Studio report containing relative file paths, you need to replace them with absolute ones. The setting allows to set the directory relative to which all paths in the report file are disclosed.

You can find a detailed description of using relative paths in the PVS-Studio report files here.

Unicorn with delicious cookie
Our website uses cookies to enhance your browsing experience.
Accept