TypeScript Plugin
a-calc provides a TypeScript language service plugin that gives intelligent autocomplete for expression strings in calc, fmt, and other functions.
Features
- Variable completion — suggests variable names from the second argument
- Format syntax completion — suggests all formatting options after
| - Preset completion — suggests preset names after
! - Unit completion — suggests available units based on project config
- Deep property support — supports nested property completion like
user.name
Setup
Add the plugin to your tsconfig.json:
json
{
"compilerOptions": {
"plugins": [{ "name": "a-calc/ts-plugin" }]
}
}VS Code Configuration
VS Code uses its built-in TypeScript version by default. You need to switch to the workspace version to load plugins.
Option 1: Manual Switch
- Open any
.tsfile - Press
Ctrl+Shift+P(Mac:Cmd+Shift+P) - Type
TypeScript: Select TypeScript Version - Select
Use Workspace Version
Option 2: Auto Switch
Add to .vscode/settings.json:
json
{
"typescript.tsdk": "node_modules/typescript/lib"
}Completion Examples
Variable Completion
Type a variable name prefix in the expression area:
typescript
const data = { price: 100, quantity: 3, user: { name: "test" } };
calc("pri", data); // typing 'pri' suggests 'price'
calc("user.", data); // typing 'user.' suggests 'name'Format Syntax Completion
Trigger completion after | to see all formatting options:
typescript
calc("100 | "); // suggests =N, <=N, %, ,, !t, !c, etc.Preset Completion
Type ! to see preset types:
typescript
calc("100 | !"); // suggests t (thousands), c (compact), u (unit), etc.
calc("100 | !t:"); // suggests en, indian, wan, etc.Supported Functions
The plugin provides completion for these functions:
calcfmtcalc_sumcalc_wrapcalc_spacecalc_avgcalc_maxcalc_mincalc_count
Notes
- Restart VS Code or reload the window after modifying
tsconfig.json - Ensure
typescriptis installed as a project dependency - The plugin only works in TypeScript files