[ty] Refactor inlay hints structure to use separate parts (#20052)

## Summary

Our internal inlay hints structure (`ty_ide::InlayHint`) now more
closely resembles `lsp_types::InlayHint`.

This mainly allows us to convert to `lsp_types::InlayHint` with less
hassle, but it also allows us to manage the different parts of the inlay
hint better, which in the future will allow us to implement features
like goto on the type part of the type inlay hint.

It also really isn't important to store a specific `Type` instance in
the `InlayHintContent`. So we remove this and use `InlayHintLabel`
instead which just shows the representation of the type (along with
other information).

We see a similar structure used in rust-analyzer too.
This commit is contained in:
Matthew Mckee 2025-08-26 05:51:31 +01:00 committed by GitHub
parent ef4897f9f3
commit 8d6dc7d3a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 147 additions and 61 deletions

View file

@ -449,14 +449,14 @@ impl Workspace {
Ok(result
.into_iter()
.map(|hint| InlayHint {
markdown: hint.display(&self.db).to_string(),
markdown: hint.display().to_string(),
position: Position::from_text_size(
hint.position,
&index,
&source,
self.position_encoding,
),
kind: hint.content.into(),
kind: hint.kind.into(),
})
.collect())
}
@ -988,11 +988,11 @@ pub enum InlayHintKind {
Parameter,
}
impl From<ty_ide::InlayHintContent<'_>> for InlayHintKind {
fn from(kind: ty_ide::InlayHintContent) -> Self {
impl From<ty_ide::InlayHintKind> for InlayHintKind {
fn from(kind: ty_ide::InlayHintKind) -> Self {
match kind {
ty_ide::InlayHintContent::Type(_) => Self::Type,
ty_ide::InlayHintContent::CallArgumentName(_) => Self::Parameter,
ty_ide::InlayHintKind::Type => Self::Type,
ty_ide::InlayHintKind::CallArgumentName => Self::Parameter,
}
}
}