[ty] Implement goto-type for inlay type hints (#21533)

This PR generalizes the signature_help system's SignatureWriter which
could get the subspans of function parameters.
We now have TypeDetailsWriter which is threaded between type's display
implementations via a new `fmt_detailed` method that many of the Display
types now have.

With this information we can properly add goto-type targets to our inlay
hints. This also lays groundwork for any future "I want to render a type
but get spans" work.

Also a ton of lifetimes are introduced to avoid things getting conflated
with `'db`.

This PR is broken up into a series of commits:

* Generalizing `SignatureWriter` to `TypeDetailsWriter`, but not using
it anywhere else. This commit was confirmed to be a non-functional
change (no test results changed)
* Introducing `fmt_detailed` everywhere to thread through
`TypeDetailsWriter` and annotate various spans as "being" a given Type
-- this is also where I had to reckon with a ton of erroneous `&'db
self`. This commit was also confirmed to be a non-functional change.
* Finally, actually using the results for goto-type on inlay hints!
* Regenerating snapshots, fixups, etc.
This commit is contained in:
Aria Desires 2025-11-20 09:40:40 -05:00 committed by GitHub
parent 02c102da88
commit 416e2267da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 2664 additions and 701 deletions

File diff suppressed because it is too large Load Diff

View File

@ -50,8 +50,8 @@ use crate::types::constraints::{
};
use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder};
use crate::types::diagnostic::{INVALID_AWAIT, INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION};
pub use crate::types::display::DisplaySettings;
use crate::types::display::TupleSpecialization;
pub use crate::types::display::{DisplaySettings, TypeDetail, TypeDisplayDetails};
use crate::types::enums::{enum_metadata, is_single_member_enum};
use crate::types::function::{
DataclassTransformerFlags, DataclassTransformerParams, FunctionDecorators, FunctionSpans,

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,20 @@ y = foo(1)
"value": ": "
},
{
"value": "int"
"value": "int",
"location": {
"uri": "file://<typeshed>/stdlib/builtins.pyi",
"range": {
"start": {
"line": 347,
"character": 6
},
"end": {
"line": 347,
"character": 9
}
}
}
}
],
"kind": 1

View File

@ -1198,6 +1198,7 @@ impl TestContext {
r#"The system cannot find the file specified."#,
"No such file or directory",
);
settings.add_filter(r"file://.*/stdlib/", "file://<typeshed>/stdlib/");
let settings_scope = settings.bind_to_scope();