Main Content

Run and Review Results in Polyspace as You Code for Visual Studio Code

After you configure the Polyspace as You Code extension, you are ready to run an analysis and fix or justify any findings. Before continuing this guide, confirm you have added example.hpp and example_source.cpp to the Quality Monitoring list.

Run Polyspace as You Code Analysis in Visual Studio Code

You can run an analysis in these ways.

  • If you set Analysis Of Files On Save, save your edited file to run an analysis.

  • Right-click a file and select Run Polyspace Analysis.

  • Manually add your file to the Quality Monitoring list and click the Run Polyspace Analysis button run polyspace analysis icon to analyze your file.

Click the Run Polyspace Analysis next to example_source.cpp to run an analysis.

 Manually Run Analysis

View, Fix, or Justify Findings

After Polyspace runs the analysis, the filename in the Quality Monitoring pane is green if there are no findings and red if there are findings. A number to the right of the filename indicates the number of findings. View your findings in the Problems pane. Open the Problems pane by clicking the filename in the Quality Monitoring pane.

The Problems pane shows all findings as a list. Use the filter within the Problems pane to search for specific findings. Each finding contains a line and column number to indicate where the finding exists within your code.

After you run an analysis on the example code, open the results in the Problems pane. Use the filter to search for A16-2-3. There is one result on line five, column five.

Click the finding in the Problems pane to open the file that contains the finding. Each finding is noted in the file with a red underline. Hover over the underlined sections of code to see a list of each finding associated with the problem.

In the example code, add this include on line two:

#include <cstdint>
Save this change and run another analysis. The A16-2-3 error on line five is no longer present.

With automatic analysis active, you can find and fix findings during the code authoring process. Each time you save changes, a Polyspace analysis begins in the background and displays any new findings or removes fixed findings from the list.

 View and Fix Findings

Justify Individual Findings

You can justify a finding from the Problems pane or from the location of the finding within the code.

Click on a finding in the Problems pane to change the red error icon error icon to a light bulb icon light bulb icon. Click on the light bulb icon and select the appropriate justification from the menu. This adds a comment to your code which you can amend. Adding a justification removes the finding from the Problems pane. To show the finding again, remove the justification comment and perform the analysis.

 Justify Findings

Provide Justification Catalog

You can add a catalog of predefined justifications to Polyspace as You Code. The justification catalog allows you to select a prewritten justification instead of manually typing each justification comment.

Open the Visual Studio Code Settings and search for polyspace.justification.catalog. Enter the path to your justification catalog in the text box relative to the install location. The catalog must be in JSON format. If you do not already have a justification catalog, use the example JSON file.

example_catalog.json

{
	"justifications": [
		{
		"family": "Defect",
		"acronym": "INT_ZERO_DIV",
		"comment": "This is my justification for division"
		},
		{
		"family": "Defect",
		"acronym": "INT_ZERO_DIV",
		"comment": "Alternative justification for division"
		}
	]
}

 Provide a Justification Catalog

View Header Findings

When you analyze source files, any header file findings are shown in the Problems pane. If a header contains a finding, it is noted with a red H next to the source file in the Quality Monitoring list.

Click a header finding in the Problems pane to go to the header file that contains the finding. To find which source file analysis caused the header finding, click the light bulb icon light bulb icon next to the finding in the Problems pane and then click the option to show details about the finding.

 View Header Findings

Check for Potential Duplicate Code

Polyspace checks for potential copy and paste errors, duplicate code, and other code refactoring opportunities.

Click Possible copy-paste error in the Problems pane to view more information in the Result Details pane. Expand the Traceback node to locate the duplicate sections occur and view further details. To view the potential error in the Visual Studio Code peek window, point to Possible copy-paste error in the Result Details pane and click the Toggle peek view in source icon toggle peek view in source icon.

 Check for Potential Duplicate Code