on master help sign in
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.

commit2bebc5042e5e50a6cd7691f3590184c4499376a7 authorMatouš Dzivjak <matousdzivjak@gmail.com> dateMon 13 Feb 2023, 03:44 (4 years ago) parent8b09b00
2 files changed+22−3
helix-lsp/src/client.rs+4 helix-term/src/ui/completion.rs+18−3
helix-lsp/src/client.rs+4
@@ -329,6 +329,10 @@ impl Client {
329329 ],
330330 }),
331331 insert_replace_support: Some(true),
332+ deprecated_support: Some(true),
333+ tag_support: Some(lsp::TagSupport {
334+ value_set: vec![lsp::CompletionItemTag::DEPRECATED],
335+ }),
332336 ..Default::default()
333337 }),
334338 completion_item_kind: Some(lsp::CompletionItemKindCapability {
helix-term/src/ui/completion.rs+18−3
@@ -1,6 +1,10 @@
11use crate::compositor::{Component, Context, Event, EventResult};
2−use helix_view::{editor::CompleteAction, ViewId};
3−use tui::buffer::Buffer as Surface;
2+use helix_view::{
3+ editor::CompleteAction,
4+ theme::{Modifier, Style},
5+ ViewId,
6+};
7+use tui::{buffer::Buffer as Surface, text::Span};
48
59use std::borrow::Cow;
610
@@ -33,8 +37,19 @@ impl menu::Item for CompletionItem {
3337 }
3438
3539 fn format(&self, _data: &Self::Data) -> menu::Row {
40+ let deprecated = self.deprecated.unwrap_or_default()
41+ || self.tags.as_ref().map_or(false, |tags| {
42+ tags.contains(&lsp::CompletionItemTag::DEPRECATED)
43+ });
3644 menu::Row::new(vec![
37− menu::Cell::from(self.label.as_str()),
45+ menu::Cell::from(Span::styled(
46+ self.label.as_str(),
47+ if deprecated {
48+ Style::default().add_modifier(Modifier::CROSSED_OUT)
49+ } else {
50+ Style::default()
51+ },
52+ )),
3853 menu::Cell::from(match self.kind {
3954 Some(lsp::CompletionItemKind::TEXT) => "text",
4055 Some(lsp::CompletionItemKind::METHOD) => "method",