diff options
Diffstat (limited to 'support/texlab/src/features/hover.rs')
-rw-r--r-- | support/texlab/src/features/hover.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/support/texlab/src/features/hover.rs b/support/texlab/src/features/hover.rs index 7d349de0a3..8663f6256d 100644 --- a/support/texlab/src/features/hover.rs +++ b/support/texlab/src/features/hover.rs @@ -5,9 +5,13 @@ mod field; mod label; mod string_ref; -use lsp_types::{Hover, HoverParams}; +use lsp_types::{Hover, HoverContents, HoverParams, MarkupContent, MarkupKind}; +use rowan::TextRange; -use crate::features::{cursor::CursorContext, hover::citation::find_citation_hover}; +use crate::{ + features::{cursor::CursorContext, hover::citation::find_citation_hover}, + LineIndexExt, +}; use self::{ component::find_component_hover, entry_type::find_entry_type_hover, field::find_field_hover, @@ -19,10 +23,31 @@ use super::FeatureRequest; pub fn find_hover(request: FeatureRequest<HoverParams>) -> Option<Hover> { let context = CursorContext::new(request); log::debug!("[Hover] Cursor: {:?}", context.cursor); - find_label_hover(&context) + let result = find_label_hover(&context) .or_else(|| find_citation_hover(&context)) .or_else(|| find_component_hover(&context)) .or_else(|| find_string_reference_hover(&context)) .or_else(|| find_field_hover(&context)) - .or_else(|| find_entry_type_hover(&context)) + .or_else(|| find_entry_type_hover(&context))?; + + Some(Hover { + contents: HoverContents::Markup(MarkupContent { + kind: result.value_kind, + value: result.value, + }), + range: Some( + context + .request + .main_document() + .line_index + .line_col_lsp_range(result.range), + ), + }) +} + +#[derive(Debug, Clone)] +struct HoverResult { + range: TextRange, + value: String, + value_kind: MarkupKind, } |