|
1 | 1 | use crate::compositor::{Component, Context, Event, EventResult};
|
2 |
| -use helix_view::{apply_transaction, editor::CompleteAction, ViewId}; |
| 2 | +use helix_view::{apply_transaction, editor::CompleteAction, theme::Modifier, Theme, ViewId}; |
3 | 3 | use tui::buffer::Buffer as Surface;
|
4 | 4 | use tui::text::Spans;
|
5 | 5 |
|
@@ -37,41 +37,51 @@ impl menu::Item for CompletionItem {
|
37 | 37 | self.label.as_str().into()
|
38 | 38 | }
|
39 | 39 |
|
40 |
| - fn row(&self, _data: &Self::Data) -> menu::Row { |
| 40 | + fn row(&self, _data: &Self::Data, theme: Option<&Theme>) -> menu::Row { |
| 41 | + let (lsp_type_label, style) = match self.kind { |
| 42 | + Some(lsp::CompletionItemKind::TEXT) => ("text", Some("ui.text")), |
| 43 | + Some(lsp::CompletionItemKind::METHOD) => ("method", Some("function.method")), |
| 44 | + Some(lsp::CompletionItemKind::FUNCTION) => ("function", Some("function")), |
| 45 | + Some(lsp::CompletionItemKind::CONSTRUCTOR) => ("constructor", Some("constructor")), |
| 46 | + Some(lsp::CompletionItemKind::FIELD) => ("field", Some("variable.other.member")), |
| 47 | + Some(lsp::CompletionItemKind::VARIABLE) => ("variable", Some("variable")), |
| 48 | + Some(lsp::CompletionItemKind::CLASS) => ("class", Some("type")), |
| 49 | + Some(lsp::CompletionItemKind::INTERFACE) => ("interface", Some("type")), |
| 50 | + Some(lsp::CompletionItemKind::MODULE) => ("module", Some("module")), |
| 51 | + Some(lsp::CompletionItemKind::PROPERTY) => ("property", Some("attributes")), |
| 52 | + Some(lsp::CompletionItemKind::UNIT) => ("unit", Some("constant")), |
| 53 | + Some(lsp::CompletionItemKind::VALUE) => ("value", Some("string")), |
| 54 | + Some(lsp::CompletionItemKind::ENUM) => ("enum", Some("type")), |
| 55 | + Some(lsp::CompletionItemKind::KEYWORD) => ("keyword", Some("keyword")), |
| 56 | + Some(lsp::CompletionItemKind::SNIPPET) => ("snippet", None), |
| 57 | + Some(lsp::CompletionItemKind::COLOR) => ("color", None), |
| 58 | + Some(lsp::CompletionItemKind::FILE) => ("file", None), |
| 59 | + Some(lsp::CompletionItemKind::REFERENCE) => ("reference", None), |
| 60 | + Some(lsp::CompletionItemKind::FOLDER) => ("folder", None), |
| 61 | + Some(lsp::CompletionItemKind::ENUM_MEMBER) => { |
| 62 | + ("enum_member", Some("type.enum.variant")) |
| 63 | + } |
| 64 | + Some(lsp::CompletionItemKind::CONSTANT) => ("constant", Some("constant")), |
| 65 | + Some(lsp::CompletionItemKind::STRUCT) => ("struct", Some("type")), |
| 66 | + Some(lsp::CompletionItemKind::EVENT) => ("event", None), |
| 67 | + Some(lsp::CompletionItemKind::OPERATOR) => ("operator", Some("operator")), |
| 68 | + Some(lsp::CompletionItemKind::TYPE_PARAMETER) => { |
| 69 | + ("type_param", Some("function.parameter")) |
| 70 | + } |
| 71 | + Some(kind) => unimplemented!("{:?}", kind), |
| 72 | + None => ("", None), |
| 73 | + }; |
| 74 | + let mut lsp_type_style = theme |
| 75 | + .zip(style) |
| 76 | + .map(|(theme, style)| theme.get(style)) |
| 77 | + .unwrap_or_default() |
| 78 | + .remove_modifier(Modifier::all()) |
| 79 | + .add_modifier(Modifier::ITALIC); |
| 80 | + lsp_type_style.bg = None; |
| 81 | + |
41 | 82 | menu::Row::new(vec![
|
42 | 83 | menu::Cell::from(self.label.as_str()),
|
43 |
| - menu::Cell::from(match self.kind { |
44 |
| - Some(lsp::CompletionItemKind::TEXT) => "text", |
45 |
| - Some(lsp::CompletionItemKind::METHOD) => "method", |
46 |
| - Some(lsp::CompletionItemKind::FUNCTION) => "function", |
47 |
| - Some(lsp::CompletionItemKind::CONSTRUCTOR) => "constructor", |
48 |
| - Some(lsp::CompletionItemKind::FIELD) => "field", |
49 |
| - Some(lsp::CompletionItemKind::VARIABLE) => "variable", |
50 |
| - Some(lsp::CompletionItemKind::CLASS) => "class", |
51 |
| - Some(lsp::CompletionItemKind::INTERFACE) => "interface", |
52 |
| - Some(lsp::CompletionItemKind::MODULE) => "module", |
53 |
| - Some(lsp::CompletionItemKind::PROPERTY) => "property", |
54 |
| - Some(lsp::CompletionItemKind::UNIT) => "unit", |
55 |
| - Some(lsp::CompletionItemKind::VALUE) => "value", |
56 |
| - Some(lsp::CompletionItemKind::ENUM) => "enum", |
57 |
| - Some(lsp::CompletionItemKind::KEYWORD) => "keyword", |
58 |
| - Some(lsp::CompletionItemKind::SNIPPET) => "snippet", |
59 |
| - Some(lsp::CompletionItemKind::COLOR) => "color", |
60 |
| - Some(lsp::CompletionItemKind::FILE) => "file", |
61 |
| - Some(lsp::CompletionItemKind::REFERENCE) => "reference", |
62 |
| - Some(lsp::CompletionItemKind::FOLDER) => "folder", |
63 |
| - Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member", |
64 |
| - Some(lsp::CompletionItemKind::CONSTANT) => "constant", |
65 |
| - Some(lsp::CompletionItemKind::STRUCT) => "struct", |
66 |
| - Some(lsp::CompletionItemKind::EVENT) => "event", |
67 |
| - Some(lsp::CompletionItemKind::OPERATOR) => "operator", |
68 |
| - Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param", |
69 |
| - Some(kind) => { |
70 |
| - log::error!("Received unknown completion item kind: {:?}", kind); |
71 |
| - "" |
72 |
| - } |
73 |
| - None => "", |
74 |
| - }), |
| 84 | + menu::Cell::from(lsp_type_label).style(lsp_type_style), |
75 | 85 | // self.detail.as_deref().unwrap_or("")
|
76 | 86 | // self.label_details
|
77 | 87 | // .as_ref()
|
|
0 commit comments