﻿# How to use PVS\-Studio extension for Visual Studio Code

The PVS\-Studio extension for Visual Studio Code enables viewing analysis results, running analysis of CMake, MSBuild, Java, JS, TS, and Go projects, and using compilation monitoring on Windows\. This documentation explains how to use this extension\.


> \*\*Note\*\*\\\. The analyzer should be \[downloaded\]\(https://pvs\-studio\.com/en/pvs\-studio/download\-all/\) and installed before using the extension\\\.

## Watch, don't read \(YouTube\)

<https://www.youtube.com/watch?v=hsgvsQFzNcE>

## How to install the extension

Here are several ways to install the extension\.


> \*\*Note\\\.\*\* The extension requires Visual Studio Code 1\\\.100\\\.0 or later\\\.



### Via the Extension Marketplace

To install the PVS\-Studio extension, open **Visual Studio Code** **\>** **Extensions**, enter "PVS\-Studio" in the search field, and click the **Install** button\.

![VSCodeExtension/image1.png](https://import.viva64.com/docx/blog/VSCodeExtension/image1.png)

Note that the marketplace installs **only** the PVS\-Studio **extension** for Visual Studio Code It requires the installed analyzer on your system\. You can download it [here](https://pvs-studio.com/en/pvs-studio/download/)\.

### Via the PVS\-Studio installer

When installing the analyzer on Windows, select **Integration with Visual Studio Code** in the installer menu\. The PVS\-Studio extension will then be automatically added to Visual Studio Code\.

![VSCodeExtension/image2.png](https://import.viva64.com/docx/blog/VSCodeExtension/image2.png)

### Via the \.vsix file

The PVS\-Studio extension file is available in the `.vsix` format on the PVS\-Studio page of the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=EvgeniyRyzhkov.pvs-studio-vscode)\.

The `pvs-studio-vscode-*.vsix` file is unpacked when you install the analyzer \(the default path: `PROGRAMFILES(x86)%\PVS-Studio` for Windows, `/usr/lib/pvs-studio/plugins` for Linux and macOS\)\.

To install the extension from this file, open the **Extensions** tab, click the three dots in the upper\-right corner, and click **Install from VSIX**\.

![VSCodeExtension/image3.png](https://import.viva64.com/docx/blog/VSCodeExtension/image3.png)

### Installation result

After installation, the **PVS\-Studio** window appears as a tab at the bottom of the Visual Studio Code interface\. If the window is hidden, you can display it using the **PVS\-Studio: Show** **window** command in the command palette \(`Ctrl + Shift + P`\)\.

![VSCodeExtension/image4.png](https://import.viva64.com/docx/blog/VSCodeExtension/image4.png)

## How to run the analysis

There are several ways to run the analysis:

1\. Using the **Start analysis** button:

![VSCodeExtension/image5.png](https://import.viva64.com/docx/blog/VSCodeExtension/image5.png)

It runs the analysis of the entire project\.

2\. Using the context menu of the code editor:

![VSCodeExtension/image6.png](https://import.viva64.com/docx/blog/VSCodeExtension/image6.png)

It runs the analysis for a single file\. Note that if this menu item is missing, the analysis of the current file is not supported\.

3\. Using the context menu of the file explorer:

![VSCodeExtension/image7.png](https://import.viva64.com/docx/blog/VSCodeExtension/image7.png)

It runs the analysis for all supported files that have been selected\. If folders are selected, all files in them and their subdirectories will be analyzed\.

4\. Using the menu of the editor tab group:

![VSCodeExtension/image8.png](https://import.viva64.com/docx/blog/VSCodeExtension/image8.png)

It runs the analysis of the supported files opened in the current tab group\. 

5\. Using the **Run regular analysis** and **Run intermodular analysis** commands in the command palette \(`Ctrl+Shift+P`\)

![VSCodeExtension/image9.png](https://import.viva64.com/docx/blog/VSCodeExtension/image9.png)

Both commands run a general solution analysis\. The difference is relevant only for C and C\+\+ code\. In this mode, the analyzer performs deeper analysis but takes longer\.

If no suitable target for analysis is found in the VS Code directory, a message will be displayed\.

On **Windows:**

![VSCodeExtension/image10.png](https://import.viva64.com/docx/blog/VSCodeExtension/image10.png)

For some C and C\+\+ compilers on Windows, you can use compilation monitoring for the analysis\. You can read about how to use it [here](https://pvs-studio.com/en/docs/manual/0031/#vscode)\.

On **Linux:**

![VSCodeExtension/image11.png](https://import.viva64.com/docx/blog/VSCodeExtension/image11.png)

You may be prompted to configure settings specific to projects that use a particular build system\. For more information on analyzing a specific project type, refer to the documentation sections: 

* [How to analyze C, C\+\+ \(CMake\) projects](https://pvs-studio.com/en/docs/manual/6646/#cmake); 
* [How to analyze C\# \(MSBuild\) projects](https://pvs-studio.com/en/docs/manual/6646/#msbuidl);
* [How to analyze Java projects](https://pvs-studio.com/en/docs/manual/6646/#java);
* [How to analyze JavaScript and TypeScript projects](https://pvs-studio.com/en/docs/manual/6646/#javascript);
* [How to analyze Go projects](https://pvs-studio.com/en/docs/manual/6646/#golang)\.

If the analysis starts successfully, the **PVS\-Studio** window will display:

![VSCodeExtension/image12.png](https://import.viva64.com/docx/blog/VSCodeExtension/image12.png)

The analysis progress will be displayed in the upper\-right corner of the window\. An interrupt button will appear next to it\. Warnings will appear in the table as they are detected\.

## How to analyze C and C\+\+ \(CMake\) projects

To run the CMake project analysis, install the [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extension and build the project using it\.

The plugin is compatible with the following build systems:

* Ninja
* Makefile Generators

If an unsupported generator is detected, or no generator is installed, a dialog will prompt users to change the parameter in the CMake Tools settings:

![VSCodeExtension/image13.png](https://import.viva64.com/docx/blog/VSCodeExtension/image13.png)

Click **Edit setting** to open a page with the `cmake.generator` setting: 

![VSCodeExtension/image14.png](https://import.viva64.com/docx/blog/VSCodeExtension/image14.png)

In CMake Tools, you can specify the preferred path to the build files folder using the `cmake.buildDirectory` setting \(by default, it is `/build` in the project folder\):

![VSCodeExtension/image15.png](https://import.viva64.com/docx/blog/VSCodeExtension/image15.png)

This parameter is important for the analysis because PVS\-Studio expects to find the `compile_commands.json` file in this directory\.

To build the project, click the **Build** button at the bottom\-left of the IDE window:

![VSCodeExtension/image16.png](https://import.viva64.com/docx/blog/VSCodeExtension/image16.png)


> \*\*Note\\\.\*\* For more information about other CMake Tools extension features, \[see the CMake Tools for Visual Studio Code documentation\]\(https://github\.com/microsoft/vscode\-cmake\-tools/blob/HEAD/docs/README\.md\)\\\.

Before running the analysis, you can select the analysis type: intermodular or regular\. Intermodular analysis takes longer but provides better results\. For more details about this mode, see the [documentation](https://pvs-studio.com/en/docs/manual/6521/#ID33D82545C7)\.

The contents of the `.PVS-Studio` folder in the project directory are also considered when running the analysis\. User [configuration files](https://pvs-studio.com/en/docs/manual/6630/) \(`.pvsconfig`\) and [suppress files](https://pvs-studio.com/en/docs/manual/0032/) \(`.suppress.json`\) will be passed to the analyzer for further handling if they are detected\.


> \*\*Note\\\.\*\* Currently, only one suppress file is supported for checking CMake projects\\\. If several files are detected upon running the tool, a message will appear in the report, indicating which file is analyzed\\\.

## How to analyze C\# \(MSBuild\) projects

The first time a solution is analyzed, a notification will appear indicating that a file has been created in `/.PVS-Studio/MSBuildAnalyzerConfig.jsonc` within the directory opened in the IDE\. There, you can configure analysis settings that are identical to the [parameters in the console version of the analyzer](https://pvs-studio.com/en/docs/manual/0035/#IDE1BD96B458)\.

![VSCodeExtension/image17.png](https://import.viva64.com/docx/blog/VSCodeExtension/image17.png)

Here are the options:

* **Edit** opens the created file \(analysis will not start\);
* **Continue** runs the analysis with default settings;
* **Cancel** cancels the analysis \(the file will not be created\)\.

In this same file, you can specify the files and parameters that will be considered during the analysis:

* [suppress files](https://pvs-studio.com/en/docs/manual/0032/) \(with the `.suppress.json` extension\);
* [configuration files](https://pvs-studio.com/en/docs/manual/6630/) \(with the `.pvsconfig`extension\); 
* a platform and build configuration;
* specific projects \(`.csproj` and `.vcxproj`\) and files \(`.cs`, `.cpp`, etc\.\) for analysis; 
* other settings described in the file and in the [documentation](https://pvs-studio.com/en/docs/manual/0035/#IDE1BD96B458)\.


> \*\*Note\\\.\*\* When you run the analysis of specific files via the context menus or editor tab group menus, only files included in the selected solution will be analyzed\\\. 
> 
> 
> 
> If a project file \\\(with the \`\.csproj\` or \`\.vcxproj\` extension\\\) is found among the analyzed files, all supported files included in this project will be analyzed\\\.

## How to analyze Java projects

To make PVS\-Studio identify your project in the opened directory, the [Project manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency) extension should be installed and enabled in Visual Studio Code\.

### Configuration

By default, the PVS\-Studio extension searches for the analyzer core in one of the following directories:

* **Windows**: `C:\Users\[User]\AppData\Roaming\PVS-Studio-Java`;
* **Linux/macOS**: `~/.config/PVS-Studio-Java`\.

If the core is located in another folder, specify its path in the extension settings \(**File \> Preferences \> Settings \> PVS\-Studio: Java Projects Analyzer** or the `pvsStudio.javaProjectsAnalyzer.path` setting\)\.

To run the analyzer core, JDK 11\-21 is required\. By default, the JDK specified in the environment variables is used\. If the JDK version is not supported, install the supported JDK and specify its path in the Visual Studio Code settings \(**File \> Preferences \> Settings \> PVS\-Studio: Java For Running Analyzer** or the `pvsStudio.javaProjectsAnalyzer.javaPath` setting\)\.

Before starting the analysis, it is recommended to run the **Java: Reload Projects** command in the command palette \(`Ctrl + Shift + P`\)\. If a drop\-down list with project modules displays after that, ensure all modules to be analyzed are selected:

![VSCodeExtension/image18.png](https://import.viva64.com/docx/blog/VSCodeExtension/image18.png)

### How to run the analysis

The first time the project is analyzed, a notification will appear indicating that a file has been created in `/.PVS-Studio/ JavaAnalyzerConfig.jsonc` within the directory opened in the IDE\. There, you can configure analysis settings that are identical to the [parameters in the console version of the analyzer](https://pvs-studio.com/en/docs/manual/6703/)\.

![VSCodeExtension/image17.png](https://import.viva64.com/docx/blog/VSCodeExtension/image17.png)

Here are the options:

* **Edit** opens the created file \(the analysis will not start\);
* **Continue** runs the analysis with default settings;
* **Cancel** cancels the analysis \(the file will not be created\)\.

In this same file, you can specify the files and parameters that will be included in the analysis:

* the path to the suppress file \(with the `. suppress.json` extension\);
* enable/disable incremental analysis \(disabled by default\);
* enable/disable the [V6078](https://pvs-studio.com/en/docs/warnings/v6078/) special diagnostic rule that detects potential API compatibility issues among selected Java SE versions \(specified as separate parameters\)\.

## How to analyze JavaScript and TypeScript projects

To analyze JavaScript and TypeScript projects, no additional extension configuration is required\. Just run the analysis with the project directory containing the `.js` and/or `.ts` files open in Visual Studio Code\.

To further configure the JavaScript and TypeScript analyzer, use the `pvs-settings.toml` configuration files; you can learn more about them [here](https://pvs-studio.com/en/docs/manual/7193/)\.

## How to analyze Go projects

To analyze Go projects, no additional extension configuration is required\. Just run the analysis with the project directory containing the `go.mod` or `go.work` file open in Visual Studio Code\.

To further configure the Go analyzer, use the `pvs-settings.toml` configuration files; you can learn more about them [here](https://pvs-studio.com/en/docs/manual/7193/)\.

## How to handle analysis results

### Converting a PVS\-Studio report to JSON format

**Note**\. The PVS\-Studio extension for Visual Studio Code supports only reports in JSON format\. Depending on the analyzed project type and how the analysis is run, PVS\-Studio can generate a report in one of several formats\. To display the report in the extension, convert it to the JSON format\.

To do this, you can use command\-line utilities: `PlogConverter.exe` on Windows and `plog-converter` on Linux and macOS\. They enable not only converting the PVS\-Studio report into various formats, but also additional handling, such as filtering warnings\. You can read more about this [here](https://pvs-studio.com/en/docs/manual/0038/)\.

The example of the PVS\-Studio report conversion command using `PlogConverter.exe` \(Windows\):

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

The example of the PVS\-Studio report conversion command using `plog-converter` \(Linux and macOS\):

```cpp
plog-converter path/to/report/file.plog -t json \
                                        -a ALL \
                                        -o PVS-Studio.json
```

### Viewing the converted report

To view the report in Visual Studio Code, click the **Open report** button in the **PVS\-Studio** window and select the appropriate file\. You can also open the report by selecting **PVS\-Studio: Load Report** in the command palette \(`Ctrl+Shift+P`\):

![VSCodeExtension/image19.png](https://import.viva64.com/docx/blog/VSCodeExtension/image19.png)

After this, the report with warnings will be displayed in the table:

![VSCodeExtension/image20.png](https://import.viva64.com/docx/blog/VSCodeExtension/image20.png)

For easier access to the table, pin it to the panel\. To do this, right\-click the panel header and check the **PVS\-Studio** box if it is unchecked:

![VSCodeExtension/image21.png](https://import.viva64.com/docx/blog/VSCodeExtension/image21.png)

To work with a report containing relative paths, use the **Source Tree Root** setting\. To do this, open the settings window, click the **Browse** button in the **Other** tab, and select the directory relative to which all paths in the report file will be expanded\.

![VSCodeExtension/image22.png](https://import.viva64.com/docx/blog/VSCodeExtension/image22.png)

### Filtering warnings

The PVS\-Studio output window filtering mechanisms enable quick finding and displaying of both individual diagnostic rules and entire groups\. There are switches among the window tools that enable or disable warnings from the groups\.

All switches fall into three groups: 

* **Level:** filters by warning certainty levels;
* **Group:** message filters by diagnostic rule groups;
* **Filter:** filters by keywords \(by message ID, by message text, and by file name with the analyzer message\. 


> \*\*Note\\\. \*\*To learn more about the certainty levels of warnings and diagnostic rule groups, see the \[documentation\]\(https://pvs\-studio\.com/en/docs/manual/0007/\)\\\.

You can enable/disable the filter group using the corresponding buttons:

![VSCodeExtension/image23.png](https://import.viva64.com/docx/blog/VSCodeExtension/image23.png)

All of the above warning filtering mechanisms can be used together\. For example, you can filter messages by warning level and group, and exclude those marked as false positives\.

### Suppressing warnings

The analyzer may issue many warnings for the first\-time analysis of a large project\. In this case, you can use the warning suppression mechanism to hide less important warnings\.

To suppress all warnings, click the **Suppress All Messages** button in the upper\-right corner of the window:

![VSCodeExtension/image24.png](https://import.viva64.com/docx/blog/VSCodeExtension/image24.png)

When this option is enabled, a dialog appears asking which warnings you want to suppress:

* **Suppress All** suppresses all warnings in the table \(even those hidden by filters and settings\);
* **Suppress Filtered** suppresses only the warnings in the table\.

![VSCodeExtension/image25.png](https://import.viva64.com/docx/blog/VSCodeExtension/image25.png)

The selected option suppresses warnings in the existing suppress file\. If the file is missing or cannot be found, it will be created in the `/.PVS-Studio` directory within the project\.

If this option is not suitable, you can use selective warning suppression instead\. To do this, select the required lines in the table, open the context menu, and select **Add message to suppression file**:

![VSCodeExtension/image26.png](https://import.viva64.com/docx/blog/VSCodeExtension/image26.png)

### Navigating & sorting

The PVS\-Studio results window is designed to simplify navigation through project code, allowing users to quickly jump to sections containing potential errors\. Double\-clicking any warning in the list automatically opens the file that the message refers to\.

To mark warnings that you want to revisit later, click the star icon in the left column\.

Right\-clicking the table header opens a context menu where you can configure the displayed columns:

![VSCodeExtension/image27.png](https://import.viva64.com/docx/blog/VSCodeExtension/image27.png)

### Other features

The table supports multi\-selection via the standard `Ctrl` and `Shift` combinations\. 

The context menu of the warning table contains several sub\-items: 

![VSCodeExtension/image28.png](https://import.viva64.com/docx/blog/VSCodeExtension/image28.png)

* **Mark as Favorite** marks the selected messages as favorites\.
* **Mark as False Alarm** marks the selected messages as false alarms and adds a special comment to the source code\.
* **Copy message** copies the diagnostic rule number and message, as well as the file path of the selected warning to the clipboard\.
* **Exclude** **diagnostic** excludes all warnings with the same code as the selected one\.
* **Exclude** **paths** excludes a path or part of a path to the selected file\. Warnings for files with the selected path will not be displayed\. 

![VSCodeExtension/image29.png](https://import.viva64.com/docx/blog/VSCodeExtension/image29.png)

The buttons on the right side of the panel are used to start analysis, suppress warnings, save reports, open a new report, and open the extension settings\. If any changes are made to the report, the button turns red, as shown in the screenshot:

![VSCodeExtension/image30.png](https://import.viva64.com/docx/blog/VSCodeExtension/image30.png)

## How to configure the plugin 

To open the settings window, click the button on the far\-right of the **PVS\-Studio** window or open the command panel \(`Ctrl+Shift+P`\) and enter **PVS\-Studio: Show Settings**\.

The settings in the panel are divided into **Extension Settings** and **Analyzer Settings**:

Use the drop\-down list in the upper\-right corner of the settings panel to select the analyzer you want to configure:



In addition to configuring via the UI, you can also use the `pvs-settings.toml` configuration file\. Learn more about it [here](https://pvs-studio.com/en/docs/manual/7193/)\.

### Analyzer settings groups

### Analysis

The **Analysis** settings group enables configuring:

* the maximum duration allowed for analysis before it stops \(**Timeout**\);
* the number of threads used during the analysis \(**Thread Count**\);
* the directory relative to which all paths in the report file are expanded \(**Source Tree Root**\);
* the removal of temporary files \(**Remove Intermediate Files**\);
* the addition of markers in the SAST column for warnings related to potential security issues \(**Security Related Issues**\)\.

You can also enable the legacy C\+\+ code parser for the C and C\+\+ analyzer\.



### Excluded paths

The **Excluded paths** tab enables entering paths or path masks in the **New excluded path wildcard** field\. Messages for files that match the mask conditions will not appear in the warning table\.

![VSCodeExtension/image31.png](https://import.viva64.com/docx/blog/VSCodeExtension/image31.png)

### Diagnostics 

The **Diagnostics** tab enables marking which warnings should be displayed in the warning table\. 

All warnings are divided into groups\. To find a specific diagnostic rule, you can use the **Code or message** field\. 

To enable/disable the display of all diagnostic rules from a specific group, use **Check all**/**Uncheck all**\. 

If all diagnostic rules in a group are disabled, the corresponding toggle is removed from the plugin window\.

![VSCodeExtension/image32.png](https://import.viva64.com/docx/blog/VSCodeExtension/image32.png)

#### Coding Standards

This settings tab enables selecting the versions of coding standards that you want to use\.

#### Monitoring

The C and C\+\+ analyzer on Windows has an additional **Monitoring** settings tab that enables you to configure compilation monitoring\.

Use the **Wrap compilers** field in this tab to enter the names of the compiler files you want to track, separated by commas\.

### Extension settings groups 

Interface The **Interface** tab enables configuring:

* the display of false alarms;
* the automatic saving of source files when a warning is marked as false;
*  columns that will appear in the warning table\.





### License

The **License** tab enables entering your analyzer username associated with the license key and license key\. If you entered valid data, a message containing the license information will appear\.

## Managing PVS\-Studio plugin versions

PVS\-Studio plugin for VS Code is strictly bound to the installed analyzer version\. Plugins are automatically updated by default, which can lead to desynchronization between the plugin and analyzer versions\. To avoid potential compatibility issues, either disable automatic plugin updates or update PVS\-Studio analyzer\.

To disable automatic updates in VS Code, open **Extensions** and find **PVS\-Studio** plugin\. Open its settings and uncheck the **Auto Update** checkbox\. 

![VSCodeExtension/image33.png](https://import.viva64.com/docx/blog/VSCodeExtension/image33.png)

VS Code enables installing the required plugin version\. To enable it, open the dropdown next to the **Uninstall** button and select **Install Specific Version**\. 

![VSCodeExtension/image34.png](https://import.viva64.com/docx/blog/VSCodeExtension/image34.png)

Then, choose the required version, which will be installed automatically\.

![VSCodeExtension/image35.png](https://import.viva64.com/docx/blog/VSCodeExtension/image35.png)