[ty] Inlay hint call argument location (#20349)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Matthew Mckee 2025-11-17 10:33:09 +00:00 committed by GitHub
parent 58fa1d71b6
commit 901e9cdf49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 1447 additions and 115 deletions

View file

@ -5,7 +5,8 @@ use lsp_types::{InlayHintParams, Url};
use ty_ide::{InlayHintKind, InlayHintLabel, inlay_hints};
use ty_project::ProjectDatabase;
use crate::document::{RangeExt, TextSizeExt};
use crate::PositionEncoding;
use crate::document::{RangeExt, TextSizeExt, ToLink};
use crate::server::api::traits::{
BackgroundDocumentRequestHandler, RequestHandler, RetriableRequestHandler,
};
@ -57,7 +58,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
.position
.to_lsp_position(db, file, snapshot.encoding())?
.local_position(),
label: inlay_hint_label(&hint.label),
label: inlay_hint_label(&hint.label, db, snapshot.encoding()),
kind: Some(inlay_hint_kind(&hint.kind)),
tooltip: None,
padding_left: None,
@ -81,12 +82,18 @@ fn inlay_hint_kind(inlay_hint_kind: &InlayHintKind) -> lsp_types::InlayHintKind
}
}
fn inlay_hint_label(inlay_hint_label: &InlayHintLabel) -> lsp_types::InlayHintLabel {
fn inlay_hint_label(
inlay_hint_label: &InlayHintLabel,
db: &ProjectDatabase,
encoding: PositionEncoding,
) -> lsp_types::InlayHintLabel {
let mut label_parts = Vec::new();
for part in inlay_hint_label.parts() {
label_parts.push(lsp_types::InlayHintLabelPart {
value: part.text().into(),
location: None,
location: part
.target()
.and_then(|target| target.to_location(db, encoding)),
tooltip: None,
command: None,
});

View file

@ -59,7 +59,20 @@ y = foo(1)
},
"label": [
{
"value": "a"
"value": "a",
"location": {
"uri": "file://<temp_dir>/src/foo.py",
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 9
}
}
}
},
{
"value": "="