DIPS Arena Calc Assistant
A Visual Studio Code extension for formatting, validating, and working with DIPS Arena calc expressions.
Features
- Clean formatting – Convert dense expressions into indented, readable layouts.
- One-click minify – Collapse formatted expressions back to single-line format.
- IntelliSense – Autocomplete for calc functions with signature help.
- Parameter hints – Function signatures and parameter types displayed while typing.
- Custom functions – Define reusable macro-style functions (BMI, FORMAT_DURATION, TEXTJOIN) that expand to standard calc expressions.
- Function wrapping – Type a function name before an expression to automatically wrap it.
- Variable autocomplete – Variables from
form_description.json with data types.
- Path autocomplete – Path suggestions for complex types (e.g.,
$quantity/magnitude).
- Value autocomplete – Allowed values for coded text fields.
- Diagnostics – Real-time validation for:
- Argument counts and type mismatches with detailed error messages
- Missing commas between arguments
- Variables used without
$ prefix (with quick fix)
- Undeclared variables not found in form_description.json
- Output type validation – Verifies expression output matches expected field datatype (when calcId is specified in file comment)
- Enhanced type errors showing rmType and conversion suggestions
- Syntax highlighting – Color-coded functions, variables, strings, and numbers.
- File icons – Dedicated icon for
.calc files in the explorer.
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions view (
Ctrl+Shift+X / Cmd+Shift+X)
- Search for "DIPS Calc Expression" or "DIPS Arena Calc Assistant"
- Click Install
From VSIX File
- Download the
.vsix file from the releases page
- Open VS Code
- Go to Extensions view (
Ctrl+Shift+X / Cmd+Shift+X)
- Click the
... menu at the top of the Extensions view
- Select Install from VSIX...
- Browse to and select the downloaded
.vsix file
Usage
- Open or create a file with the
.calc extension (or select DIPS Calc Expression from the language mode picker).
- Type or paste your expression. Use Format Document (
Shift+Alt+F) to format.
- Add comments using
// for documentation (editor-only, not supported in DIPS Arena).
- To get a compact version, run DIPS Calc: Minify Document or Selection from the Command Palette (
Ctrl+Shift+P / Cmd+Shift+P).
- Before pasting to DIPS Arena, run DIPS Calc: Export for Arena to strip comments and expand custom functions.
- Use
Ctrl+Space to trigger function and variable completions.
Commands
| Command |
Purpose |
DIPS Calc: Minify Document or Selection |
Collapse the active selection or entire file into a single-line expression while preserving strings and operators. |
DIPS Calc: Beautify Document or Selection |
Manually beautify the selection or the entire file. |
DIPS Calc: Strip Comments |
Remove all // comments from the document or selection. Use this before copying expressions to DIPS Arena, which does not support comments natively. |
DIPS Calc: Expand Custom Functions |
Expand all custom function calls (like BMI, FORMAT_DURATION) into standard DIPS Calc expressions. |
DIPS Calc: Export for Arena |
One-click export: strip comments and expand custom functions for pasting into DIPS Arena. |
Custom Functions
Custom functions are macro-style functions that expand to standard DIPS Calc expressions. Use cases:
- Reusing calculations across forms
- Simplifying complex expressions
- Creating domain-specific functions
Built-in Custom Functions
BMI(weight_kg, height_cm) – Calculate Body Mass Index
FORMAT_DURATION(duration_string, format_string) – Format ISO8601 durations with Norwegian localization
- Standard formats:
"c", "g", "G"
- Norwegian formats:
"no-short", "no-long", "no-compact"
- Custom formats using:
d (days), h (hours), m (minutes), s (seconds)
TEXTJOIN(delimiter, ignore_empty, text1, ..., text10) – Excel-style text joining
Using Custom Functions
- Type custom function names in your expressions (autocomplete available).
- Run DIPS Calc: Export for Arena or DIPS Calc: Expand Custom Functions to convert to standard DIPS Calc.
- Copy the expanded result to DIPS Arena.
Creating Custom Functions
Add a new file to lib/custom-functions/ with this structure:
module.exports = {
name: 'MY_FUNCTION',
signature: 'MY_FUNCTION(param1, param2)',
detail: 'Description of what the function does',
minArgs: 2,
maxArgs: 2,
returns: 'number',
params: [
{ name: 'param1', type: 'number' },
{ name: 'param2', type: 'text' }
],
expansion: 'ROUND({param1} * 10 + LEN({param2}), 2)'
};
The function will be automatically loaded – no registration required.
Parameter Hints (Signature Help)
Function signatures display parameter names, types, and the current parameter position while typing.
Triggers:
- Type
( after a function name
- Type
, to move to next parameter
- Select a function from autocomplete
- Manual:
Ctrl+Shift+Space / Cmd+Shift+Space
Configuration
The extension ships with sensible defaults for calc expression editing. Override them in your settings.json if you prefer a different setup:
"[dips-calc]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnPaste": false
}
Variable Autocomplete
The extension provides variable completion for both DIPS Arena forms and VAQMs:
The extension searches for form_description.json in the same folder or immediate parent folder and extracts calcId annotations for variable completions.
Usage:
- Place
.calc file in the same folder as form_description.json or in a direct subfolder.
- Type
$ to trigger autocomplete.
- Variables from form description appear with name and data type.
VAQMs
For VAQM display-format.calc files, the extension automatically discovers predicates and paths from the aql-bindings folder structure.
Usage:
- Place
.calc file in the VAQM data-element folder structure (alongside metadata.json).
- Type
$ to trigger autocomplete for predicates (e.g., $ordinasjonsPred).
- Type
. after a predicate to see available paths (e.g., $ordinasjonsPred.hovedDiagnose).
- Path suggestions include data types extracted from
paths.xml.
The extension automatically detects whether you're working with a form or VAQM and provides appropriate variable completions.
Path Completion
Type / after a variable name to get path suggestions based on data type:
$quantity/magnitude – Numeric value of DV_QUANTITY
$quantity/units – Unit string
$coded/defining_code/code_string – Code value of DV_CODED_TEXT
$ordinal/value – Integer value of DV_ORDINAL
Value Completion
For DV_CODED_TEXT and DV_ORDINAL fields with defined values, type " after an equals sign to see allowed values:
$status = " <-- triggers value completion
Note: The extension automatically detects the appropriate metadata file (form_description.json or VAQM aql-bindings) based on your file location. Cache refreshes automatically when metadata files change.
Diagnostics
Real-time validation:
- Argument count – Errors for incorrect number of arguments
- Type checking – Warnings for type mismatches
- Missing commas – Warnings with quick fix to insert comma
- Unknown functions – Highlights unrecognized function names
- Output type validation – When a
.calc file includes a // calcId: $fieldName comment, validates that the expression's output type matches the expected field datatype from form_description.json
- ISNULL/GENERIC_FIELD – Error suggesting
ISBLANK() instead
Use Ctrl+. or click the lightbulb for quick fixes.
Feedback
Report bugs or request features in the Codeberg repository. Include sample expressions for faster reproduction.