Fix incorrect lsp inlay hint type (#20044)

This commit is contained in:
Matthew Mckee 2025-08-22 16:12:49 +01:00 committed by GitHub
parent 8b827c3c6c
commit 0e9d77e43a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 4 deletions

View file

@ -26,7 +26,7 @@ pub use document_symbols::{document_symbols, document_symbols_with_options};
pub use goto::{goto_declaration, goto_definition, goto_type_definition}; pub use goto::{goto_declaration, goto_definition, goto_type_definition};
pub use goto_references::goto_references; pub use goto_references::goto_references;
pub use hover::hover; pub use hover::hover;
pub use inlay_hints::{InlayHintSettings, inlay_hints}; pub use inlay_hints::{InlayHintContent, InlayHintSettings, inlay_hints};
pub use markup::MarkupKind; pub use markup::MarkupKind;
pub use references::ReferencesMode; pub use references::ReferencesMode;
pub use rename::{can_rename, rename}; pub use rename::{can_rename, rename};

View file

@ -9,7 +9,7 @@ use crate::session::client::Client;
use lsp_types::request::InlayHintRequest; use lsp_types::request::InlayHintRequest;
use lsp_types::{InlayHintParams, Url}; use lsp_types::{InlayHintParams, Url};
use ruff_db::source::{line_index, source_text}; use ruff_db::source::{line_index, source_text};
use ty_ide::inlay_hints; use ty_ide::{InlayHintContent, inlay_hints};
use ty_project::ProjectDatabase; use ty_project::ProjectDatabase;
pub(crate) struct InlayHintRequestHandler; pub(crate) struct InlayHintRequestHandler;
@ -56,7 +56,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
.position .position
.to_position(&source, &index, snapshot.encoding()), .to_position(&source, &index, snapshot.encoding()),
label: lsp_types::InlayHintLabel::String(hint.display(db).to_string()), label: lsp_types::InlayHintLabel::String(hint.display(db).to_string()),
kind: Some(lsp_types::InlayHintKind::TYPE), kind: Some(inlay_hint_kind(&hint.content)),
tooltip: None, tooltip: None,
padding_left: None, padding_left: None,
padding_right: None, padding_right: None,
@ -70,3 +70,10 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
} }
impl RetriableRequestHandler for InlayHintRequestHandler {} impl RetriableRequestHandler for InlayHintRequestHandler {}
fn inlay_hint_kind(inlay_hint_content: &InlayHintContent) -> lsp_types::InlayHintKind {
match inlay_hint_content {
InlayHintContent::Type(_) => lsp_types::InlayHintKind::TYPE,
InlayHintContent::CallArgumentName(_) => lsp_types::InlayHintKind::PARAMETER,
}
}

View file

@ -51,7 +51,7 @@ foo(1)
"character": 4 "character": 4
}, },
"label": "a=", "label": "a=",
"kind": 1 "kind": 2
} }
] ]
"#); "#);

View file

@ -455,6 +455,7 @@ impl Workspace {
&source, &source,
self.position_encoding, self.position_encoding,
), ),
kind: hint.content.into(),
}) })
.collect()) .collect())
} }
@ -977,6 +978,22 @@ impl From<ty_python_semantic::CompletionKind> for CompletionKind {
} }
} }
#[wasm_bindgen]
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum InlayHintKind {
Type,
Parameter,
}
impl From<ty_ide::InlayHintContent<'_>> for InlayHintKind {
fn from(kind: ty_ide::InlayHintContent) -> Self {
match kind {
ty_ide::InlayHintContent::Type(_) => Self::Type,
ty_ide::InlayHintContent::CallArgumentName(_) => Self::Parameter,
}
}
}
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct InlayHint { pub struct InlayHint {
@ -984,6 +1001,8 @@ pub struct InlayHint {
pub markdown: String, pub markdown: String,
pub position: Position, pub position: Position,
pub kind: InlayHintKind,
} }
#[wasm_bindgen] #[wasm_bindgen]

View file

@ -27,6 +27,7 @@ import {
type FileHandle, type FileHandle,
DocumentHighlight, DocumentHighlight,
DocumentHighlightKind, DocumentHighlightKind,
InlayHintKind,
} from "ty_wasm"; } from "ty_wasm";
import { FileId, ReadonlyFiles } from "../Playground"; import { FileId, ReadonlyFiles } from "../Playground";
import { isPythonFile } from "./Files"; import { isPythonFile } from "./Files";
@ -405,6 +406,15 @@ class PlaygroundServer
return undefined; return undefined;
} }
function mapInlayHintKind(kind: InlayHintKind): languages.InlayHintKind {
switch (kind) {
case InlayHintKind.Type:
return languages.InlayHintKind.Type;
case InlayHintKind.Parameter:
return languages.InlayHintKind.Parameter;
}
}
return { return {
dispose: () => {}, dispose: () => {},
hints: inlayHints.map((hint) => ({ hints: inlayHints.map((hint) => ({
@ -413,6 +423,7 @@ class PlaygroundServer
lineNumber: hint.position.line, lineNumber: hint.position.line,
column: hint.position.column, column: hint.position.column,
}, },
kind: mapInlayHintKind(hint.kind),
})), })),
}; };
} }