From 2f862cd6fe6c10343f6dec4c414419db88fac32e Mon Sep 17 00:00:00 2001 From: vsrs Date: Fri, 29 Oct 2021 18:22:48 +0300 Subject: [PATCH] Fix Plaintext textDocument/hover --- crates/rust-analyzer/src/cli/lsif.rs | 1 + crates/rust-analyzer/src/handlers.rs | 7 ++++++- crates/rust-analyzer/src/to_proto.rs | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs index f3b843dc088..f108b694c01 100644 --- a/crates/rust-analyzer/src/cli/lsif.rs +++ b/crates/rust-analyzer/src/cli/lsif.rs @@ -136,6 +136,7 @@ impl LsifManager<'_> { result: lsp_types::Hover { contents: lsp_types::HoverContents::Markup(to_proto::markup_content( hover.markup, + ide::HoverDocFormat::Markdown, )), range: None, }, diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index ba4b153cfc0..0ddddeca675 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -920,9 +920,14 @@ pub(crate) fn handle_hover( let line_index = snap.file_line_index(file_range.file_id)?; let range = to_proto::range(&line_index, info.range); + let markup_kind = + snap.config.hover().documentation.map_or(ide::HoverDocFormat::Markdown, |kind| kind); let hover = lsp_ext::Hover { hover: lsp_types::Hover { - contents: HoverContents::Markup(to_proto::markup_content(info.info.markup)), + contents: HoverContents::Markup(to_proto::markup_content( + info.info.markup, + markup_kind, + )), range: Some(range), }, actions: if snap.config.hover_actions().none() { diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index ea39f799b79..8e77df95982 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -1202,9 +1202,16 @@ pub(crate) fn reference_title(count: usize) -> String { } } -pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent { +pub(crate) fn markup_content( + markup: Markup, + kind: ide::HoverDocFormat, +) -> lsp_types::MarkupContent { + let kind = match kind { + ide::HoverDocFormat::Markdown => lsp_types::MarkupKind::Markdown, + ide::HoverDocFormat::PlainText => lsp_types::MarkupKind::PlainText, + }; let value = crate::markdown::format_docs(markup.as_str()); - lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value } + lsp_types::MarkupContent { kind, value } } pub(crate) fn rename_error(err: RenameError) -> crate::LspError {