From b2b171b7a8dac17e8be7e714812c8bbfcd0bd772 Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Mon, 24 Jun 2024 19:31:25 -0400 Subject: [PATCH] fix: resolve #129 --- src/config.rs | 2 ++ src/hover.rs | 12 +++++++++++- src/main.rs | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3bc34167..fd9bac3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ pub struct Settings { pub references_in_codeblocks: bool, pub include_md_extension_md_link: bool, pub include_md_extension_wikilink: bool, + pub hover: bool, } impl Settings { @@ -61,6 +62,7 @@ impl Settings { .set_default("references_in_codeblocks", true)? .set_default("include_md_extension_md_link", false)? .set_default("include_md_extension_wikilink", false)? + .set_default("hover", true)? .set_override_option( "semantic_tokens", capabilities.text_document.as_ref().and_then(|it| { diff --git a/src/hover.rs b/src/hover.rs index e4ccd492..d4b0f42c 100644 --- a/src/hover.rs +++ b/src/hover.rs @@ -3,11 +3,21 @@ use std::path::Path; use tower_lsp::lsp_types::{Hover, HoverContents, HoverParams}; use crate::{ + config::Settings, ui::{preview_reference, preview_referenceable}, vault::Vault, }; -pub fn hover(vault: &Vault, params: &HoverParams, path: &Path) -> Option { +pub fn hover( + vault: &Vault, + params: &HoverParams, + path: &Path, + settings: &Settings, +) -> Option { + if settings.hover == false { + return None; + } + let cursor_position = params.text_document_position_params.position; match ( diff --git a/src/main.rs b/src/main.rs index 8b8b1a59..3d35b302 100644 --- a/src/main.rs +++ b/src/main.rs @@ -602,9 +602,10 @@ impl LanguageServer for Backend { } async fn hover(&self, params: HoverParams) -> Result> { + let settings = self.bind_settings(|settings| Ok(settings.clone())).await?; self.bind_vault(|vault| { let path = params_path!(params.text_document_position_params)?; - Ok(hover::hover(vault, ¶ms, &path)) + Ok(hover::hover(vault, ¶ms, &path, &settings)) }) .await }