From 70d452db3e0890e13f8ce9d88b861fa39fb6d95c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 1 Feb 2025 21:24:25 -0500 Subject: [PATCH] core: Make completion item documentation optional Path completion items always have documentation but future core (i.e. non-LSP) completions may not always have documentation - for example word completion from the current buffer. --- helix-core/src/completion.rs | 2 +- helix-term/src/handlers/completion/path.rs | 2 +- helix-term/src/ui/completion.rs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/helix-core/src/completion.rs b/helix-core/src/completion.rs index c13b440c0c84..29c86b7380a2 100644 --- a/helix-core/src/completion.rs +++ b/helix-core/src/completion.rs @@ -8,7 +8,7 @@ pub struct CompletionItem { pub label: Cow<'static, str>, pub kind: Cow<'static, str>, /// Containing Markdown - pub documentation: String, + pub documentation: Option, pub provider: CompletionProvider, } diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs index 21dc9c31f5b9..c2ffa5efa44e 100644 --- a/helix-term/src/handlers/completion/path.rs +++ b/helix-term/src/handlers/completion/path.rs @@ -113,7 +113,7 @@ pub(crate) fn path_completion( kind: Cow::Borrowed(kind), label: file_name.into(), transaction, - documentation, + documentation: Some(documentation), provider: CompletionProvider::Path, })) }) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index be78dd083218..e17762bfc5ef 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -523,7 +523,10 @@ impl Component for Completion { None => return, }, CompletionItem::Other(option) => { - markdowned(language, None, Some(&option.documentation)) + let Some(doc) = option.documentation.as_deref() else { + return; + }; + markdowned(language, None, Some(doc)) } };