Skip to content

Commit 0fa3b7c

Browse files
Add documentation for GNATmetric VS Code integration
For eng/ide/ada_language_server#1294
1 parent 7f63869 commit 0fa3b7c

6 files changed

Lines changed: 39 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ section below it for the last release. -->
1111
* Highlight `finally` keyword (from Ada extension) with semantic tokens
1212
* Prompt the user to restart the Ada Language Server when the workspace `.als.json` configuration file is modified
1313
* Two color themes **GNAT Studio Light** and **GNAT Studio Dark**
14+
* Add a predefined task to compute file metrics and display them automatically via CodeLenses
1415

1516
## 2026.1.202601121
1617

392 KB
Loading

doc/media/gnatmetric-vscode.gif

228 KB
Loading

doc/settings.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,26 @@ On the server side this option does not trigger any additional logging.
148148

149149
An equivalent setting `gpr.trace.server` exists for tracing the communcation between VS Code and the GPR language server.
150150

151-
### metricthresholds
151+
### metricThresholds
152152

153-
Configurable thresholds for metrics provided by `gnatmetric`. Each key is a metric name (e.g., `cyclomatic_complexity`, `code_lines`), and the value is an object with optional 'warn' and 'error' numeric thresholds.
153+
Configurable thresholds for metrics provided by `gnatmetric`. Each key is a metric name (e.g., `cyclomatic_complexity`, `code_lines`), and the value is an object with optional `warn` and `error` numeric thresholds.
154154
Metric names can be retrieved from the XML metric files generated by `gnatmetric`, which by default are located under the project's object directory (`.metrics.xml` files).
155155

156+
Below is an example configuration for setting metric thresholds to highlight subprograms with high cyclomatic complexity:
157+
158+
```json
159+
{
160+
"ada.metricThresholds":
161+
{
162+
"cyclomatic_complexity":
163+
{
164+
"warn": 10,
165+
"error": 20
166+
}
167+
}
168+
}
169+
```
170+
156171
If not set, no thresholds will be applied.
157172

158173
### projectFile

doc/vscode-ug.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This extension **does not include a compiler nor additional tools**. Nonetheless
2727
| | Code Coverage ||
2828
| **GNAT SAS** | | |
2929
| | Static Analysis ||
30+
| | Metrics ||
3031
| **SPARK** | | |
3132
| | Formal Proof ||
3233

@@ -314,6 +315,18 @@ The GNATtest integration in VS Code also supports running tests in coverage mode
314315

315316
Integrating the steps of source instrumentation and test harness build into the test execution workflow allows for a quick feedback loop: run a test, observe results and coverage, edit the test or the tested code, repeat... In this context invoking the VS Code commands `Test: Rerun Last Run` and `Test: Rerun Last Run with Coverage` with their respective keyboard shortcuts can be valuable.
316317

318+
## GNAT Metrics Support
319+
320+
The extension provides a predefined task called `Compute metrics for current file`, which runs `gnatmetric` and displays file metrics directly in the editor using CodeLenses.
321+
322+
![GNAT Metrics CodeLenses](media/gnatmetric-vscode.gif)
323+
324+
By default, the displayed metrics include code complexity and lines of code. You can customize which metrics are shown by adjusting the command-line options for `gnatmetric` in the task configuration.
325+
326+
You can configure thresholds for specific metrics to highlight when they are exceeded via the `ada.metricThresholds` [VS Code setting](./settings.md#metricthresholds). The extension will display warning or error diagnostics for each violation, and the corresponding CodeLenses will show warning or error icons as appropriate.
327+
328+
![GNAT Metrics Thresholds](media/gnatmetric-thresholds.png)
329+
317330
## Cross and Embedded Support
318331

319332
This section provides some guidance to work on cross or embedded projects. It assumes
@@ -489,15 +502,15 @@ The VS Code extension has a few limitations and some differences compared to [GN
489502
* **Indentation/formatting**: it does not support automatic indentation when adding a newline and range/document
490503
formatting might no succeed on incomplete/illegal code.
491504

492-
* **Tooling support**: we currently provide support for some _SPARK_, _GNATtest_, _GNATcoverage_, _GNAT SAS_ and _GNATemulator_ [Tasks](#tasks), but some workflows may not be supported yet.
505+
* **Tooling support**: we currently provide support for some _SPARK_, _GNATtest_, _GNATcoverage_, _GNAT SAS_, _GNATmetric_ and _GNATemulator_ [Tasks](#tasks), but some workflows may not be supported yet.
493506

494507
* **Alire support**: if the root folder contains an `alire.toml` file and
495508
there is `alr` executable in the `PATH`, then the language server fetches
496509
the project's search path, environment variables and the project's file
497510
name from the crate description. [Tasks](#tasks) are also automatically
498511
invoked with Alire in this case.
499512

500-
* **Project support**: there is no `Scenario` view: users should configure scenarios via the _ada.scenarioVariables* setting (see the settings list available [here](./settings.md)). Saving the settings file after changing the values will automatically reload the project and update the
513+
* **Project support**: there is no `Scenario` view: users should configure scenarios via the `ada.scenarioVariables` setting (see the settings list available [here](./settings.md)). Saving the settings file after changing the values will automatically reload the project and update the
501514
predefined tasks to take into account the new scenario values.
502515

503516
Source directories from imported projects should be added in a [workspace file](https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces). If you already have a workspace file, the extension will propose you to automatically add all the source directories coming from imported projects to your workspace automatically at startup.

integration/vscode/ada/schemas/als-settings-schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139
"type": "integer",
140140
"default": 10,
141141
"description": "Controls the maximum number of trace files preserved in the ALS log directory (which defaults to `~/.als`). When this threshold is reached, old trace files get deleted automatically. The default number of preserved trace files is `10`."
142+
},
143+
"metricThresholds": {
144+
"scope": "window",
145+
"type": "object",
146+
"default": null,
147+
"markdownDescription": "Configurable thresholds for metrics provided by `gnatmetric`. Each key is a metric name (e.g., `cyclomatic_complexity`, `code_lines`), and the value is an object with optional 'warn' and 'error' numeric thresholds.\nMetric names can be retrieved from the XML metric files generated by `gnatmetric`, which by default are located under the project's object directory (`.metrics.xml` files).\n\nIf not set, no thresholds will be applied."
142148
}
143149
},
144150
"additionalProperties": false

0 commit comments

Comments
 (0)