Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

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.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 3, 2025 06:20
Copilot AI review requested due to automatic review settings December 3, 2025 06:20
Copy link

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

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.

Comment on lines +109 to +134
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);
}
}
_ => {}
}
}
Copy link

Copilot AI Dec 3, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tuple Types in type hints are currently not clickable

2 participants