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.
To reset a setting to its default value, click the 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.
Setting | Description |
---|---|
Polyspace Installation Folder | Root folder of the Polyspace as You Code installation,
for instance, |
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
|
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.
Setting | Description |
---|---|
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 pane, or Source Control pane 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.
Setting | Description |
---|---|
Analysis Options: Analysis Setup | Select between manual setup and 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 |
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.
Setting | Description |
---|---|
Analysis Options > Manual Setup: Build | Specification of build-related Polyspace analysis options. Options are:
|
Analysis Options > Manual Setup > Build Setting: Build Command | Use this setting if you choose 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. |
Analysis Options > Manual Setup > Build Setting: Build Task | Use this setting if you choose 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. |
Analysis Options > Manual Setup > Build Setting: JSON Compilation Database File | Use this setting if you choose Specify the full path to a
database file (typically named
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 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
See also Options Files for Polyspace Analysis (Polyspace Bug Finder). |
Setup Analysis by Using a Script
Setting ID:
polyspace.analysisOptions.scriptFile
Setting | Description |
---|---|
Analysis Options > Script: Script File | Use this setting if you choose
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:
Optionally, the extension passes these additional settings to the script if you specify them:
For example, this Windows batch script assigns the paths of the source
file (
If you enable this setting, the extension
ignores the
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
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 |
Configure Baseline Settings
Setting ID:
polyspace.baseline
Set these options if you want to compare your local results against 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 Set Baseline Polyspace as You Code Results in Visual Studio Code.
Setting | Description |
---|---|
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
|
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. |
Baseline: Show Baseline Information | Enable or disable the use of information from the baseline run:
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.
Setting | Description |
---|---|
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.
Setting | Description |
---|---|
Other Settings: Debug Mode | Enable or disable debugging.
|
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
|
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.
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
orGet from build command
, check that your build completes successfully before you run thePolyspace: Generate Build Options
command.