Skip to content

Commit b16e658

Browse files
author
Michele Pasinelli
committed
Add lookup table research
- Added the new CSV lookup signature: `csv(table, lookupValue, lookupColumn, valueColumn[, interpolation])`. - Kept backward compatibility with the previous 3-argument form: `csv(table, lookupValue, valueColumn)`. - Added optional interpolation modes when the lookup key is missing: - `none` / `exact` (default, no interpolation) - `linear` / `lerp` - `nearest` / `closest` - `csv`, `table`, and `lookup` remain aliases of the same function.
1 parent 2fbe954 commit b16e658

27 files changed

Lines changed: 3600 additions & 1043 deletions
363 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@
1212

1313
## 0.1.4
1414
- Extended CodeLens to all C files
15+
16+
## 0.1.5
17+
- Added the new CSV lookup signature: `csv(table, lookupValue, lookupColumn, valueColumn[, interpolation])`.
18+
- Kept backward compatibility with the previous 3-argument form: `csv(table, lookupValue, valueColumn)`.
19+
- Added optional interpolation modes when the lookup key is missing:
20+
- `none` / `exact` (default, no interpolation)
21+
- `linear` / `lerp`
22+
- `nearest` / `closest`
23+
- `csv`, `table`, and `lookup` remain aliases of the same function.

README.md

Lines changed: 129 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
1-
# 🧮 CalcDocs - Formula Hover, Definition and C/C++ Sync
1+
# 🧮 CalcDocs - Formula Evaluator & C/C++ Constant Sync + Computed-Value Preview
22

3-
Formula navigation and evaluation for YAML engineering formulas and C/C++ constants directly inside Visual Studio Code.
3+
**See the real values your compiler produces. Catch errors before they hit your firmware. Navigate formulas instantly.**
4+
5+
**CalcDocs is your real‑time engineering sanity checker.**
6+
7+
It prevents subtle errors by showing you actual computed values — the ones you'd only catch *after* compiling — and keeps your formulas and C/C++ constants perfectly synchronized.
8+
9+
CalcDocs is a VS Code extension designed for firmware and embedded developers who work with engineering formulas in YAML and constants in C/C++.
10+
It helps you **keep formulas, documentation, and code always aligned** — automatically.
11+
12+
## 🔥 Why CalcDocs?
13+
Writing engineering formulas and constants across YAML and C/C++ files often leads to hidden issues:
14+
- A formula looks correct… but the final computed value is wrong.
15+
- A `#define` expands to something unexpected.
16+
- A constant silently overflows the target type.
17+
- Documentation and code drift apart without anyone noticing.
18+
19+
CalcDocs solves all of this by showing you **what the compiler would really compute**, directly inside your editor.
20+
21+
## ⭐ Key Features (the real value)
22+
- **Real computed values (compiler‑level evaluation)**
23+
CalcDocs expands formulas and C/C++ definitions, showing the *final numeric value* you would see only after compiling.
24+
This helps catch wrong formulas, overflow, unit errors, and “nonsense values” early.
25+
*(Supports YAML formulas, `#define`, `const`, and nested dependencies.)*
26+
27+
- **Instant navigation — “Go to Definition”**
28+
Jump from any formula symbol or C/C++ constant straight to its definition, even across YAML ↔ C/C++ boundaries.
29+
30+
- **Hover previews everywhere**
31+
Hover over a symbol to see:
32+
- expanded formula
33+
- substituted values
34+
- evaluated numeric result
35+
- source location (YAML or C/C++)
36+
37+
- **CodeLens with effective values**
38+
CalcDocs adds CodeLens annotations showing the *real resolved value* of complex C/C++ constants — even when computed through multiple macro layers.
39+
40+
- **Mismatch detection**
41+
Warns you when YAML values and computed C/C++ constants diverge beyond a threshold.
42+
43+
- **Automatic YAML write‑back**
44+
When formulas are refreshed, YAML `dati` and `value` fields are updated automatically.
45+
46+
---
447

548
![CalcDocs Demo](https://github.com/mik1981/Calcdocs-VSCode-Extension/raw/main/resources/CalcDocs_Refresh.gif)
649
![CalcDocs Screenshot](https://github.com/mik1981/Calcdocs-VSCode-Extension/raw/main/resources/CalcDocs_Definition.jpg)
@@ -10,13 +53,17 @@ CalcDocs helps firmware, embedded, and software teams keep formulas, documentati
1053
- GitHub project: [Calcdocs-VSCode-Extension](https://github.com/mik1981/Calcdocs-VSCode-Extension/)
1154
- Issues: [Open an issue](https://github.com/mik1981/Calcdocs-VSCode-Extension/issues)
1255

56+
---
57+
1358
## 📑 Index
1459

1560
- [Install from `.vsix` File (Quick Guide)](#install-from-vsix-file-quick-guide)
1661
- [Features](#features)
1762
- [Commands](#commands)
1863
- [Configuration](#configuration)
1964
- [File Scanning Rules](#file-scanning-rules)
65+
- [CSV Table Lookup](#csv-table-lookup)
66+
- [Complex Formulas and Constants](#complex-formulas-and-constants)
2067
- [Quick Example](#quick-example)
2168
- [Contributing](#contributing)
2269
- [Sponsor](#sponsor)
@@ -27,7 +74,7 @@ CalcDocs helps firmware, embedded, and software teams keep formulas, documentati
2774

2875
## 📦 Install from `.vsix` File (Quick Guide)
2976

30-
If you already have the file `calcdocs-vscode-extension-0.1.3.vsix`, you can install it without using the Marketplace.
77+
If you wish, you can directly use the file `calcdocs-vscode-extension-0.1.5.vsix` to install it without going through the Marketplace.
3178

3279
**Graphical method (recommended):**
3380

@@ -41,7 +88,7 @@ If you already have the file `calcdocs-vscode-extension-0.1.3.vsix`, you can ins
4188
**Terminal method (optional):**
4289

4390
```bash
44-
code --install-extension calcdocs-vscode-extension-0.1.3.vsix
91+
code --install-extension calcdocs-vscode-extension-0.1.5.vsix
4592
```
4693

4794
**Verify the installation:**
@@ -66,6 +113,7 @@ code --install-extension calcdocs-vscode-extension-0.1.3.vsix
66113
- C/C++ CodeLens for composite definitions with computed numeric values.
67114
- Mismatch detection between C/C++ constants and YAML computed values (warning lens when difference is significant).
68115
- YAML write-back of `dati` and `value` fields on refresh.
116+
- CSV/table lookups in formulas with named columns and optional interpolation.
69117
- Status bar quick refresh and periodic background analysis.
70118

71119
---
@@ -86,7 +134,7 @@ Available workspace settings:
86134

87135
- `calcdocs.scanInterval` (number, default `0`)
88136
- `calcdocs.ignoredDirs` (string array, folders excluded from analysis)
89-
- `calcdocs.enableCppProviders` (boolean, default `false`, keeps C/C++ tools as primary)
137+
- `calcdocs.enableCppProviders` (boolean, default `true`, keeps C/C++ tools as primary)
90138

91139
---
92140

@@ -110,6 +158,80 @@ Activation events:
110158

111159
---
112160

161+
## CSV Table Lookup
162+
163+
Use this in YAML formulas to read values from adjacent CSV files.
164+
165+
Preferred form:
166+
167+
```yaml
168+
NTC_ADC_10K_25C:
169+
formula: csv("ntc_10k_table.csv", "25", "temp_c", "resistance_ohm")
170+
```
171+
172+
With interpolation:
173+
174+
```yaml
175+
NTC_ADC_10K_22C:
176+
formula: csv("ntc_10k_table.csv", "22", "temp_c", "resistance_ohm", "linear")
177+
```
178+
179+
Legacy compatible form:
180+
181+
```yaml
182+
NTC_ADC_10K_25C_OLD:
183+
formula: csv("ntc_10k_table.csv", "25", "resistance_ohm")
184+
```
185+
186+
In summary, the available forms to use this function are:
187+
188+
1. `csv(table, lookupValue, lookupColumn, valueColumn[, interpolation])`.
189+
2. `csv(table, lookupValue, valueColumn)`.
190+
191+
For the interpolation option, the available values are:
192+
193+
- `none` / `exact` (default, no interpolation)
194+
- `linear` / `lerp`
195+
- `nearest` / `closest`
196+
197+
Note: `csv`, `table`, and `lookup` remain aliases of the same function.
198+
199+
---
200+
201+
## Complex Formulas and Constants
202+
203+
This section describes what is currently supported by the evaluator and parser.
204+
205+
Complex formulas in YAML:
206+
207+
- Arithmetic expressions with operators like `+`, `-`, `*`, `/`, `%`, parentheses, and ternary `?:`.
208+
- Bitwise and comparison operators are accepted by the evaluator, as long as the final result is a finite number.
209+
- Recursive symbol resolution across dependent `#define` constants (for example `B = A * 2`, `C = B + 3`).
210+
- Math functions and constants (case-insensitive aliases are available), including:
211+
- `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`
212+
- `sqrt`, `pow`, `log`, `log10`, `log2`, `exp`, `abs`, `min`, `max`, `round`, `floor`, `ceil`
213+
- degree helpers: `deg2rad`, `rad2deg`, `sind`, `cosd`, `tand`, `asind`, `acosd`, `atand`
214+
- constants: `pi`, `tau`, `e`
215+
- Inline table lookups through `csv(...)`, `table(...)`, `lookup(...)`, including optional interpolation modes (`none`, `linear`, `nearest`).
216+
217+
C/C++ constants currently extracted:
218+
219+
- Object-like `#define` with one-line expression:
220+
- `#define NAME EXPR`
221+
- `const`/`static const` scalar declarations with these types:
222+
- `long`, `int`, `short`, `char`, `float`, `double`
223+
- `int*_t`, `uint*_t` forms (e.g. `int32_t`, `uint16_t`)
224+
- optional `unsigned` prefix
225+
226+
Current limits:
227+
228+
- Function-like macros are ignored (for example `#define F(x) ...`).
229+
- Multi-line macros are not parsed as a single expression.
230+
- `const` declarations with unsupported types (for example pointers, structs, custom typedefs not matching supported patterns) are ignored for numeric extraction.
231+
- Expressions that do not reduce to a finite numeric value are left unresolved.
232+
233+
---
234+
113235
## 🧪 Quick Example
114236

115237
```yaml
@@ -149,7 +271,7 @@ Contributions are welcome, especially for:
149271

150272
If you find this extension useful, consider sponsoring the project.
151273

152-
[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white)](https://www.paypal.me/gianmichelepasinelli)
274+
[![PayPal](./resources/paypal.png)](https://www.paypal.me/gianmichelepasinelli)
153275

154276
---
155277

@@ -166,4 +288,4 @@ Planned improvements:
166288

167289
## 📄 License
168290

169-
[![MIT License](https://img.shields.io/github/license/Ileriayo/markdown-badges?style=for-the-badge)](./LICENSE.md)
291+
[![MIT License](./resources/mit-license.png)](./LICENSE.md)

resources/mit-license.png

7.17 KB
Loading

resources/paypal.png

7.59 KB
Loading

0 commit comments

Comments
 (0)