From 2bebc5042e5e50a6cd7691f3590184c4499376a7 Mon Sep 17 00:00:00 2001 From: Matouš Dzivjak Date: Mon, 13 Feb 2023 03:44:31 +0100 Subject: feat(ui): deprecated completions (#5932) * feat(ui): deprecated completions Mark deprecated completions using strike-through (CROSSED_OUT modifier). The deprection information is taken either from the `deprecated` field of the completion item or from the completion tags. The field seems to be the older way of passing the deprecated information and it was already marked as deprecated for Symbol. In completion item the field is still valid but it seems that the LSP is moving in the general direction of using tags for this kind of information and as such relying on tags as well seems reasonable and future-proof. --- helix-term/src/ui/completion.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index ac434894..3e2f2aea 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,6 +1,10 @@ use crate::compositor::{Component, Context, Event, EventResult}; -use helix_view::{editor::CompleteAction, ViewId}; -use tui::buffer::Buffer as Surface; +use helix_view::{ + editor::CompleteAction, + theme::{Modifier, Style}, + ViewId, +}; +use tui::{buffer::Buffer as Surface, text::Span}; use std::borrow::Cow; @@ -33,8 +37,19 @@ impl menu::Item for CompletionItem { } fn format(&self, _data: &Self::Data) -> menu::Row { + let deprecated = self.deprecated.unwrap_or_default() + || self.tags.as_ref().map_or(false, |tags| { + tags.contains(&lsp::CompletionItemTag::DEPRECATED) + }); menu::Row::new(vec![ - menu::Cell::from(self.label.as_str()), + menu::Cell::from(Span::styled( + self.label.as_str(), + if deprecated { + Style::default().add_modifier(Modifier::CROSSED_OUT) + } else { + Style::default() + }, + )), menu::Cell::from(match self.kind { Some(lsp::CompletionItemKind::TEXT) => "text", Some(lsp::CompletionItemKind::METHOD) => "method", -- cgit v1.2.3-70-g09d2