Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 91833f1

Browse files
committed
feat: Implement inlay hint tooltips
1 parent 12d5343 commit 91833f1

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

crates/rust-analyzer/src/caps.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use lsp_types::{
44
CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DeclarationCapability,
55
DocumentOnTypeFormattingOptions, FileOperationFilter, FileOperationPattern,
66
FileOperationPatternKind, FileOperationRegistrationOptions, FoldingRangeProviderCapability,
7-
HoverProviderCapability, ImplementationProviderCapability, OneOf, RenameOptions, SaveOptions,
7+
HoverProviderCapability, ImplementationProviderCapability, InlayHintOptions,
8+
InlayHintServerCapabilities, OneOf, RenameOptions, SaveOptions,
89
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
910
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
1011
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
@@ -112,7 +113,12 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
112113
.into(),
113114
),
114115
moniker_provider: None,
115-
inlay_hint_provider: Some(OneOf::Left(true)),
116+
inlay_hint_provider: Some(OneOf::Right(InlayHintServerCapabilities::Options(
117+
InlayHintOptions {
118+
work_done_progress_options: Default::default(),
119+
resolve_provider: Some(true),
120+
},
121+
))),
116122
experimental: Some(json!({
117123
"externalDocs": true,
118124
"hoverRange": true,

crates/rust-analyzer/src/handlers.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,19 @@ pub(crate) fn handle_inlay_hints(
13481348
))
13491349
}
13501350

1351+
pub(crate) fn handle_inlay_hints_resolve(
1352+
_snap: GlobalStateSnapshot,
1353+
mut hint: InlayHint,
1354+
) -> Result<InlayHint> {
1355+
if let lsp_types::InlayHintLabel::String(s) = &hint.label {
1356+
hint.tooltip = Some(lsp_types::InlayHintTooltip::MarkupContent(lsp_types::MarkupContent {
1357+
kind: lsp_types::MarkupKind::PlainText,
1358+
value: s.clone(),
1359+
}));
1360+
}
1361+
Ok(hint)
1362+
}
1363+
13511364
pub(crate) fn handle_call_hierarchy_prepare(
13521365
snap: GlobalStateSnapshot,
13531366
params: CallHierarchyPrepareParams,

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ impl GlobalState {
612612
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
613613
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
614614
.on::<lsp_types::request::InlayHintRequest>(handlers::handle_inlay_hints)
615+
.on::<lsp_types::request::InlayHintResolveRequest>(handlers::handle_inlay_hints_resolve)
615616
.on::<lsp_types::request::Completion>(handlers::handle_completion)
616617
.on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)
617618
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)

0 commit comments

Comments
 (0)