Main Content

Integrate Polyspace as You Code in IDEs and Editors Without Plugins

Polyspace as You Code supports these IDEs with extensions or plugins: Visual Studio, Visual Studio Code, and Eclipse. Even if an IDE is not explicitly supported with a Polyspace as You Code plugin, you can open a console within the IDE and run Polyspace as You Code commands, or create a menu item to run the commands on the file currently open in the IDE.

This topic demonstrates how to integrate Polyspace as You Code in a simple editor such as Notepad++. You can use the principles here to integrate Polyspace as You Code in most editors or IDEs.

Overview of Approach

In supported IDEs, a Polyspace as You Code extension allows you to analyze the file that is currently active in the IDE and see results within the IDE (as source code markers or in a list). In an unsupported IDE or editor, you can partly emulate this workflow, that is, run analysis within the IDE and view results. The workflow consists of two steps:

  • Running analysis and exporting results

    Most IDEs or editors provides environment variables that resolve to the current file path. You can create menu items that execute a script which runs the polyspace-bug-finder-access command on this path. In the same script, you can export the results to the IDE console.

  • Parsing console output to allow navigation to line

    Each Polyspace as You Code result in the console output starts with a line in this format:

    Here, filepath is the path to the current file, lineNumber is the line number of the result, and columnNumber is the column that starts the token with the result. For instance:
    indicates that the file C:\MyProj\myFile.c contains a result on line 17, starting from column 31. If you can parse the console output, you can enable a navigation to line 31 to the start of the token containing the result.

Integration Steps

This example shows an integration of Polyspace as You Code in a simple editor such as Notepad++. You can follow similar integration steps in other editors such as GNU Emacs, Sublime Text, and so on.

Step 1: Set Up Script Runs from Within Editor

In Notepad++, you can use a plugin such as NppExec that allows you to execute any script from within the editor. The editor also provides the environment variable $(FULL_CURRENT_PATH) that resolves to the file that is currently active in the IDE.

The simplest script that can be run within the plugin can be the following:

set POLYSPACE_EXECUTABLES_FOLDER=C:\Program Files\Polyspace as You Code\R2024a\polyspace\bin
set POLYSPACE_ENGINE=$(POLYSPACE_EXECUTABLES_FOLDER)\polyspace-bug-finder-access.exe
$(POLYSPACE_REPORT_EXPORTER) -results-dir . -format console
The console format is only available for Polyspace as You Code. In practice, you might want to specify additional analysis options using an options file. If the options file is called polyspace_options.txt, the command to run Polyspace as You Code in the preceding script can be replaced with:
$(POLYSPACE_ENGINE) -sources $(FULL_CURRENT_PATH) -options-file polyspace_options.txt
See also Options Files for Polyspace Analysis (Polyspace Bug Finder).

For other command-line examples, see Run Polyspace as You Code from Command Line and Export Results. For instance, instead of exporting to the console directly, you can export the results to a JSON format, use a JSON parser to package the results, and then export them to the console or use them in some other way.

Step 2: Set Up Parsing of Console Output

The NppExec plugin allows you to parse console output and navigate to the appropriate line of code. You can also optionally apply specific formatting to the console output.

For instance, your console output can look like the following:

You can set up the output so that clicking a link directly takes you to the start of the relevant token on the relevant line of code.

To set up this presentation of results, select Plugins > NppExec and then select the Console Output Filters option. The following options allow the previous presentation of results:

The first highlight mask indicates that lines having the format

contain the absolute path to the file before the first colon, the line number between the first and second colon, and the column number (or character number) after the second colon. The mask reads the information (file, line and column), underlines these lines and colors them blue.

The second highlight mask simply bolds lines having the format

These lines contain the result name, for instance, the name of a defect.

Further Exploration

The official Polyspace as You Code extensions enable other actions such as analyzing build commands, configuring checkers, and downloading baselines from the Polyspace Access web server. In a real development environment, you want to analyze your build commands to emulate your compilation toolchain as closely as possible, configure the checkers that are most meaningful to you, and baseline results so that you focus only on new results coming from your changes.

You can extend the approach described here to create menu items in your IDE or editor for all these actions. For more information on these workflows from the command line, see:

With your IDE or editor set up for Polyspace as You Code, you can create a quality gate for submission. You can set up a configuration with checkers for which you do not want any finding in your submission. Before submitting a file, you can make sure that you have fixed all findings from those checkers.

See Also

| (Polyspace Bug Finder)