Skip to content

Commit 6e68f91

Browse files
MatthewMckee4second-ed
authored andcommitted
Fix incorrect lsp inlay hint type (astral-sh#20044)
1 parent 43d7463 commit 6e68f91

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

crates/ty_ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use document_symbols::{document_symbols, document_symbols_with_options};
2626
pub use goto::{goto_declaration, goto_definition, goto_type_definition};
2727
pub use goto_references::goto_references;
2828
pub use hover::hover;
29-
pub use inlay_hints::{InlayHintSettings, inlay_hints};
29+
pub use inlay_hints::{InlayHintContent, InlayHintSettings, inlay_hints};
3030
pub use markup::MarkupKind;
3131
pub use references::ReferencesMode;
3232
pub use rename::{can_rename, rename};

crates/ty_server/src/server/api/requests/inlay_hints.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::session::client::Client;
99
use lsp_types::request::InlayHintRequest;
1010
use lsp_types::{InlayHintParams, Url};
1111
use ruff_db::source::{line_index, source_text};
12-
use ty_ide::inlay_hints;
12+
use ty_ide::{InlayHintContent, inlay_hints};
1313
use ty_project::ProjectDatabase;
1414

1515
pub(crate) struct InlayHintRequestHandler;
@@ -56,7 +56,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
5656
.position
5757
.to_position(&source, &index, snapshot.encoding()),
5858
label: lsp_types::InlayHintLabel::String(hint.display(db).to_string()),
59-
kind: Some(lsp_types::InlayHintKind::TYPE),
59+
kind: Some(inlay_hint_kind(&hint.content)),
6060
tooltip: None,
6161
padding_left: None,
6262
padding_right: None,
@@ -70,3 +70,10 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
7070
}
7171

7272
impl RetriableRequestHandler for InlayHintRequestHandler {}
73+
74+
fn inlay_hint_kind(inlay_hint_content: &InlayHintContent) -> lsp_types::InlayHintKind {
75+
match inlay_hint_content {
76+
InlayHintContent::Type(_) => lsp_types::InlayHintKind::TYPE,
77+
InlayHintContent::CallArgumentName(_) => lsp_types::InlayHintKind::PARAMETER,
78+
}
79+
}

crates/ty_server/tests/e2e/inlay_hints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ foo(1)
5151
"character": 4
5252
},
5353
"label": "a=",
54-
"kind": 1
54+
"kind": 2
5555
}
5656
]
5757
"#);

crates/ty_wasm/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ impl Workspace {
455455
&source,
456456
self.position_encoding,
457457
),
458+
kind: hint.content.into(),
458459
})
459460
.collect())
460461
}
@@ -977,13 +978,31 @@ impl From<ty_python_semantic::CompletionKind> for CompletionKind {
977978
}
978979
}
979980

981+
#[wasm_bindgen]
982+
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
983+
pub enum InlayHintKind {
984+
Type,
985+
Parameter,
986+
}
987+
988+
impl From<ty_ide::InlayHintContent<'_>> for InlayHintKind {
989+
fn from(kind: ty_ide::InlayHintContent) -> Self {
990+
match kind {
991+
ty_ide::InlayHintContent::Type(_) => Self::Type,
992+
ty_ide::InlayHintContent::CallArgumentName(_) => Self::Parameter,
993+
}
994+
}
995+
}
996+
980997
#[wasm_bindgen]
981998
#[derive(Debug, Clone, PartialEq, Eq)]
982999
pub struct InlayHint {
9831000
#[wasm_bindgen(getter_with_clone)]
9841001
pub markdown: String,
9851002

9861003
pub position: Position,
1004+
1005+
pub kind: InlayHintKind,
9871006
}
9881007

9891008
#[wasm_bindgen]

playground/ty/src/Editor/Editor.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type FileHandle,
2828
DocumentHighlight,
2929
DocumentHighlightKind,
30+
InlayHintKind,
3031
} from "ty_wasm";
3132
import { FileId, ReadonlyFiles } from "../Playground";
3233
import { isPythonFile } from "./Files";
@@ -405,6 +406,15 @@ class PlaygroundServer
405406
return undefined;
406407
}
407408

409+
function mapInlayHintKind(kind: InlayHintKind): languages.InlayHintKind {
410+
switch (kind) {
411+
case InlayHintKind.Type:
412+
return languages.InlayHintKind.Type;
413+
case InlayHintKind.Parameter:
414+
return languages.InlayHintKind.Parameter;
415+
}
416+
}
417+
408418
return {
409419
dispose: () => {},
410420
hints: inlayHints.map((hint) => ({
@@ -413,6 +423,7 @@ class PlaygroundServer
413423
lineNumber: hint.position.line,
414424
column: hint.position.column,
415425
},
426+
kind: mapInlayHintKind(hint.kind),
416427
})),
417428
};
418429
}

0 commit comments

Comments
 (0)