Main Content

Configure Polyspace as You Code Extension in Visual Studio Code

Polyspace® as You Code allows you to find bugs and coding rule violations while you work in your Visual Studio Code editor.

After you install the Polyspace as You Code analysis engine and Visual Studio Code 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 you expect, 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 most 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 or the Remote tab if you are using the VS Code Remote Development feature.

Unless otherwise specified, settings that are available on the User tab are also available on the Workspace or Remote tabs.

Visual Studio Code User and Workspace settings tabs

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.

Specify Analysis Engine Preferences

Setting ID: polyspace.analysisEngine

These settings are mandatory. For better performance on Windows®, the path that you provide for these settings should not point to network drives.

SettingDescription
Polyspace Installation Folder

Root folder of the Polyspace as You Code installation, for instance, C:\Program Files\Polyspace as You Code\R2024a.

Working Directory

Folder where analysis results are stored. Each new run overwrites results of the previous run.

The default working directory is stored under your system temporary folder, and typically contains polyspace_vscode in the folder name:

  • Windows — %temp% folder, for example C:\Users\jsmith\AppData\Local\Temp.

  • Linux®/tmp folder.

Configure Analysis Behavior On Save

Setting ID: polyspace.analysisOptions OnSave

By default, Polyspace as You Code adds the current file to the Quality Monitoring list and runs each time you save your code. You can choose to disable these automatic actions.

SettingDescription
Analysis Options: Add To Quality Monitoring On Save

Select how you add files to the Quality Monitoring list. Polyspace as You Code analyzes files only files in this list.

By default, Polyspace adds the current file to the list on save (Ctrl + S). Clear the checkbox for this setting to add files to the Quality Monitoring list manually. To add files manually, right-click the file in the editor, the EXPLORER panel, or SOURCE CONTROL panel in the side bar.

Analysis Options: Analysis Of Files On Save

Select when Polyspace as You Code runs on files that are in the Quality Monitoring list.

By default, Polyspace as You Code runs each time you save your code. Clear the checkbox for this setting to run the analysis manually. You can right-click the source code or a file in the EXPLORER and select Run Polyspace Analysis (or run the command Polyspace: Run Polyspace Analysis from the Command Palette).

Configure Analysis Settings

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.

SettingDescription
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.

    See Setup Analysis Manually.

  • Script: Run a script each time you save your code (or right-click a source file and select Run Polyspace Analysis).

    See Setup Analysis by Using a Script.

Analysis Options: 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.

Analysis Options: Fast Analysis

Toggle on or off fast analysis mode. This option is disabled by default.

Fast analysis decreases the duration of your Polyspace as You Code analysis by checking only for specific types of issues. This option enables only checkers for issues that are syntactic and do not require abstraction or data flow calculations. Polyspace excludes checkers that are not syntactic or require abstraction of the code from a fast analysis. These exclusions are in addition to the Checkers Deactivated in Polyspace as You Code Analysis.

Use fast analysis to iteratively identify and address bugs that are smaller in scope and addressable earlier in the development process. To take full advantage of the defects that Polyspace as You Code can find, use fast analysis as a precursor to a full Polyspace as You Code analysis of your code.

The Configuration view shows Fast analysis mode: On when the option is enabled. You can toggle the option on or off from this pane by clicking the icon to the right of the option name.

Setup Analysis Manually

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.

SettingDescription
Analysis Options > Manual Setup: Build

Specification 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 build command

    Polyspace uses your build command to generate a build options file. 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.

    To generate the build options file, from the Command Palette, run Polyspace: Generate Build Options.

    See Get Build Configuration from Build Command

  • Get from build task

    Polyspace uses your Visual Studio® build task to generate a build options file. Make sure that the build task performs a complete build of all the files in your workspace. Specify the build task name in the setting Analysis Options > Manual Setup > Build Setting: Build Task.

    To generate the build options file, from the Command Palette, run Polyspace: Generate Build Options.

    See Get Build Configuration from Build Task.

  • Get from JSON Compilation Database file

    Polyspace uses your JSON compilation database to generate a build options file. 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.

    To generate the build options file, from the Command Palette, run Polyspace: Generate Build Options.

    See Get Build Configuration from JSON Compilation Database.

  • 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.

    See also Options Files for Polyspace Analysis (Polyspace Bug Finder).

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

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.

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.

If you use a build system generator such as CMake, you can follow this approach to set up Polyspace as You Code. For instance, if you use CMake projects in Visual Studio Code, CMake also allows you to generate a JSON compilation database with the commands used for building the project. You can then provide the compilation database to this setting. For an example of how to generate this JSON file, see Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder).

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 (Polyspace Bug Finder).

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 (Polyspace Bug Finder).

Setup Analysis by Using a Script

Setting ID: polyspace.analysisOptions.scriptFile

SettingDescription
Analysis Options > Script: Script File

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

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

Enter the full path to a script that runs each time you start a Polyspace as You Code analysis. You can write the script in any language. On Windows, the extension supports scripting languages only for scripts that are executable from the Command Prompt window.

The extension passes these setting values as parameters to the script:

  • Path to the current file as the first argument

  • Path to the Working Directory folder as the second argument

  • Path to the Polyspace Installation Folder as the third argument

Optionally, the extension passes these additional settings to the script if you specify or enable those settings:

  • The path of a local result that Polyspace uses as a baseline for the file being analyzed. The path is prefixed by the option -baseline-folder. Polyspace stores local baseline results in a local-baseline subfolder of the Working Directory folder.

  • The path of integration results downloaded from Polyspace Access, and that Polyspace uses as a baseline for the file being analyzed. The path is prefixed by the option -baseline-folder. Polyspace stores integration baseline results in a baseline subfolder of the Working Directory folder.

  • The path of the options file from the setting Analysis Options > Manual Setup: Other Analysis Options (polyspace.analysisOptions.otherAnalysisOptionsFile), prefixed by -options-file. For instance, if you specify the file C:\polyspace\myOpts.txt, the extension passes -options-file C:\polyspace\myOpts.txt as a parameter.

  • The path of the checkers activation XML file from the setting Analysis Options > Manual Setup: Checkers File (polyspace.analysisOptions.checkersFile), prefixed by -checkers-activation-file. For instance, if you specify the file C:\polyspace\myCheckers.xml, the extension passes -checkers-activation-file C:\polyspace\myCheckers.xml as a parameter.

  • Any additional parameters you specify with setting the Analysis Options > Script: Script File Arguments (polyspace.analysisOptions.checkersFile).

For example, this Windows batch script assigns the paths of the source file (SOURCES), results folder (RESULTS_FOLDER), and the installation folder (INSTALL_DIR), and assigns any additional parameters to OTHER_PARAMS. The script then analyzes the current file, using any analysis options stored in OTHER_PARAMS, and imports the review information from a previously downloaded baseline:

@echo off

set SOURCES=%1
set RESULTS_FOLDER=%2
set INSTALL_DIR=%3
set ANALYZE=%INSTALL_DIR%\polyspace\bin\polyspace-bug-finder-access.exe
set BASELINE_DIR=%RESULTS_FOLDER%\..\..\..\baseline

set OTHER_PARAMS=
REM loop through additional parameters if any
:loop
    if [%4] == [] (
    goto :done)
    set OTHER_PARAMS=%OTHER_PARAMS% %4
    shift
    goto :loop
:done

"%ANALYZE%" -sources %SOURCES% -import-comments %BASELINE_DIR%^
 -results-dir %RESULTS_FOLDER% %OTHER_PARAMS% 
IF %ERRORLEVEL% NEQ 0 EXIT 1
For more on downloading a baseline and importing its review information at the command line, see Set Baseline Polyspace as You Code Results on Command Line.

If you enable this setting, the extension ignores the polyspace.analysisOptions.manualSetup.buildSetting and polyspace.baseline settings.

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 example by using %ERRORLEVEL%) and returns a meaningful exit status.

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

Analysis Options > Script: Script File Arguments

Use this setting to specify additional parameters that the extension passes to the script when you run an analysis. For example, you might want to run a command on preprocessed files to work around a compilation error. See Command/script to apply to preprocessed files (-post-preprocessing-command) (Polyspace Bug Finder).

Configure Baseline Settings

Setting ID: polyspace.baseline

Set these options if you want to compare your local results against an integration baseline run that you download from Polyspace Access™. After you download an integration 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.

You can also use local results as a baseline. See Set Baseline Polyspace as You Code Results in Visual Studio Code.

SettingDescription
Baseline: Polyspace Access Login

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

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

Baseline: Polyspace Access Url

Specify the Polyspace Access URL, for example https://example.access-server:9443.

Baseline: Project

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

To download the baseline, from the Command Palette, run Polyspace: Download Baseline.

See also Set Baseline Polyspace as You Code Results in Visual Studio Code.

Configure Justification Catalog

Setting ID: polyspace.justification.catalog

Use this setting if your team or organization has a predefined set of comments that they use to justify results. You can store these justifications in a catalog file and associate one or more justification with a specific result or result family.

If you use the Polyspace syntax to annotate a result in the Visual Studio Code editor, justifications that you store in the catalog for that result are available in a dropdown when you start typing the annotation comment. For details of the Polyspace syntax, see Annotation Syntax Details (Polyspace Bug Finder).

To create a justification catalog, see Use a Justification Catalog to Autocomplete Annotations in Polyspace as You Code plugins.

SettingDescription
Justification: Catalog

Specify the full file path of the JSON catalog.

Configure Other Settings

Setting ID: polyspace.otherSettings

Additional settings to configure the debugging mode and the port the extension uses to communicate with the analysis engine.

SettingDescription
Other Settings: Debug Mode

Enable or disable debugging.

  • Disabled(default)

    Show only errors, warnings, and information messages such as start and end of analysis in the OUTPUT pane.

  • Enabled

    Show all debugging information in the OUTPUT pane. Enable this setting to troubleshoot issues with the Polyspace as You Code extension.

Other Settings: Headers Extensions

Specify the extensions that Polyspace as You Code should treat as header files instead of source files.

If you configure Polyspace to add files to the Quality Monitoring list on save and you make edits to a file with one of the specified header extensions, Polyspace does not add that file to the Quality Monitoring list on save.

Polyspace analyzes and reports findings in a header file if you analyze a file that includes the header file or if you explicitly start an analysis of the header file. The header file is analyzed even if you do not specify the extension of the file in this setting.

See also HEADERS view.

Other Settings: Help Improve Polyspace as You Code

Enable or disable the sharing of user experience information with MathWorks®. Polyspace uses this information to improve the Polyspace as You Code extension.

This setting is available only on the User tab.

Other Settings: Port

Specify the port number that the Polyspace as You Code extension uses on startup to establish an internal connection with the analysis engine.

Use this setting if, for example, your machine is configured with a firewall and you want to specify an open port in the firewall.

By default, port 0 is specified and Polyspace queries your system for an available port and uses whichever port your system returns.

If you run multiple instances of the Polyspace as You Code extension, specify a different port for each instance.

If you change this setting, you might need to reload Visual Studio Code. If you let Polyspace obtain a port number automatically (port 0), the extension might connect on a different port when you reload Visual Studio Code and you might need to rerun the command Polyspace: Generate Build Options.

Configure Polyspace as You Code for Remote Development

The Polyspace as You Code extension supports the Visual Studio Code remote development feature. See VS Code Remote Development.

With remote development, you can run a Polyspace as You Code analysis in a remote environment from your local machine. You can analyze code that you develop on a remote machine, in a container, or using the Windows Subsystem for Linux (WSL) feature. Use the remote development feature to, for instance, develop and analyze your code in an environment that uses a specific operating system or specialized hardware.

Remote development configuration diagram

To enable remote development with Polyspace as You Code:

  • Install the Polyspace as You Code extension and analysis engine on the remote environment. After you copy the installation image to the remote environment, see for example Install Polyspace as You Code Noninteractively.

    If you install the Polyspace as You Code extension in the remote environment by going to the Extensions view and clicking Install in from the locally installed extension, the operation does not install the analysis engine.

  • Install and enable the appropriate remote development extension. See Remote tutorials.

  • After you install the extension and connect to the remote environment, open the settings and go to the Remote tab to specify:

    • The Polyspace Installation Folder path in the remote environment.

    • The Working Directory path in the remote environment. If you do not specify a path, Polyspace uses a path under the system temporary folder.

    • The paths of any other file of or folders that the analysis uses in the remote environment, for example the Checkers File path.

      On Windows, if any of your project files or folders on the remote environment are on a network drive, provide the UNC path for that network drive. The Polyspace as You Code extension cannot resolve the path of a network drive that is mapped to a drive letter when you enable remote development and the Polyspace: Generate Build Options command might fail.

Once you connect to the remote environment and start the remotely installed Polyspace as You Code extension, the locally installed extension appears greyed out in the Extensions view.

Note

  • The versions of the Polyspace as You Code extension and analysis engine on the remote environment must match the versions of the extension and analysis engine on the local environment.

    To compare the extension versions, from the Extensions view, select the locally and then the remotely installed Polyspace as You Code extension.

  • If you set Analysis Options > Manual Setup: Build to Get from build task or Get from build command, check that your build completes successfully before you run the Polyspace: Generate Build Options command.

Related Topics