pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

fix Types from the typing module are currently not clickable in type hints #1681

Open asukaminato0721 opened this issue 1 month ago • 1 comments

Summary

Fixes #1681

Reworked the type-label plumbing so OutputWithLocations now emits TypeLabelPart records that carry both the rendered text and optional TypeSymbolReference metadata (module/name) whenever we render known symbols (e.g., via maybe_fmt_with_module). This involved extending the TypeOutput trait with write_symbol and updating all implementations/tests accordingly.

In the LSP transaction, added resolve_type_symbol_reference to import typing/typing_extensions modules on demand and attach their source locations to inlay-hint label parts when the original type string lacked a location. Both return-type and variable-type hint builders now fall back to this resolver before emitting each label part.

Test Plan

Strengthened coverage with a new end-to-end LSP test that asserts Literal label parts point into typing.pyi, alongside the existing goto-type-definition test. The display-layer tests were also updated to exercise the richer label parts and verify Literal parts carry typing metadata.

asukaminato0721 avatar Nov 25 '25 17:11 asukaminato0721

Thanks for taking a look at this! I have been looking at this as well as https://github.com/facebook/pyrefly/pull/1683 and I am wondering if there is one solution that we can use for both of these. It seems like to get tuples working we are including the entire stdlib along with TypeOutput which seems like a large lift for just that purpose. I am wondering if we could also combine that logic with what we do here somehow. What do you think?

jvansch1 avatar Nov 26 '25 14:11 jvansch1