Skip to content

Commit

Permalink
feat(ui): deprecated completions (#5932)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
matoous authored Feb 13, 2023
1 parent 8b09b00 commit 2bebc50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ impl Client {
],
}),
insert_replace_support: Some(true),
deprecated_support: Some(true),
tag_support: Some(lsp::TagSupport {
value_set: vec![lsp::CompletionItemTag::DEPRECATED],
}),
..Default::default()
}),
completion_item_kind: Some(lsp::CompletionItemKindCapability {
Expand Down
21 changes: 18 additions & 3 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2bebc50

Please sign in to comment.