Configure Polyspace as You Code Extension in Visual Studio Code

After installing the Polyspace as You Code analysis engine and IDE extension, configure the extension so that a Polyspace® analysis runs smoothly when you save your code or explicitly start an analysis. An analysis has run smoothly if results appear as expected, either as source code markers with tooltips or in a list on the PROBLEMS pane.

To configure the extension, in Visual Studio Code, open the settings interface by pressing Ctrl + , (comma) and type polyspace in the settings search bar.

For each setting, you can specify a value that applies globally to all workspaces or folders that you open in the Visual Studio editor. For some of the settings, you can also override the global specification with a workspace-specific value.

  • To specify global settings, enter the settings on the User tab.

  • To override the global settings for the currently open workspace or folder, enter the settings on the Workspace tab.

To reset a setting to its default value, click the settings icon icon on the left of the setting and select Reset Setting. All settings retain their current values when you reinstall the extension.

Tip

Type the Setting ID in the settings search bar to view only the settings related to that ID.

Analysis Engine

Setting ID: polyspace.analysisengine

These settings are mandatory.

SettingDescriptionAvailable Per Workspace?
Polyspace Installation FolderRoot folder of the Polyspace as You Code installation, for instance, C:\Program Files\Polyspace as You Code\R2021a.No
Result FolderFolder where analysis results are stored. Each new run overwrites results of the previous run.Yes

Analysis Launch Mode

Setting ID: polyspace.analysisoptions.analysislaunchmode

By default, Polyspace as You Code runs each time you save your code. You can choose to disable the automatic runs.

SettingDescriptionAvailable Per Workspace?
Analysis Options: Analysis Launch Mode

Select when Polyspace as You Code must run:

  • Automatically (default): The analysis must run on each save.

  • Manually: Choose to explicitly start the analysis. You can right-click a source file and select Polyspace: Analyze Current File (or run the same command from the Command Palette).

Yes

Analysis Setup

Setting ID: polyspace.analysisoptions.analysissetup

You can set up a Polyspace as You Code analysis through extension settings or override extension settings and run a script instead. By default, the analysis uses extension settings.

SettingDescriptionAvailable Per Workspace?
Analysis Options: Analysis Setup

Select between manual setup and script.

  • Manual Setup (default): Set up Polyspace as You Code through extension settings. Specify build-related and other options through the Manual Setup group of settings.

  • Script: Run a script each time you save your code (or right-click a source file and select Polyspace: Analyze Current File). The script takes the path to the current file as the first argument and the results folder as the second argument. All other extension settings are ignored.

Yes

Analysis Options > Manual Setup

Setting ID: polyspace.analysisoptions.manualsetup

Manual setup of the analysis involves specifying build options, checkers and other analysis options. Extract build options from a Visual Studio Code build task or a JSON Compilation Database file, or specify them explicitly in a build options file. Enable or disable checkers in a checkers selection window. Specify all remaining analysis options explicitly in an options file.

SettingDescriptionAvailable Per Workspace?
Analysis Options > Manual Setup: BuildSpecification of build-related Polyspace analysis options. Options are:
  • Build options file not required (default): You do not have to specify Polyspace options related to building your files. This is a basic option for simple projects where the default Polyspace analysis options are sufficient to compile the files.

  • Get from JSON Compilation Database file: The analysis must create build options from a JSON compilation database. Specify the path to the database file (typically named compile_commands.json) in the setting Analysis Options > Manual Setup > Build Setting: JSON Compilation Database File.

    Later, when you run Polyspace: Analyze Build in the Command Palette, the polyspace-configure command creates build-related Polyspace analysis options from this database file using the option -compilation-database. Subsequent runs of Polyspace as You code use these options.

  • Get from build task: The analysis must extract build options from a Visual Studio Code build task. Use a build task that performs a complete build of all files in your workspace. Specify the build task name in the setting Analysis Options > Manual Setup > Build Setting: Build Task.

    Later, when you run Polyspace: Analyze Build in the Command Palette, the polyspace-configure command runs on the command underneath this build task and creates Polyspace analysis options. Subsequent runs of Polyspace as You code use these options.

  • Get from build command: The analysis must extract build options from a build command. Make sure that the command builds all source files in your workspace. Specify the build command in the setting Analysis Options > Manual Setup > Build Setting: Build Command.

    Later, when you run Polyspace: Analyze Build in the Command Palette, the polyspace-configure command runs on the build command and creates Polyspace analysis options. Subsequent runs of Polyspace as You code use these options.

  • Get from Polyspace build options file: Provide the build options in the options file that you specify in the setting Analysis Options > Manual Setup > Build Setting: Polyspace Build Options File.

Yes
Analysis Options > Manual Setup > Build Setting: Build Command

Use this setting if you choose Get from build command for the setting Analysis Options > Manual Setup: Build.

Specify the build command name exactly as you would enter on a command-line terminal or console.

Use a build command that performs a complete build of all files in your workspace and not an incremental build.

See Get Build Configuration from Build Command

Yes
Analysis Options > Manual Setup > Build Setting: Build Task

Use this setting if you choose Get from build task for the setting Analysis Options > Manual Setup: Build.

Specify the build task name. The build task name is the name of a command that runs when you select Terminal > Run Task. For more information on tasks, see Visual Studio Code documentation.

Use a build task that performs a complete build of all files in your workspace and not an incremental build.

See Get Build Configuration from Build Task.

Yes
Analysis Options > Manual Setup > Build Setting: JSON Compilation Database File

Use this setting if you choose Get from JSON Compilation Database File for the setting Analysis Options > Manual Setup: Build.

Specify the full path to a database file (typically named compile_commands.json).

See Get Build Configuration from JSON Compilation Database.

Yes
Analysis Options > Manual Setup > Build Setting: Polyspace Build Options File

Use this setting if you choose Get from Polyspace Build Options File for the setting Analysis Options > Manual Setup: Build.

Specify the full path to a Polyspace build options file. The options file is a text file with one Polyspace analysis option per line.

See also Options Files for Polyspace Analysis.

Yes
Analysis Options > Manual Setup: Checkers File

Specify the full path to a checkers configuration file.

To create this file, in the Command Palette, run Polyspace: Configure Checkers. Enable the checkers that you want and save the file.

See also Configure Checkers for Polyspace as You Code in Visual Studio Code.

Yes
Analysis Options > Manual Setup: Other Analysis Options

Path to an options file. The options file contains one Polyspace analysis option per line. For example:

-termination-functions exit_handler
-code-behavior-specifications /usr/jdoe/util/checkerModifiers.xml

You typically do not need to specify additional options in an options file. However, in some situations,you might want to use an options file. For instance, you might want to modify some checkers using an XML file that you provide with the option -code-behavior-specifications.

See also Options Files for Polyspace Analysis.

Yes

Analysis Options > Script

Setting ID: polyspace.analysisoptions.scriptfile

SettingDescriptionAvailable Per Workspace?
Analysis Options > Script: Script File

Use this setting if you choose Script for the setting Analysis Options: Analysis Setup.

Enter the full path to a script. The script can be written in any language and runs each time you run Polyspace as You Code on file save or explicitly.

The script takes the path to the current file as the first argument and the Result Folder as the second argument.

For example, this simple Windows batch script analyzes the current file, uses the default Polyspace build options, and imports the review information from a previously downloaded baseline:

set INSTALL_DIR=C:\Program Files\Polyspace as You Code\R2021a
set ANALYZE=%INSTALL_DIR%\polyspace\bin\polyspace-bug-finder-access.exe
set SOURCES=%1
set RESULTS_FOLDER=%2
set BASELINE_DIR=%RESULTS_FOLDER%\..\..\..\baseline


"%ANALYZE%" -sources %SOURCES% -baseline-folder %BASELINE_DIR% -results-dir %RESULTS_FOLDER% 
IF %ERRORLEVEL% NEQ 0 EXIT 1

Use a script if, for instance, you switch between files from components that have different build configurations or you use a custom tool to setup your build environment.

If you enable this setting, all other extension settings are ignored.

Note

The Polyspace as You Code extension does not check the exit status of the commands in your script. Make sure your script checks exit codes (for instance by using %ERRORLEVEL%) and returns a meaningful exit status.

Typically, the Polyspace binaries return 0 on success and a non-zero value on failure.

Yes

Baseline

Setting ID: polyspace.baseline

These options are essential only if you want to obtain a baseline from Polyspace Access. After you obtain a baseline from Polyspace Access, subsequent runs of Polyspace as You Code allow you to distinguish between new results and results that were present in existing code. See also Baseline Polyspace as You Code Results in Visual Studio Code.

SettingDescriptionAvailable Per Workspace?
Baseline: Polyspace Access UrlSpecify Polyspace Access URL.No
Baseline: Polyspace Access Login

Specify the user name you use to log in to Polyspace Access.

Later, when you run Polyspace: Get Baseline in the Command Palette, you are prompted for the password corresponding to this user name.

No
Baseline: Project

Specify a project on Polyspace Access that you use as baseline.

Later, when you run Polyspace: Get Baseline in the Command Palette, the polyspace-access command runs with the -download option to download the baseline results from the latest run of this project. Subsequent runs of Polyspace as You Code use this baseline.

Yes
Baseline: Show Only New Findings

Suppress findings that are already present in the Polyspace Access project that you use as baseline.

If you select this setting, you must also select Baseline: Use Baseline.

Yes
Baseline: Use Baseline

Use Polyspace Access project as baseline.

Results that are already present in Polyspace Access show associated review information. If a result has review information that indicates a justified status, for instance, No action planned, the result is not shown at all.

In addition, if you select the setting Baseline: Show Only New Findings, results that are already present in Polyspace Access are not shown at all.

Yes

Trace

Setting ID: polyspace.trace.server

The option is useful only for troubleshooting by technical support. You typically do not need to use this option.

SettingDescriptionAvailable Per Workspace?
Trace: ServerWhether the log must show messages related to communication between the internal server that hosts analysis results and the IDE. This option is only useful for troubleshooting internal communication issues.Yes

Related Topics