Skip to content

feat(lsp): extract real Ty from NetType field specs (fixes TODO(type-hints)) - #1276

Open
Dev-X25874 wants to merge 3 commits into
diodeinc:mainfrom
Dev-X25874:feat/lsp-type-hints-net
Open

Dev-X25874 wants to merge 3 commits into
diodeinc:mainfrom
Dev-X25874:feat/lsp-type-hints-net

Conversation

@Dev-X25874

@Dev-X25874 Dev-X25874 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Resolves both TODO(type-hints) markers in crates/pcb-zen-core/src/lang/net.rs.

Single file changed. New ty_from_field_spec() helper replaces Ty::any() in param_spec() and eval_type() so LSP clients see concrete types instead of any.


Note

Low Risk
Changes only static typing hints for LSP/typechecker; runtime field validation still goes through existing compile_field_type / validate_field paths with a safe Ty::any() fallback.

Overview
Improves LSP and typechecker metadata for NetType constructors and net instances by emitting concrete field types instead of Ty::any().

Adds ty_from_field_spec() as the shared extractor: it reads types from field(...) specs (FieldGen + TypeCompiled), from bare net type constructors via eval_type(), and falls back to Ty::any() when the spec shape is unknown.

param_spec() now attaches those types to each optional keyword field (constructor signature help / hover). eval_type() uses the same helper for known_fields on custom net instance types (field hover and completion). The two TODO(type-hints) comments in this file are removed.

Reviewed by Cursor Bugbot for commit cb71242. Bugbot is set up for automated code reviews on this repo. Configure here.

Replace Ty::any() at both TODO(type-hints) sites in NetTypeGen:
- param_spec(): constructor params now carry concrete Ty for signature-help
- eval_type(): known_fields now carry concrete Ty for hover/completion
New helper ty_from_field_spec() handles FieldGen<V>, bare NetType,
and falls back to Ty::any() for unrecognised spec kinds.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +1019 to +1020
// Safe fallback — lets the LSP accept any value rather than emit a wrong type.
Ty::any()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Bare field types remain untyped

ty_from_field_spec returns any for supported bare specs such as str, enums, Symbol, and physical types. Their constructor parameters and instance fields retain inaccurate hints.

Learn more

Net types accept both field(type, ...) wrappers and direct type specifications. The direct path is validated through TypeCompiled::new in NetType::new, and existing uses include primitive, enum, symbol, and physical-value constructors. The helper recognizes only wrapped fields and net constructors, so every other valid direct specification reaches Ty::any().

Example: Signal = builtin.net_type("Signal", frequency=int) validates frequency as an integer at runtime. The LSP still displays frequency: any in Signal(...) and on a Signal instance instead of frequency: int.

Recommended fix: Add a general extraction path for valid direct type specifications, using the Starlark value's instance/evaluation type or the same compiled type representation used during validation. Preserve Ty::any() only when no concrete instance type can be derived, and add coverage for primitive, enum, Symbol, and physical-value specs.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4cca810. Configure here.

ArcStr::from(field_name.as_str()),
ParamIsRequired::No,
Ty::any(),
ty_from_field_spec(field_spec.to_value()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor types reject implicit conversions

High Severity

param_spec now uses the stored field Ty as the constructor argument type. Runtime still accepts implicit conversions such as strings and scalars for physical fields like voltage. With static typechecking enabled, common calls such as Power(voltage="3.3V") can fail even though they evaluate correctly.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4cca810. Configure here.

@Dev-X25874

Copy link
Copy Markdown
Contributor Author

Hey @akhilles, could you please review #1276? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant