-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completions: Add colors based on the LSP item kind #1905
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use helix_view::{ | |
document::SavePoint, | ||
editor::CompleteAction, | ||
theme::{Modifier, Style}, | ||
ViewId, | ||
Theme, ViewId, | ||
}; | ||
use tui::{buffer::Buffer as Surface, text::Span}; | ||
|
||
|
@@ -33,11 +33,57 @@ impl menu::Item for CompletionItem { | |
.into() | ||
} | ||
|
||
fn format(&self, _data: &Self::Data) -> menu::Row { | ||
// fn label(&self, _data: &Self::Data) -> Spans { | ||
// self.label.as_str().into() | ||
// } | ||
|
||
fn format(&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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we intentionally removing the modifier from the theme and hardcoding italics? What's the point of pulling in user themes if we're just going to ignore them? I personally can't stand italics in code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are pulling the theme to apply the colors. This is for the completions items, they should have a matching modifier, i.e. no bold but all in italic. Please have a look at the screenshots above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, in my opinion, we should just let the theme decide how to style the completion items here and not hard code style for the user. |
||
lsp_type_style.bg = None; | ||
|
||
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(Span::styled( | ||
self.label.as_str(), | ||
|
@@ -47,38 +93,7 @@ impl menu::Item for CompletionItem { | |
Style::default() | ||
}, | ||
)), | ||
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to remove this commented code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, this slipped through.