Inspiration

Python happily allows 100 meters + 10 seconds. For scientific, robotics, engineering, and data code, that kind of mistake can quietly produce bad results. We wanted physical units to feel as natural and immediate as type errors.

What it does

DimLint is a VS Code extension that performs dimensional analysis on Python code as you write it. It understands SI units such as meters, seconds, kilograms, velocity, force, and energy.

It catches incompatible arithmetic, comparisons, dimensional exponents, wrong function arguments and return values, and invalid reassignments. It also provides hover explanations, inferred-unit inlay hints, function-contract CodeLens, safe quick fixes, and an opt-in AI workflow that proposes missing Annotated unit types as a reviewable diff.

How we built it

We built DimLint as a VS Code extension in TypeScript backed by a Python language server. The Python engine walks the AST, represents every unit as SI base-dimension exponents, propagates units through expressions, and publishes diagnostics over the Language Server Protocol.

The extension turns that analysis into editor features: diagnostics, hover cards, CodeLens, inlay hints, generated comments, and code actions. For AI annotation suggestions, we use OpenRouter to propose unit contracts from selected code, docstrings, and nearby equations, then show the result in a diff before the user can apply it.

Challenges we ran into

Dimensional analysis is straightforward on paper but tricky in a real editor. We had to make inference work through nested expressions, function calls, returns, reassignment, augmented assignment, and incomplete code while someone was actively typing.

The AI workflow added another challenge: a suggestion must be helpful without becoming an unsafe automatic rewrite. We added explicit consent before sending code, strict unit guidance, import cleanup, unit normalization, a diff preview, and a separate apply action.

Accomplishments that we're proud of

We turned a static-analysis idea into a polished editor experience rather than only a command-line checker. DimLint gives immediate, understandable feedback for errors like adding velocity to time, comparing distance with duration, or using a quantity as an exponent.

We are especially proud of the hybrid workflow: deterministic rules catch mistakes reliably, while AI helps developers add unit annotations to existing code without forcing them to write every contract manually.

What we learned

We learned how much value comes from presenting analysis where developers already work. A precise diagnostic is useful, but hover explanations, inlay hints, CodeLens, and reviewable fixes make the feedback much easier to understand and act on.

We also learned that AI works best as a constrained assistant around a trustworthy rules engine, not as a replacement for correctness.

What's next for DimLint

Next, we want to support unit conversions and prefixes such as kilometers, centimeters, and hours; add richer support for libraries like NumPy and Pandas; analyze units across files; and let teams define domain-specific units and contracts.

We also want to improve the AI assistant with project-wide context and confidence scoring, while keeping every suggested change reviewable by the developer.

Built With

Share this project:

Updates