9. Using GNAT SAS in Visual Studio Code
GNAT SAS can be used in Visual Studio Code by simply using its command line interface from the integrated terminal. In order to benefit from more advanced integrated GNAT SAS support in Visual Studio Code, we strongly recommend installing the Ada & SPARK Extension developed by AdaCore.
The extension provides automated tasks to run the analysis and generate reports in SARIF formats, which can then be displayed using any third-party extension that displays SARIF reports.
9.1. Prerequisites
Make GNAT SAS available in the
PATH
before launching Visual Studio Code.Install the Ada & SPARK Extension.
If the root directory of the Visual Studio Code workspace contains more than one project file, or if the project file you want to analyze is not in the workspace root directory, you need to set the
ada.projectFile
extension setting.
9.2. Running GNAT SAS in Visual Studio Code
9.2.1. Using the integrated terminal
The integrated terminal can be used to run arbitrary GNAT SAS commands. Refer to other chapters of this guide and the GNAT SAS CLI Reference for more information.
9.2.2. Using pre-defined tasks
The supported feature set is more limited than the features available in GNAT Studio. Support is based on Visual Studio Code Tasks. The extension provides pre-defined tasks for the following scenarios.
Tasks may be accessed by opening the action bar (Cmd+Shift+P) and selecting
Tasks: Run Task
.
Note
You cannot specify switches when calling GNAT SAS when using pre-defined
tasks. To configure the analysis (mode, engines, ...) or the reporting, edit
the .gpr
project file as explained in Configuring the Analysis.
ada: Analyze the project with GNAT SAS
Analyze the project specified by the
ada.projectFile
extension setting, if specified, or the project located at the workspace's root if its.gpr
file is the only one in that directory.ada: Create a report after a GNAT SAS analysis
Generate a SARIF report for the previous analysis.
If a third-party extension providing SARIF-viewing capabilities is available, it will automatically display the report (see Viewing GNAT SAS Output in Visual Studio Code).
ada: Analyze the project with GNAT SAS and produce a report
Combine the above project analysis and report tasks.
ada: Analyze the current file with GNAT SAS
Run an analysis on the file currently opened in the editor.
ada: Analyze the current file with GNAT SAS and produce a report
Combine the above current file analysis and report tasks.
See also
Refer to Tasks for the complete list of tasks provided by the extension.
9.3. Viewing GNAT SAS Output in Visual Studio Code
Results from GNAT SAS generated in the SARIF format can be browsed in Visual Studio Code using any third-party extension with SARIF-viewing capabilities. Such third-party extensions may provide an interface to display the results interactively and inline messages and backtraces in the editor.
Note that SARIF-viewing features are specific to each particular extension and are not maintained by AdaCore.
Note
By default, file URIs in the report are made relative to the workspace's root
directory. This is compatible with the third-party SARIF-viewing extensions
that we tested. If needed, you can modify the file URIs' base directory with
the --root DIR
gnatsas report switch. This can be done directly in the
.gpr
file with:
project Prj is
...
package Analyzer is
for Switches ("report sarif") use ("--root=<PATH_TO_BASE_URI_DIR>");
end Analyzer;
end Prj;