mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Fix incorrect lsp inlay hint type (#20044)
This commit is contained in:
parent
8b827c3c6c
commit
0e9d77e43a
5 changed files with 41 additions and 4 deletions
|
@ -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_references::goto_references;
|
||||
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 references::ReferencesMode;
|
||||
pub use rename::{can_rename, rename};
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::session::client::Client;
|
|||
use lsp_types::request::InlayHintRequest;
|
||||
use lsp_types::{InlayHintParams, Url};
|
||||
use ruff_db::source::{line_index, source_text};
|
||||
use ty_ide::inlay_hints;
|
||||
use ty_ide::{InlayHintContent, inlay_hints};
|
||||
use ty_project::ProjectDatabase;
|
||||
|
||||
pub(crate) struct InlayHintRequestHandler;
|
||||
|
@ -56,7 +56,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler {
|
|||
.position
|
||||
.to_position(&source, &index, snapshot.encoding()),
|
||||
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,
|
||||
padding_left: None,
|
||||
padding_right: None,
|
||||
|
@ -70,3 +70,10 @@ impl BackgroundDocumentRequestHandler 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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ foo(1)
|
|||
"character": 4
|
||||
},
|
||||
"label": "a=",
|
||||
"kind": 1
|
||||
"kind": 2
|
||||
}
|
||||
]
|
||||
"#);
|
||||
|
|
|
@ -455,6 +455,7 @@ impl Workspace {
|
|||
&source,
|
||||
self.position_encoding,
|
||||
),
|
||||
kind: hint.content.into(),
|
||||
})
|
||||
.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]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct InlayHint {
|
||||
|
@ -984,6 +1001,8 @@ pub struct InlayHint {
|
|||
pub markdown: String,
|
||||
|
||||
pub position: Position,
|
||||
|
||||
pub kind: InlayHintKind,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
type FileHandle,
|
||||
DocumentHighlight,
|
||||
DocumentHighlightKind,
|
||||
InlayHintKind,
|
||||
} from "ty_wasm";
|
||||
import { FileId, ReadonlyFiles } from "../Playground";
|
||||
import { isPythonFile } from "./Files";
|
||||
|
@ -405,6 +406,15 @@ class PlaygroundServer
|
|||
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 {
|
||||
dispose: () => {},
|
||||
hints: inlayHints.map((hint) => ({
|
||||
|
@ -413,6 +423,7 @@ class PlaygroundServer
|
|||
lineNumber: hint.position.line,
|
||||
column: hint.position.column,
|
||||
},
|
||||
kind: mapInlayHintKind(hint.kind),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue