From 41cb3fd7587f418ad18b6a3672211e0bfa304cfb Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 10 Jun 2019 03:28:53 +0800 Subject: Rename Description to ShortLabel --- crates/ra_ide_api/src/display.rs | 4 +- crates/ra_ide_api/src/display/description.rs | 92 ---------------------- crates/ra_ide_api/src/display/navigation_target.rs | 56 ++++++------- crates/ra_ide_api/src/display/short_label.rs | 92 ++++++++++++++++++++++ crates/ra_ide_api/src/goto_definition.rs | 22 +++--- 5 files changed, 133 insertions(+), 133 deletions(-) delete mode 100644 crates/ra_ide_api/src/display/description.rs create mode 100644 crates/ra_ide_api/src/display/short_label.rs (limited to 'crates') diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs index 313415610..7a8734a75 100644 --- a/crates/ra_ide_api/src/display.rs +++ b/crates/ra_ide_api/src/display.rs @@ -4,7 +4,7 @@ mod function_signature; mod navigation_target; mod structure; -mod description; +mod short_label; use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}}; @@ -12,7 +12,7 @@ pub use navigation_target::NavigationTarget; pub use structure::{StructureNode, file_structure}; pub use function_signature::FunctionSignature; -pub(crate) use description::Description; +pub(crate) use short_label::ShortLabel; pub(crate) fn function_label(node: &ast::FnDef) -> String { FunctionSignature::from(node).to_string() diff --git a/crates/ra_ide_api/src/display/description.rs b/crates/ra_ide_api/src/display/description.rs deleted file mode 100644 index 4f6b0a858..000000000 --- a/crates/ra_ide_api/src/display/description.rs +++ /dev/null @@ -1,92 +0,0 @@ -use ra_syntax::{ - ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner, AstNode}, -}; - -pub(crate) trait Description { - fn description(&self) -> Option; -} - -impl Description for ast::FnDef { - fn description(&self) -> Option { - Some(crate::display::function_label(self)) - } -} - -impl Description for ast::StructDef { - fn description(&self) -> Option { - description_from_node(self, "struct ") - } -} - -impl Description for ast::EnumDef { - fn description(&self) -> Option { - description_from_node(self, "enum ") - } -} - -impl Description for ast::TraitDef { - fn description(&self) -> Option { - description_from_node(self, "trait ") - } -} - -impl Description for ast::Module { - fn description(&self) -> Option { - description_from_node(self, "mod ") - } -} - -impl Description for ast::TypeAliasDef { - fn description(&self) -> Option { - description_from_node(self, "type ") - } -} - -impl Description for ast::ConstDef { - fn description(&self) -> Option { - description_from_ascribed_node(self, "const ") - } -} - -impl Description for ast::StaticDef { - fn description(&self) -> Option { - description_from_ascribed_node(self, "static ") - } -} - -impl Description for ast::NamedFieldDef { - fn description(&self) -> Option { - description_from_ascribed_node(self, "") - } -} - -impl Description for ast::EnumVariant { - fn description(&self) -> Option { - Some(self.name()?.text().to_string()) - } -} - -fn description_from_ascribed_node(node: &T, prefix: &str) -> Option -where - T: NameOwner + VisibilityOwner + TypeAscriptionOwner, -{ - let mut string = description_from_node(node, prefix)?; - - if let Some(type_ref) = node.ascribed_type() { - string.push_str(": "); - type_ref.syntax().text().push_to(&mut string); - } - - Some(string) -} - -fn description_from_node(node: &T, label: &str) -> Option -where - T: NameOwner + VisibilityOwner, -{ - let mut string = - node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default(); - string.push_str(label); - string.push_str(node.name()?.text().as_str()); - Some(string) -} diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index f441ae943..9b17d6adc 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -8,7 +8,7 @@ use ra_syntax::{ use hir::{ModuleSource, FieldSource, ImplItem}; use crate::{FileSymbol, db::RootDatabase}; -use super::description::Description; +use super::short_label::ShortLabel; /// `NavigationTarget` represents and element in the editor's UI which you can /// click on to navigate to a particular piece of code. @@ -142,7 +142,7 @@ impl NavigationTarget { None, node.syntax(), node.doc_comment_text(), - node.description(), + node.short_label(), ), } } @@ -157,7 +157,7 @@ impl NavigationTarget { None, source.syntax(), source.doc_comment_text(), - source.description(), + source.short_label(), ); } NavigationTarget::from_module(db, module) @@ -169,7 +169,7 @@ impl NavigationTarget { file_id.original_file(db), &*fn_def, fn_def.doc_comment_text(), - fn_def.description(), + fn_def.short_label(), ) } @@ -178,7 +178,7 @@ impl NavigationTarget { let file_id = file_id.original_file(db); match field { FieldSource::Named(it) => { - NavigationTarget::from_named(file_id, &*it, it.doc_comment_text(), it.description()) + NavigationTarget::from_named(file_id, &*it, it.doc_comment_text(), it.short_label()) } FieldSource::Pos(it) => { NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax(), None, None) @@ -194,7 +194,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::AdtDef::Union(s) => { @@ -203,7 +203,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::AdtDef::Enum(s) => { @@ -212,7 +212,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } } @@ -231,7 +231,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::Union(s) => { @@ -240,7 +240,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::Const(s) => { @@ -249,7 +249,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::Static(s) => { @@ -258,7 +258,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::Enum(e) => { @@ -267,7 +267,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::EnumVariant(var) => { @@ -276,7 +276,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::Trait(e) => { @@ -285,7 +285,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::TypeAlias(e) => { @@ -294,7 +294,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } hir::ModuleDef::BuiltinType(..) => { @@ -328,7 +328,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } ImplItem::TypeAlias(a) => { @@ -337,7 +337,7 @@ impl NavigationTarget { file_id.original_file(db), &*node, node.doc_comment_text(), - node.description(), + node.short_label(), ) } } @@ -446,15 +446,15 @@ fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option Option; +} + +impl ShortLabel for ast::FnDef { + fn short_label(&self) -> Option { + Some(crate::display::function_label(self)) + } +} + +impl ShortLabel for ast::StructDef { + fn short_label(&self) -> Option { + short_label_from_node(self, "struct ") + } +} + +impl ShortLabel for ast::EnumDef { + fn short_label(&self) -> Option { + short_label_from_node(self, "enum ") + } +} + +impl ShortLabel for ast::TraitDef { + fn short_label(&self) -> Option { + 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::TypeAliasDef { + fn short_label(&self) -> Option { + short_label_from_node(self, "type ") + } +} + +impl ShortLabel for ast::ConstDef { + fn short_label(&self) -> Option { + short_label_from_ascribed_node(self, "const ") + } +} + +impl ShortLabel for ast::StaticDef { + fn short_label(&self) -> Option { + short_label_from_ascribed_node(self, "static ") + } +} + +impl ShortLabel for ast::NamedFieldDef { + fn short_label(&self) -> Option { + short_label_from_ascribed_node(self, "") + } +} + +impl ShortLabel for ast::EnumVariant { + fn short_label(&self) -> Option { + Some(self.name()?.text().to_string()) + } +} + +fn short_label_from_ascribed_node(node: &T, prefix: &str) -> Option +where + T: NameOwner + VisibilityOwner + TypeAscriptionOwner, +{ + let mut string = short_label_from_node(node, prefix)?; + + if let Some(type_ref) = node.ascribed_type() { + string.push_str(": "); + type_ref.syntax().text().push_to(&mut string); + } + + Some(string) +} + +fn short_label_from_node(node: &T, label: &str) -> Option +where + T: NameOwner + VisibilityOwner, +{ + let mut string = + node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default(); + string.push_str(label); + string.push_str(node.name()?.text().as_str()); + Some(string) +} diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 359fc2da1..325a5a4f3 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -13,7 +13,7 @@ use crate::{ db::RootDatabase, RangeInfo, name_ref_kind::{NameRefKind::*, classify_name_ref}, - display::Description, + display::ShortLabel, }; pub(crate) fn goto_definition( @@ -116,34 +116,34 @@ pub(crate) fn name_definition( fn named_target(file_id: FileId, node: &SyntaxNode) -> Option { visitor() .visit(|node: &ast::StructDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::EnumDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::EnumVariant| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::FnDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::TypeAliasDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::ConstDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::StaticDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::TraitDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::NamedFieldDef| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::Module| { - NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) + NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) }) .visit(|node: &ast::MacroCall| { NavigationTarget::from_named(file_id, node, node.doc_comment_text(), None) -- cgit v1.2.3