Skip to content
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

Show Icons for Completion Kind #10056

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/icons/completion_icons/class.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/constant.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/constructor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/enum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/event.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/field_or_property.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/function.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/interface.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/keyword.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/method.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/module.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/operator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/reference.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/snippet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/struct.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/completion_icons/type_parameter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/unit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/value.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/completion_icons/variable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use language::{
CodeLabel, Completion, CursorShape, Diagnostic, Documentation, IndentKind, IndentSize,
Language, OffsetRangeExt, Point, Selection, SelectionGoal, TransactionId,
};
use lsp::{DiagnosticSeverity, LanguageServerId};
use lsp::{CompletionItemKind, DiagnosticSeverity, LanguageServerId};
use mouse_context_menu::MouseContextMenu;
use movement::TextLayoutDetails;
use multi_buffer::ToOffsetUtf16;
Expand Down Expand Up @@ -965,6 +965,11 @@ impl CompletionsMenu {
documentation,
max_completion_len,
);

let completion_kind_icon =
completion_kind_icon(&completion.lsp_completion.kind)
.color(Color::Muted);

div()
.min_w(px(widest_completion_pixels + padding_width))
.max_w(max_completion_len + px(padding_width))
Expand All @@ -983,7 +988,13 @@ impl CompletionsMenu {
task.detach_and_log_err(cx)
}
}))
.child(h_flex().overflow_hidden().child(completion_label))
.child(
h_flex()
.overflow_hidden()
.gap_1()
.child(completion_kind_icon)
.child(completion_label),
)
.end_slot(documentation_label),
)
})
Expand Down Expand Up @@ -1397,6 +1408,37 @@ impl CompletionsMenu {
}
}

fn completion_kind_icon(completion_kind: &Option<CompletionItemKind>) -> Icon {
match completion_kind {
Some(CompletionItemKind::REFERENCE) => Icon::new(IconName::Reference),
Some(CompletionItemKind::METHOD) => Icon::new(IconName::Method),
Some(CompletionItemKind::FUNCTION) => Icon::new(IconName::Function),
Some(CompletionItemKind::CONSTRUCTOR) => Icon::new(IconName::Constructor),
Some(CompletionItemKind::FIELD) => Icon::new(IconName::Field),
Some(CompletionItemKind::VARIABLE) => Icon::new(IconName::Variable),
Some(CompletionItemKind::CLASS) => Icon::new(IconName::Class),
Some(CompletionItemKind::INTERFACE) => Icon::new(IconName::Interface),
Some(CompletionItemKind::MODULE) => Icon::new(IconName::Module),
Some(CompletionItemKind::PROPERTY) => Icon::new(IconName::Property),
Some(CompletionItemKind::UNIT) => Icon::new(IconName::Unit),
Some(CompletionItemKind::VALUE) => Icon::new(IconName::Value),
Some(CompletionItemKind::ENUM) => Icon::new(IconName::Enum),
Some(CompletionItemKind::KEYWORD) => Icon::new(IconName::Keyword),
Some(CompletionItemKind::SNIPPET) => Icon::new(IconName::Snippet),
Some(CompletionItemKind::COLOR) => Icon::new(IconName::Color),
Some(CompletionItemKind::FILE) => Icon::new(IconName::File),
Some(CompletionItemKind::FOLDER) => Icon::new(IconName::Folder),
Some(CompletionItemKind::ENUM_MEMBER) => Icon::new(IconName::Enum),
Some(CompletionItemKind::CONSTANT) => Icon::new(IconName::Constant),
Some(CompletionItemKind::STRUCT) => Icon::new(IconName::Struct),
Some(CompletionItemKind::EVENT) => Icon::new(IconName::Event),
Some(CompletionItemKind::OPERATOR) => Icon::new(IconName::Operator),
Some(CompletionItemKind::TYPE_PARAMETER) => Icon::new(IconName::TypeParameter),
Some(CompletionItemKind::TEXT) => Icon::new(IconName::Text),
_ => Icon::new(IconName::Text),
}
}

#[derive(Clone)]
struct CodeActionsMenu {
actions: Arc<[CodeAction]>,
Expand Down
48 changes: 48 additions & 0 deletions crates/ui/src/components/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ pub enum IconName {
WholeWord,
XCircle,
ZedXCopilot,
Text,
Method,
Function,
Constructor,
Field,
Variable,
Class,
Interface,
Module,
Property,
Unit,
Value,
Enum,
Keyword,
Snippet,
Color,
FileKind,
Reference,
FolderKind,
Constant,
Struct,
Event,
Operator,
TypeParameter,
}

impl IconName {
Expand Down Expand Up @@ -212,6 +236,30 @@ impl IconName {
IconName::WholeWord => "icons/word_search.svg",
IconName::XCircle => "icons/error.svg",
IconName::ZedXCopilot => "icons/zed_x_copilot.svg",
IconName::Text => "icons/completion_icons/text.svg",
IconName::Unit => "icons/completion_icons/unit.svg",
IconName::Value => "icons/completion_icons/value.svg",
IconName::Enum => "icons/completion_icons/enum.svg",
IconName::Keyword => "icons/completion_icons/keyword.svg",
IconName::Snippet => "icons/completion_icons/snippet.svg",
IconName::Color => "icons/completion_icons/color.svg",
IconName::FileKind => "icons/completion_icons/file.svg",
IconName::Reference => "icons/completion_icons/reference.svg",
IconName::FolderKind => "icons/completion_icons/folder.svg",
IconName::Constant => "icons/completion_icons/constant.svg",
IconName::Struct => "icons/completion_icons/struct.svg",
IconName::Event => "icons/completion_icons/event.svg",
IconName::Operator => "icons/completion_icons/operator.svg",
IconName::Field => "icons/completion_icons/field_or_property.svg",
IconName::Variable => "icons/completion_icons/variable.svg",
IconName::Class => "icons/completion_icons/class.svg",
IconName::Interface => "icons/completion_icons/interface.svg",
IconName::Module => "icons/completion_icons/module.svg",
IconName::Property => "icons/completion_icons/field_or_property.svg",
IconName::Method => "icons/completion_icons/method.svg",
IconName::Function => "icons/completion_icons/function.svg",
IconName::Constructor => "icons/completion_icons/constructor.svg",
IconName::TypeParameter => "icons/completion_icons/type_parameter.svg",
}
}
}
Expand Down
Loading