-
Notifications
You must be signed in to change notification settings - Fork 215
fix Tuple Types in type hints are currently not clickable #1680 #1683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
1d353ce to
47541c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR makes tuple types clickable in inlay hints by enabling the tuple keyword to have location information that links to its definition. The implementation threads a tuple QName through the type display system when stdlib context is available.
- TypeDisplayContext gains the ability to track extra symbol QNames (like "tuple") with their definition locations
- The Type::get_types_with_locations API now requires a Stdlib parameter to access the tuple class definition
- Test files updated to strip location fields from JSON assertions since locations are now dynamically computed
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/pyrefly_types/src/display.rs |
Added extra_symbol_qnames tracking to TypeDisplayContext; updated get_types_with_locations to require Stdlib parameter and inject tuple QName |
crates/pyrefly_types/src/tuple.rs |
Modified fmt_with_type to accept optional tuple QName and use write_qname when available |
crates/pyrefly_types/src/type_output.rs |
Added test verifying tuple keyword is clickable when QName is provided |
pyrefly/lib/lsp/module_helpers.rs |
Added collect_symbol_def_paths_with_stdlib to include tuple QName when type contains tuples |
pyrefly/lib/lsp/wasm/inlay_hints.rs |
Updated to fetch stdlib and pass to get_types_with_locations |
pyrefly/lib/lsp/wasm/hover.rs |
Refactored to compute symbol_def_paths once and store in HoverValue struct |
pyrefly/lib/state/lsp.rs |
Updated to use new collect_symbol_def_paths_with_stdlib function |
pyrefly/lib/test/lsp/lsp_interaction/inlay_hint.rs |
Added helper functions to strip location fields from test assertions |
pyrefly/lib/test/lsp/lsp_interaction/notebook_inlay_hint.rs |
Added helper functions to strip location fields from test assertions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn expect_inlay_hint_response(handle: ClientRequestHandle<'_, InlayHintRequest>, expected: Value) { | ||
| let mut expected = expected; | ||
| strip_inlay_hint_locations(&mut expected); | ||
| let _ = handle.expect_response_with(move |result| { | ||
| let mut actual_json = serde_json::to_value(&result).unwrap(); | ||
| strip_inlay_hint_locations(&mut actual_json); | ||
| actual_json == expected | ||
| }); | ||
| } | ||
|
|
||
| fn strip_inlay_hint_locations(value: &mut Value) { | ||
| match value { | ||
| Value::Object(map) => { | ||
| map.remove("location"); | ||
| for inner in map.values_mut() { | ||
| strip_inlay_hint_locations(inner); | ||
| } | ||
| } | ||
| Value::Array(items) => { | ||
| for item in items { | ||
| strip_inlay_hint_locations(item); | ||
| } | ||
| } | ||
| _ => {} | ||
| } | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These helper functions (expect_inlay_hint_response and strip_inlay_hint_locations) are duplicated in both notebook_inlay_hint.rs and inlay_hint.rs. Consider extracting them to a shared test utility module (e.g., util.rs) to avoid duplication and make maintenance easier.
Summary
Fixes #1680
TypeDisplayContext now tracks an optional tuple QName, exposes new_with_tuple, and Type gained get_types_with_locations_with_stdlib, so callers with a stdlib can request clickable tuple bases while legacy callers stay untouched.
The formatting stack gained TypeOutput::write_tuple_keyword, Tuple::fmt_with_type now routes through it, and OutputWithLocations injects the tuple location when available, giving us localized spans without changing the rendered text.
The inlay-hint provider fetches the stdlib once per request and uses the new helper so tuple keywords inside hints are now cmd+clickable.
Test Plan
cargo test -p pyrefly_types type_output::tests::test_output_with_locations_tuple_base_clickable_when_qname_available
cargo test -p pyrefly_types display::tests::test_get_types_with_location_tuple.