Run Polyspace as You Code in Visual Studio and Review Results

You can choose to run Polyspace as You Code on each save in the Visual Studio IDE, or at will. The analysis runs on the file that is currently active in the IDE (the file must be part of a Visual Studio project, which can be part of a larger Visual Studio solution). After analysis, you see bugs and coding standard violations as source code markers or in a separate list.

Confirm Installation of Extension

To confirm that your Visual Studio installation has the Polyspace as You Code extension, check the list of extensions installed.

  • In Visual Studio 2019, select Extensions > Manage Extensions.

  • In Visual Studio 2017, select Tools > Extensions and Updates.

You can also confirm that the extension starts as expected on the Output pane. Select View > Output and then from the dropdown, select Polyspace. If the extension starts without errors, you see a message such as:

11/25/2020 3:59:37 PM.005: Please wait while Polyspace Connector is starting on port '9091'...
11/25/2020 3:59:41 PM.229: Polyspace Connector has started successfully.

The Polyspace Connector is an internal server that handles communication between the Polyspace as You Code analysis engine and the Visual Studio extension. If the default port is not available, the extension increments the port number and attempts to start the Polyspace Connector on the next port. If you use multiple Visual Studio instances, you can run Polyspace as You Code on all the instances. The Polyspace Connector in each instance uses a different port.

Run Analysis on Save

By default, Polyspace as You Code is configured to run analysis on save. Analysis results appear within a few seconds but in case of an error, you can check the progress of analysis on the Output pane.

After analysis, results appear as source code markers (lines below source code tokens). You also see the error locations as red circles in the scroll bar on the left.

To disable analysis on save:

  1. Select Tools > Options.

  2. On the Polyspace node, in the Analysis launch mode section, select Manually.

If results do not appear, see Troubleshoot Failed Analysis or Unexpected Results in Polyspace as You Code.

Run Analysis on Demand

You can also explicitly start a Polyspace analysis. To start an analysis, right-click a source file in the Visual Studio Solution Explorer or right-click on the source file content itself, and select Run Polyspace analysis.

Review Results

After analysis, the results appear in two forms:

  • As source code markers (with a line below source code tokens).

    You can hover on a source code token to see more details about a result.

    Tooltip on an array access out of bounds defect

  • In a list on the Polyspace Results List pane.

    To open the pane, select View > Other Windows > Polyspace Results List.

    The results list shows results only for the file that is currently active in the IDE. For instance, if you switch to another file, the results list shows defects found in the new file that is active.

    If you select a result in this list, you see further details of the result on the Polyspace Result Details pane.

Justify Results Using Code Annotations

If you decide not to fix a result, you can add code annotations to the result to avoid another review. If the annotations follow a specific syntax, subsequent Polyspace as You Code runs can read these annotations and suppress the corresponding results.

To add a code annotation, click the source code token containing a result. Click the light bulb icon that appears and select Polyspace Annotate finding result_name. The annotation is entered on the same line as the result.

Click light bulb icon to justify result with annotation

See also:

View Help

You can see more information on a type of result by visiting the context-sensitive help page for the result.

  • To open the context-sensitive help for a result, first open the Polyspace Result Details pane for a result. Then, click the question mark icon next to the result details.

  • To navigate directly to the Fix section of the context-sensitive help for a result, click the wrench icon next to the result details.

Open result details pane to visit context-sensitive help

You can also open the full searchable documentation for the Polyspace as You Code extension from within Visual Studio. To open the documentation, select Help > Open Polyspace Product Help.

Configure Checkers and Other Settings

By default, Polyspace as You Code checks for defects that are likely to be of most interest to developers. You can expand the set of checkers and perform other configuration through the Polyspace as You Code extension settings in Visual Studio. To open the settings, select Tools > Options and specify appropriate settings on the Polyspace node.

For instance, you might want to:

For the full list of settings, see Configure Polyspace as You Code Extension in Visual Studio.