Skip to content

✨ feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support#1397

Merged
harehare merged 4 commits intomainfrom
feat/mq-wasm-inlay-hint
Mar 6, 2026
Merged

✨ feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support#1397
harehare merged 4 commits intomainfrom
feat/mq-wasm-inlay-hint

Conversation

@harehare
Copy link
Copy Markdown
Owner

@harehare harehare commented Mar 6, 2026

  • Add mq-check dependency to mq-wasm
  • Extend diagnostics API to support type checking
  • Implement inlayHints API for type annotation hints
  • Update TypeScript interface for inlayHints

…ith type checking support

- Add mq-check dependency to mq-wasm
- Extend diagnostics API to support type checking
- Implement inlayHints API for type annotation hints
- Update TypeScript interface for inlayHints

Closes #issue (if relevant)
Copilot AI review requested due to automatic review settings March 6, 2026 12:44
@harehare harehare changed the title feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support : sparkle feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support Mar 6, 2026
@harehare harehare changed the title : sparkle feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support :sparkle feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support Mar 6, 2026
@harehare harehare changed the title :sparkle feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support ❇️ feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support Mar 6, 2026
@harehare harehare changed the title ❇️ feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support ✨ feat(mq-wasm): add mq-check dependency and implement inlayHints API with type checking support Mar 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds type-checking capabilities to the mq-wasm WebAssembly bindings by wiring in mq-check, extending the diagnostics API, and exposing a new inlayHints API for inferred type annotations.

Changes:

  • Add mq-check as a dependency of mq-wasm.
  • Extend diagnostics(code) to optionally include type-checking errors via enableTypeCheck.
  • Add inlayHints(code) API (plus TS types) to return inferred type annotation hints.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/mq-wasm/src/script.rs Adds TS typings, optional type-checking diagnostics, and a new inlayHints wasm export backed by mq-check.
crates/mq-wasm/Cargo.toml Adds mq-check workspace dependency for wasm bindings.
Cargo.lock Locks the new mq-check dependency for mq-wasm.

Comment on lines +529 to +530
serde_wasm_bindgen::to_value(&hints).unwrap_or(JsValue::NULL)
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

inlay_hints returns JsValue::NULL if serialization fails, but the TypeScript signature promises an array. Returning null will force consumers to add null checks and may cause runtime errors. Prefer returning an empty array on failure or propagating a JS error (consistent with other exports that unwrap() or return Result).

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 6, 2026 12:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +490 to +496
pub async fn inlay_hints(code: &str) -> JsValue {
let mut hir = mq_hir::Hir::default();
hir.add_code(None, code);

let mut checker = mq_check::TypeChecker::default();
let _ = checker.check(&hir);

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

inlay_hints always runs HIR construction + type checking even when the source has parse errors. Since Hir::add_code uses recovery and drops parse errors, this can produce inlay hints for syntactically-invalid code (and do extra work) while diagnostics explicitly skips type checking unless there are no parse errors. Consider mirroring diagnostics behavior by checking mq_lang::parse_recovery first and returning an empty hint list when parse errors exist.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 6, 2026 13:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines 486 to 487
serde_wasm_bindgen::to_value(&errors).unwrap()
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

diagnostics() ends with serde_wasm_bindgen::to_value(&errors).unwrap(), which will panic the WASM module on serialization failure. Since this function now aggregates parse + type-check errors (and is called on every edit in the playground), prefer returning a safe fallback (e.g., empty array) or converting the error into a JsValue rather than panicking.

Suggested change
serde_wasm_bindgen::to_value(&errors).unwrap()
}
serde_wasm_bindgen::to_value(&errors)
.unwrap_or_else(|_| JsValue::from(js_sys::Array::new()))

Copilot uses AI. Check for mistakes.
Comment on lines +463 to +468
if enable_type_check.unwrap_or(false) && errors.is_empty() {
let mut hir = mq_hir::Hir::default();
hir.add_code(None, code);

let mut checker = mq_check::TypeChecker::default();
let type_errors = checker.check(&hir);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

diagnostics() now has an enable_type_check path that runs mq_check::TypeChecker and converts TypeError into Diagnostic, but there are no wasm_bindgen tests covering this behavior. Add a test that calls diagnostics(code, Some(true)) on a known type mismatch and asserts the returned message + 1-based line/column mapping.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +489 to +497
#[wasm_bindgen(js_name=inlayHints, skip_typescript)]
pub async fn inlay_hints(code: &str) -> JsValue {
let mut hir = mq_hir::Hir::default();
hir.add_code(None, code);

let mut checker = mq_check::TypeChecker::default();
let _ = checker.check(&hir);

let symbol_types = checker.symbol_types();
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The new exported inlay_hints() API currently has no wasm_bindgen tests. Add a test that type-checks a small snippet (e.g., a let binding and/or def) and asserts that inlay_hints() returns a hint at the end of the identifier with the expected label, and that built-in symbols are excluded.

Copilot generated this review using guidance from repository custom instructions.
@harehare harehare merged commit f2b3df7 into main Mar 6, 2026
8 checks passed
@harehare harehare deleted the feat/mq-wasm-inlay-hint branch March 6, 2026 13:31
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.

2 participants