From 4628d94e749f05a12ca51548a2c9afa2cc44ea84 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 16 Mar 2021 15:44:31 +0100 Subject: Remove ShortLabel --- crates/ide/src/display/short_label.rs | 128 ---------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 crates/ide/src/display/short_label.rs (limited to 'crates/ide/src/display/short_label.rs') diff --git a/crates/ide/src/display/short_label.rs b/crates/ide/src/display/short_label.rs deleted file mode 100644 index 2df9266b4..000000000 --- a/crates/ide/src/display/short_label.rs +++ /dev/null @@ -1,128 +0,0 @@ -//! FIXME: write short doc here - -use stdx::format_to; -use syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; - -pub(crate) trait ShortLabel { - fn short_label(&self) -> Option; -} - -impl ShortLabel for ast::Fn { - fn short_label(&self) -> Option { - Some(crate::display::function_declaration(self)) - } -} - -impl ShortLabel for ast::Struct { - fn short_label(&self) -> Option { - short_label_from_node(self, "struct ") - } -} - -impl ShortLabel for ast::Union { - fn short_label(&self) -> Option { - short_label_from_node(self, "union ") - } -} - -impl ShortLabel for ast::Enum { - fn short_label(&self) -> Option { - short_label_from_node(self, "enum ") - } -} - -impl ShortLabel for ast::Trait { - fn short_label(&self) -> Option { - if self.unsafe_token().is_some() { - short_label_from_node(self, "unsafe trait ") - } else { - short_label_from_node(self, "trait ") - } - } -} - -impl ShortLabel for ast::Module { - fn short_label(&self) -> Option { - short_label_from_node(self, "mod ") - } -} - -impl ShortLabel for ast::SourceFile { - fn short_label(&self) -> Option { - None - } -} - -impl ShortLabel for ast::BlockExpr { - fn short_label(&self) -> Option { - None - } -} - -impl ShortLabel for ast::TypeAlias { - fn short_label(&self) -> Option { - let mut buf = short_label_from_node(self, "type ")?; - if let Some(type_ref) = self.ty() { - format_to!(buf, " = {}", type_ref.syntax()); - } - Some(buf) - } -} - -impl ShortLabel for ast::Const { - fn short_label(&self) -> Option { - short_label_from_ty(self, self.ty(), "const ") - } -} - -impl ShortLabel for ast::Static { - fn short_label(&self) -> Option { - short_label_from_ty(self, self.ty(), "static ") - } -} - -impl ShortLabel for ast::RecordField { - fn short_label(&self) -> Option { - short_label_from_ty(self, self.ty(), "") - } -} - -impl ShortLabel for ast::Variant { - fn short_label(&self) -> Option { - Some(self.name()?.text().to_string()) - } -} - -impl ShortLabel for ast::ConstParam { - fn short_label(&self) -> Option { - let mut buf = "const ".to_owned(); - buf.push_str(self.name()?.text()); - if let Some(type_ref) = self.ty() { - format_to!(buf, ": {}", type_ref.syntax()); - } - Some(buf) - } -} - -fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option -where - T: NameOwner + VisibilityOwner, -{ - let mut buf = short_label_from_node(node, prefix)?; - - if let Some(type_ref) = ty { - format_to!(buf, ": {}", type_ref.syntax()); - } - - Some(buf) -} - -fn short_label_from_node(node: &T, label: &str) -> Option -where - T: NameOwner + VisibilityOwner, -{ - let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default(); - buf.push_str(label); - buf.push_str(node.name()?.text()); - Some(buf) -} -- cgit v1.2.3