diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index c54990e8ec752..a9206f891477d 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,5 +1,5 @@ use crate::compositor::{Component, Context, Event, EventResult}; -use helix_view::{apply_transaction, editor::CompleteAction, ViewId}; +use helix_view::{apply_transaction, editor::CompleteAction, theme::Modifier, Theme, ViewId}; use tui::buffer::Buffer as Surface; use tui::text::Spans; @@ -37,41 +37,51 @@ impl menu::Item for CompletionItem { self.label.as_str().into() } - fn row(&self, _data: &Self::Data) -> menu::Row { + fn row(&self, _data: &Self::Data, theme: Option<&Theme>) -> menu::Row { + let (lsp_type_label, style) = match self.kind { + Some(lsp::CompletionItemKind::TEXT) => ("text", Some("ui.text")), + Some(lsp::CompletionItemKind::METHOD) => ("method", Some("function.method")), + Some(lsp::CompletionItemKind::FUNCTION) => ("function", Some("function")), + Some(lsp::CompletionItemKind::CONSTRUCTOR) => ("constructor", Some("constructor")), + Some(lsp::CompletionItemKind::FIELD) => ("field", Some("variable.other.member")), + Some(lsp::CompletionItemKind::VARIABLE) => ("variable", Some("variable")), + Some(lsp::CompletionItemKind::CLASS) => ("class", Some("type")), + Some(lsp::CompletionItemKind::INTERFACE) => ("interface", Some("type")), + Some(lsp::CompletionItemKind::MODULE) => ("module", Some("module")), + Some(lsp::CompletionItemKind::PROPERTY) => ("property", Some("attributes")), + Some(lsp::CompletionItemKind::UNIT) => ("unit", Some("constant")), + Some(lsp::CompletionItemKind::VALUE) => ("value", Some("string")), + Some(lsp::CompletionItemKind::ENUM) => ("enum", Some("type")), + Some(lsp::CompletionItemKind::KEYWORD) => ("keyword", Some("keyword")), + Some(lsp::CompletionItemKind::SNIPPET) => ("snippet", None), + Some(lsp::CompletionItemKind::COLOR) => ("color", None), + Some(lsp::CompletionItemKind::FILE) => ("file", None), + Some(lsp::CompletionItemKind::REFERENCE) => ("reference", None), + Some(lsp::CompletionItemKind::FOLDER) => ("folder", None), + Some(lsp::CompletionItemKind::ENUM_MEMBER) => { + ("enum_member", Some("type.enum.variant")) + } + Some(lsp::CompletionItemKind::CONSTANT) => ("constant", Some("constant")), + Some(lsp::CompletionItemKind::STRUCT) => ("struct", Some("type")), + Some(lsp::CompletionItemKind::EVENT) => ("event", None), + Some(lsp::CompletionItemKind::OPERATOR) => ("operator", Some("operator")), + Some(lsp::CompletionItemKind::TYPE_PARAMETER) => { + ("type_param", Some("function.parameter")) + } + Some(kind) => unimplemented!("{:?}", kind), + None => ("", None), + }; + let mut lsp_type_style = theme + .zip(style) + .map(|(theme, style)| theme.get(style)) + .unwrap_or_default() + .remove_modifier(Modifier::all()) + .add_modifier(Modifier::ITALIC); + lsp_type_style.bg = None; + menu::Row::new(vec![ menu::Cell::from(self.label.as_str()), - menu::Cell::from(match self.kind { - Some(lsp::CompletionItemKind::TEXT) => "text", - Some(lsp::CompletionItemKind::METHOD) => "method", - Some(lsp::CompletionItemKind::FUNCTION) => "function", - Some(lsp::CompletionItemKind::CONSTRUCTOR) => "constructor", - Some(lsp::CompletionItemKind::FIELD) => "field", - Some(lsp::CompletionItemKind::VARIABLE) => "variable", - Some(lsp::CompletionItemKind::CLASS) => "class", - Some(lsp::CompletionItemKind::INTERFACE) => "interface", - Some(lsp::CompletionItemKind::MODULE) => "module", - Some(lsp::CompletionItemKind::PROPERTY) => "property", - Some(lsp::CompletionItemKind::UNIT) => "unit", - Some(lsp::CompletionItemKind::VALUE) => "value", - Some(lsp::CompletionItemKind::ENUM) => "enum", - Some(lsp::CompletionItemKind::KEYWORD) => "keyword", - Some(lsp::CompletionItemKind::SNIPPET) => "snippet", - Some(lsp::CompletionItemKind::COLOR) => "color", - Some(lsp::CompletionItemKind::FILE) => "file", - Some(lsp::CompletionItemKind::REFERENCE) => "reference", - Some(lsp::CompletionItemKind::FOLDER) => "folder", - Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member", - Some(lsp::CompletionItemKind::CONSTANT) => "constant", - Some(lsp::CompletionItemKind::STRUCT) => "struct", - Some(lsp::CompletionItemKind::EVENT) => "event", - Some(lsp::CompletionItemKind::OPERATOR) => "operator", - Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param", - Some(kind) => { - log::error!("Received unknown completion item kind: {:?}", kind); - "" - } - None => "", - }), + menu::Cell::from(lsp_type_label).style(lsp_type_style), // self.detail.as_deref().unwrap_or("") // self.label_details // .as_ref() diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index b9c1f9ded2e10..65d3867f17532 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -11,7 +11,7 @@ pub use tui::widgets::{Cell, Row}; use fuzzy_matcher::skim::SkimMatcherV2 as Matcher; use fuzzy_matcher::FuzzyMatcher; -use helix_view::{graphics::Rect, Editor}; +use helix_view::{graphics::Rect, Editor, Theme}; use tui::layout::Constraint; pub trait Item { @@ -30,7 +30,7 @@ pub trait Item { label.into() } - fn row(&self, data: &Self::Data) -> Row { + fn row(&self, data: &Self::Data, _theme: Option<&Theme>) -> Row { Row::new(vec![Cell::from(self.label(data))]) } } @@ -144,10 +144,10 @@ impl Menu { let n = self .options .first() - .map(|option| option.row(&self.editor_data).cells.len()) + .map(|option| option.row(&self.editor_data, None).cells.len()) .unwrap_or_default(); let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| { - let row = option.row(&self.editor_data); + let row = option.row(&self.editor_data, None); // maintain max for each column for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) { let width = cell.content.width(); @@ -331,7 +331,9 @@ impl Component for Menu { (a + b - 1) / b } - let rows = options.iter().map(|option| option.row(&self.editor_data)); + let rows = options + .iter() + .map(|option| option.row(&self.editor_data, Some(theme))); let table = Table::new(rows) .style(style) .highlight_style(selected)