feat: Implement inlay hint tooltips

This commit is contained in:
Lukas Wirth 2022-05-17 12:49:51 +02:00
parent 12d5343993
commit 91833f1974
3 changed files with 22 additions and 2 deletions

View File

@ -4,7 +4,8 @@
CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DeclarationCapability,
DocumentOnTypeFormattingOptions, FileOperationFilter, FileOperationPattern,
FileOperationPatternKind, FileOperationRegistrationOptions, FoldingRangeProviderCapability,
HoverProviderCapability, ImplementationProviderCapability, OneOf, RenameOptions, SaveOptions,
HoverProviderCapability, ImplementationProviderCapability, InlayHintOptions,
InlayHintServerCapabilities, OneOf, RenameOptions, SaveOptions,
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
@ -112,7 +113,12 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
.into(),
),
moniker_provider: None,
inlay_hint_provider: Some(OneOf::Left(true)),
inlay_hint_provider: Some(OneOf::Right(InlayHintServerCapabilities::Options(
InlayHintOptions {
work_done_progress_options: Default::default(),
resolve_provider: Some(true),
},
))),
experimental: Some(json!({
"externalDocs": true,
"hoverRange": true,

View File

@ -1348,6 +1348,19 @@ pub(crate) fn handle_inlay_hints(
))
}
pub(crate) fn handle_inlay_hints_resolve(
_snap: GlobalStateSnapshot,
mut hint: InlayHint,
) -> Result<InlayHint> {
if let lsp_types::InlayHintLabel::String(s) = &hint.label {
hint.tooltip = Some(lsp_types::InlayHintTooltip::MarkupContent(lsp_types::MarkupContent {
kind: lsp_types::MarkupKind::PlainText,
value: s.clone(),
}));
}
Ok(hint)
}
pub(crate) fn handle_call_hierarchy_prepare(
snap: GlobalStateSnapshot,
params: CallHierarchyPrepareParams,

View File

@ -612,6 +612,7 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()>
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
.on::<lsp_types::request::InlayHintRequest>(handlers::handle_inlay_hints)
.on::<lsp_types::request::InlayHintResolveRequest>(handlers::handle_inlay_hints_resolve)
.on::<lsp_types::request::Completion>(handlers::handle_completion)
.on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)