From 4484908a867fc742104d6ffe63b865a411203276 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:03:08 +0200 Subject: Rewrite goto definition tests --- crates/ra_ide/src/display/navigation_target.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 0b52b01ab..02f55e5ba 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -64,6 +64,7 @@ impl NavigationTarget { self.file_id } + // TODO: inconsistent pub fn file_range(&self) -> FileRange { FileRange { file_id: self.file_id, range: self.full_range } } @@ -283,11 +284,13 @@ impl ToNav for hir::ImplDef { } else { original_range(db, src.as_ref().map(|it| it.syntax())) }; + let focus_range = + src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range); NavigationTarget::from_syntax( frange.file_id, "impl".into(), - None, + focus_range, frange.range, src.value.syntax().kind(), ) -- cgit v1.2.3 From 34072d53b683805f449bf106d16788f171ca3522 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:20:16 +0200 Subject: Rewrite goto implementation tests --- crates/ra_ide/src/display/navigation_target.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 02f55e5ba..f8a466304 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -279,13 +279,17 @@ impl ToNav for hir::Module { impl ToNav for hir::ImplDef { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); - let frange = if let Some(item) = self.is_builtin_derive(db) { + let derive_attr = self.is_builtin_derive(db); + let frange = if let Some(item) = &derive_attr { original_range(db, item.syntax()) } else { original_range(db, src.as_ref().map(|it| it.syntax())) }; - let focus_range = - src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range); + let focus_range = if derive_attr.is_some() { + None + } else { + src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range) + }; NavigationTarget::from_syntax( frange.file_id, -- cgit v1.2.3 From af7e300041b1af68e671446fe22d2b9e5d30f83d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:27:13 +0200 Subject: Remove confusing API --- crates/ra_ide/src/display/navigation_target.rs | 36 ++++++++++---------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index f8a466304..8bf2428ed 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -11,7 +11,7 @@ use ra_syntax::{ TextRange, }; -use crate::{FileRange, FileSymbol}; +use crate::FileSymbol; use super::short_label::ShortLabel; @@ -47,6 +47,19 @@ impl NavigationTarget { pub fn range(&self) -> TextRange { self.focus_range.unwrap_or(self.full_range) } + /// A "most interesting" range withing the `full_range`. + /// + /// Typically, `full_range` is the whole syntax node, + /// including doc comments, and `focus_range` is the range of the identifier. + pub fn focus_range(&self) -> Option { + self.focus_range + } + pub fn full_range(&self) -> TextRange { + self.full_range + } + pub fn file_id(&self) -> FileId { + self.file_id + } pub fn name(&self) -> &SmolStr { &self.name @@ -60,19 +73,6 @@ impl NavigationTarget { self.kind } - pub fn file_id(&self) -> FileId { - self.file_id - } - - // TODO: inconsistent - pub fn file_range(&self) -> FileRange { - FileRange { file_id: self.file_id, range: self.full_range } - } - - pub fn full_range(&self) -> TextRange { - self.full_range - } - pub fn docs(&self) -> Option<&str> { self.docs.as_deref() } @@ -81,14 +81,6 @@ impl NavigationTarget { self.description.as_deref() } - /// A "most interesting" range withing the `full_range`. - /// - /// Typically, `full_range` is the whole syntax node, - /// including doc comments, and `focus_range` is the range of the identifier. - pub fn focus_range(&self) -> Option { - self.focus_range - } - pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); if let Some(src) = module.declaration_source(db) { -- cgit v1.2.3 From 53e3a7aeb4a706a6ee84229f94719dd78432417c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 17:59:44 +0200 Subject: Update file structure tests --- crates/ra_ide/src/display/structure.rs | 428 +++++++++++++++++---------------- 1 file changed, 215 insertions(+), 213 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index aad5a8e4d..c22a5d17b 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -173,12 +173,19 @@ fn structure_node(node: &SyntaxNode) -> Option { #[cfg(test)] mod tests { + use expect::{expect, Expect}; + use super::*; - use insta::assert_debug_snapshot; + + fn check(ra_fixture: &str, expect: Expect) { + let file = SourceFile::parse(ra_fixture).ok().unwrap(); + let structure = file_structure(&file); + expect.assert_debug_eq(&structure) + } #[test] fn test_file_structure() { - let file = SourceFile::parse( + check( r#" struct Foo { x: i32 @@ -223,216 +230,211 @@ fn obsolete() {} #[deprecated(note = "for awhile")] fn very_obsolete() {} "#, - ) - .ok() - .unwrap(); - let structure = file_structure(&file); - assert_debug_snapshot!(structure, - @r###" - [ - StructureNode { - parent: None, - label: "Foo", - navigation_range: 8..11, - node_range: 1..26, - kind: STRUCT_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 0, - ), - label: "x", - navigation_range: 18..19, - node_range: 18..24, - kind: RECORD_FIELD_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "m", - navigation_range: 32..33, - node_range: 28..158, - kind: MODULE, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar1", - navigation_range: 43..47, - node_range: 40..52, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar2", - navigation_range: 60..64, - node_range: 57..81, - kind: FN_DEF, - detail: Some( - "fn(t: T) -> T", - ), - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar3", - navigation_range: 89..93, - node_range: 86..156, - kind: FN_DEF, - detail: Some( - "fn(a: A, b: B) -> Vec< u32 >", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "E", - navigation_range: 165..166, - node_range: 160..180, - kind: ENUM_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 6, - ), - label: "X", - navigation_range: 169..170, - node_range: 169..170, - kind: ENUM_VARIANT, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 6, - ), - label: "Y", - navigation_range: 172..173, - node_range: 172..178, - kind: ENUM_VARIANT, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "T", - navigation_range: 186..187, - node_range: 181..193, - kind: TYPE_ALIAS_DEF, - detail: Some( - "()", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "S", - navigation_range: 201..202, - node_range: 194..213, - kind: STATIC_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "C", - navigation_range: 220..221, - node_range: 214..232, - kind: CONST_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "impl E", - navigation_range: 239..240, - node_range: 234..243, - kind: IMPL_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "impl fmt::Debug for E", - navigation_range: 265..266, - node_range: 245..269, - kind: IMPL_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mc", - navigation_range: 284..286, - node_range: 271..303, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mcexp", - navigation_range: 334..339, - node_range: 305..356, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mcexp", - navigation_range: 387..392, - node_range: 358..409, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "obsolete", - navigation_range: 428..436, - node_range: 411..441, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: true, - }, - StructureNode { - parent: None, - label: "very_obsolete", - navigation_range: 481..494, - node_range: 443..499, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: true, - }, - ] - "### - ); + expect![[r#" + [ + StructureNode { + parent: None, + label: "Foo", + navigation_range: 8..11, + node_range: 1..26, + kind: STRUCT_DEF, + detail: None, + deprecated: false, + }, + StructureNode { + parent: Some( + 0, + ), + label: "x", + navigation_range: 18..19, + node_range: 18..24, + kind: RECORD_FIELD_DEF, + detail: Some( + "i32", + ), + deprecated: false, + }, + StructureNode { + parent: None, + label: "m", + navigation_range: 32..33, + node_range: 28..158, + kind: MODULE, + detail: None, + deprecated: false, + }, + StructureNode { + parent: Some( + 2, + ), + label: "bar1", + navigation_range: 43..47, + node_range: 40..52, + kind: FN_DEF, + detail: Some( + "fn()", + ), + deprecated: false, + }, + StructureNode { + parent: Some( + 2, + ), + label: "bar2", + navigation_range: 60..64, + node_range: 57..81, + kind: FN_DEF, + detail: Some( + "fn(t: T) -> T", + ), + deprecated: false, + }, + StructureNode { + parent: Some( + 2, + ), + label: "bar3", + navigation_range: 89..93, + node_range: 86..156, + kind: FN_DEF, + detail: Some( + "fn(a: A, b: B) -> Vec< u32 >", + ), + deprecated: false, + }, + StructureNode { + parent: None, + label: "E", + navigation_range: 165..166, + node_range: 160..180, + kind: ENUM_DEF, + detail: None, + deprecated: false, + }, + StructureNode { + parent: Some( + 6, + ), + label: "X", + navigation_range: 169..170, + node_range: 169..170, + kind: ENUM_VARIANT, + detail: None, + deprecated: false, + }, + StructureNode { + parent: Some( + 6, + ), + label: "Y", + navigation_range: 172..173, + node_range: 172..178, + kind: ENUM_VARIANT, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "T", + navigation_range: 186..187, + node_range: 181..193, + kind: TYPE_ALIAS_DEF, + detail: Some( + "()", + ), + deprecated: false, + }, + StructureNode { + parent: None, + label: "S", + navigation_range: 201..202, + node_range: 194..213, + kind: STATIC_DEF, + detail: Some( + "i32", + ), + deprecated: false, + }, + StructureNode { + parent: None, + label: "C", + navigation_range: 220..221, + node_range: 214..232, + kind: CONST_DEF, + detail: Some( + "i32", + ), + deprecated: false, + }, + StructureNode { + parent: None, + label: "impl E", + navigation_range: 239..240, + node_range: 234..243, + kind: IMPL_DEF, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "impl fmt::Debug for E", + navigation_range: 265..266, + node_range: 245..269, + kind: IMPL_DEF, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "mc", + navigation_range: 284..286, + node_range: 271..303, + kind: MACRO_CALL, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "mcexp", + navigation_range: 334..339, + node_range: 305..356, + kind: MACRO_CALL, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "mcexp", + navigation_range: 387..392, + node_range: 358..409, + kind: MACRO_CALL, + detail: None, + deprecated: false, + }, + StructureNode { + parent: None, + label: "obsolete", + navigation_range: 428..436, + node_range: 411..441, + kind: FN_DEF, + detail: Some( + "fn()", + ), + deprecated: true, + }, + StructureNode { + parent: None, + label: "very_obsolete", + navigation_range: 481..494, + node_range: 443..499, + kind: FN_DEF, + detail: Some( + "fn()", + ), + deprecated: true, + }, + ] + "#]], + ); } } -- cgit v1.2.3 From b34cdf7bf47c87290500a573756e719a2699cd3b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Jul 2020 22:48:56 +0200 Subject: Implementations lens for unions closes #4728 --- crates/ra_ide/src/display/structure.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index c22a5d17b..1f6a3febf 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -127,6 +127,7 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(it, Some(detail)) }, ast::StructDef(it) => decl(it), + ast::UnionDef(it) => decl(it), ast::EnumDef(it) => decl(it), ast::EnumVariant(it) => decl(it), ast::TraitDef(it) => decl(it), -- cgit v1.2.3 From 1d63b3efc918d8d72273b90935e4ddd51400be22 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 10:25:36 +0200 Subject: simplify --- crates/ra_ide/src/display/function_signature.rs | 107 +++++++++++------------- 1 file changed, 47 insertions(+), 60 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index a98264fb3..1d39544d3 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -61,15 +61,11 @@ pub struct FunctionQualifier { } impl FunctionSignature { - pub(crate) fn with_doc_opt(mut self, doc: Option) -> Self { - self.doc = doc; - self - } - pub(crate) fn from_hir(db: &RootDatabase, function: hir::Function) -> Self { - let doc = function.docs(db); let ast_node = function.source(db).value; - FunctionSignature::from(&ast_node).with_doc_opt(doc) + let mut res = FunctionSignature::from(&ast_node); + res.doc = function.docs(db); + res } pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option { @@ -93,24 +89,21 @@ impl FunctionSignature { params.push(raw_param); } - Some( - FunctionSignature { - kind: CallableKind::StructConstructor, - visibility: node.visibility().map(|n| n.syntax().text().to_string()), - // Do we need `const`? - qualifier: Default::default(), - name: node.name().map(|n| n.text().to_string()), - ret_type: node.name().map(|n| n.text().to_string()), - parameters: params, - parameter_names: vec![], - parameter_types, - generic_parameters: generic_parameters(&node), - where_predicates: where_predicates(&node), - doc: None, - has_self_param: false, - } - .with_doc_opt(st.docs(db)), - ) + Some(FunctionSignature { + kind: CallableKind::StructConstructor, + visibility: node.visibility().map(|n| n.syntax().text().to_string()), + // Do we need `const`? + qualifier: Default::default(), + name: node.name().map(|n| n.text().to_string()), + ret_type: node.name().map(|n| n.text().to_string()), + parameters: params, + parameter_names: vec![], + parameter_types, + generic_parameters: generic_parameters(&node), + where_predicates: where_predicates(&node), + doc: st.docs(db), + has_self_param: false, + }) } pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) -> Option { @@ -140,24 +133,21 @@ impl FunctionSignature { params.push(format!("{}: {}", name, ty.display(db))); } - Some( - FunctionSignature { - kind: CallableKind::VariantConstructor, - visibility: None, - // Do we need `const`? - qualifier: Default::default(), - name: Some(name), - ret_type: None, - parameters: params, - parameter_names: vec![], - parameter_types, - generic_parameters: vec![], - where_predicates: vec![], - doc: None, - has_self_param: false, - } - .with_doc_opt(variant.docs(db)), - ) + Some(FunctionSignature { + kind: CallableKind::VariantConstructor, + visibility: None, + // Do we need `const`? + qualifier: Default::default(), + name: Some(name), + ret_type: None, + parameters: params, + parameter_names: vec![], + parameter_types, + generic_parameters: vec![], + where_predicates: vec![], + doc: variant.docs(db), + has_self_param: false, + }) } pub(crate) fn from_macro(db: &RootDatabase, macro_def: hir::MacroDef) -> Option { @@ -165,23 +155,20 @@ impl FunctionSignature { let params = vec![]; - Some( - FunctionSignature { - kind: CallableKind::Macro, - visibility: None, - qualifier: Default::default(), - name: node.name().map(|n| n.text().to_string()), - ret_type: None, - parameters: params, - parameter_names: vec![], - parameter_types: vec![], - generic_parameters: vec![], - where_predicates: vec![], - doc: None, - has_self_param: false, - } - .with_doc_opt(macro_def.docs(db)), - ) + Some(FunctionSignature { + kind: CallableKind::Macro, + visibility: None, + qualifier: Default::default(), + name: node.name().map(|n| n.text().to_string()), + ret_type: None, + parameters: params, + parameter_names: vec![], + parameter_types: vec![], + generic_parameters: vec![], + where_predicates: vec![], + doc: macro_def.docs(db), + has_self_param: false, + }) } } -- cgit v1.2.3 From ff0312fa32715ce42f134fd9f049c4df5956d042 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 13:00:56 +0200 Subject: Semantical call info --- crates/ra_ide/src/display/function_signature.rs | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 1d39544d3..709a85f65 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -149,27 +149,6 @@ impl FunctionSignature { has_self_param: false, }) } - - pub(crate) fn from_macro(db: &RootDatabase, macro_def: hir::MacroDef) -> Option { - let node: ast::MacroCall = macro_def.source(db).value; - - let params = vec![]; - - Some(FunctionSignature { - kind: CallableKind::Macro, - visibility: None, - qualifier: Default::default(), - name: node.name().map(|n| n.text().to_string()), - ret_type: None, - parameters: params, - parameter_names: vec![], - parameter_types: vec![], - generic_parameters: vec![], - where_predicates: vec![], - doc: macro_def.docs(db), - has_self_param: false, - }) - } } impl From<&'_ ast::FnDef> for FunctionSignature { -- cgit v1.2.3 From 29832b8c3db509dea8da9164e980ccac4bccf47d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 18:07:53 +0200 Subject: Reduce visibility --- crates/ra_ide/src/display/function_signature.rs | 40 ++++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 709a85f65..9b7220d1f 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -15,49 +15,48 @@ use stdx::{split_delim, SepBy}; use crate::display::{generic_parameters, where_predicates}; #[derive(Debug)] -pub enum CallableKind { +pub(crate) enum CallableKind { Function, StructConstructor, VariantConstructor, - Macro, } /// Contains information about a function signature #[derive(Debug)] -pub struct FunctionSignature { - pub kind: CallableKind, +pub(crate) struct FunctionSignature { + pub(crate) kind: CallableKind, /// Optional visibility - pub visibility: Option, + pub(crate) visibility: Option, /// Qualifiers like `async`, `unsafe`, ... - pub qualifier: FunctionQualifier, + pub(crate) qualifier: FunctionQualifier, /// Name of the function - pub name: Option, + pub(crate) name: Option, /// Documentation for the function - pub doc: Option, + pub(crate) doc: Option, /// Generic parameters - pub generic_parameters: Vec, + pub(crate) generic_parameters: Vec, /// Parameters of the function - pub parameters: Vec, + pub(crate) parameters: Vec, /// Parameter names of the function - pub parameter_names: Vec, + pub(crate) parameter_names: Vec, /// Parameter types of the function - pub parameter_types: Vec, + pub(crate) parameter_types: Vec, /// Optional return type - pub ret_type: Option, + pub(crate) ret_type: Option, /// Where predicates - pub where_predicates: Vec, + pub(crate) where_predicates: Vec, /// Self param presence - pub has_self_param: bool, + pub(crate) has_self_param: bool, } #[derive(Debug, Default)] -pub struct FunctionQualifier { +pub(crate) struct FunctionQualifier { // `async` and `const` are mutually exclusive. Do we need to enforcing it here? - pub is_async: bool, - pub is_const: bool, - pub is_unsafe: bool, + pub(crate) is_async: bool, + pub(crate) is_const: bool, + pub(crate) is_unsafe: bool, /// The string `extern ".."` - pub extern_abi: Option, + pub(crate) extern_abi: Option, } impl FunctionSignature { @@ -277,7 +276,6 @@ impl Display for FunctionSignature { CallableKind::Function => write!(f, "fn {}", name)?, CallableKind::StructConstructor => write!(f, "struct {}", name)?, CallableKind::VariantConstructor => write!(f, "{}", name)?, - CallableKind::Macro => write!(f, "{}!", name)?, } } -- cgit v1.2.3 From a4e9681c79095d6c10a851cfefe64cf1a3570ec5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 18:13:43 +0200 Subject: Better module structure --- crates/ra_ide/src/display/structure.rs | 441 --------------------------------- 1 file changed, 441 deletions(-) delete mode 100644 crates/ra_ide/src/display/structure.rs (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs deleted file mode 100644 index 1f6a3febf..000000000 --- a/crates/ra_ide/src/display/structure.rs +++ /dev/null @@ -1,441 +0,0 @@ -use ra_syntax::{ - ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, - match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, -}; - -#[derive(Debug, Clone)] -pub struct StructureNode { - pub parent: Option, - pub label: String, - pub navigation_range: TextRange, - pub node_range: TextRange, - pub kind: SyntaxKind, - pub detail: Option, - pub deprecated: bool, -} - -// Feature: File Structure -// -// Provides a tree of the symbols defined in the file. Can be used to -// -// * fuzzy search symbol in a file (super useful) -// * draw breadcrumbs to describe the context around the cursor -// * draw outline of the file -// -// |=== -// | Editor | Shortcut -// -// | VS Code | kbd:[Ctrl+Shift+O] -// |=== -pub fn file_structure(file: &SourceFile) -> Vec { - let mut res = Vec::new(); - let mut stack = Vec::new(); - - for event in file.syntax().preorder() { - match event { - WalkEvent::Enter(node) => { - if let Some(mut symbol) = structure_node(&node) { - symbol.parent = stack.last().copied(); - stack.push(res.len()); - res.push(symbol); - } - } - WalkEvent::Leave(node) => { - if structure_node(&node).is_some() { - stack.pop().unwrap(); - } - } - } - } - res -} - -fn structure_node(node: &SyntaxNode) -> Option { - fn decl(node: N) -> Option { - decl_with_detail(node, None) - } - - fn decl_with_ascription( - node: N, - ) -> Option { - let ty = node.ascribed_type(); - decl_with_type_ref(node, ty) - } - - fn decl_with_type_ref( - node: N, - type_ref: Option, - ) -> Option { - let detail = type_ref.map(|type_ref| { - let mut detail = String::new(); - collapse_ws(type_ref.syntax(), &mut detail); - detail - }); - decl_with_detail(node, detail) - } - - fn decl_with_detail( - node: N, - detail: Option, - ) -> Option { - let name = node.name()?; - - Some(StructureNode { - parent: None, - label: name.text().to_string(), - navigation_range: name.syntax().text_range(), - node_range: node.syntax().text_range(), - kind: node.syntax().kind(), - detail, - deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"), - }) - } - - fn collapse_ws(node: &SyntaxNode, output: &mut String) { - let mut can_insert_ws = false; - node.text().for_each_chunk(|chunk| { - for line in chunk.lines() { - let line = line.trim(); - if line.is_empty() { - if can_insert_ws { - output.push(' '); - can_insert_ws = false; - } - } else { - output.push_str(line); - can_insert_ws = true; - } - } - }) - } - - match_ast! { - match node { - ast::FnDef(it) => { - let mut detail = String::from("fn"); - if let Some(type_param_list) = it.type_param_list() { - collapse_ws(type_param_list.syntax(), &mut detail); - } - if let Some(param_list) = it.param_list() { - collapse_ws(param_list.syntax(), &mut detail); - } - if let Some(ret_type) = it.ret_type() { - detail.push_str(" "); - collapse_ws(ret_type.syntax(), &mut detail); - } - - decl_with_detail(it, Some(detail)) - }, - ast::StructDef(it) => decl(it), - ast::UnionDef(it) => decl(it), - ast::EnumDef(it) => decl(it), - ast::EnumVariant(it) => decl(it), - ast::TraitDef(it) => decl(it), - ast::Module(it) => decl(it), - ast::TypeAliasDef(it) => { - let ty = it.type_ref(); - decl_with_type_ref(it, ty) - }, - ast::RecordFieldDef(it) => decl_with_ascription(it), - ast::ConstDef(it) => decl_with_ascription(it), - ast::StaticDef(it) => decl_with_ascription(it), - ast::ImplDef(it) => { - let target_type = it.target_type()?; - let target_trait = it.target_trait(); - let label = match target_trait { - None => format!("impl {}", target_type.syntax().text()), - Some(t) => { - format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),) - } - }; - - let node = StructureNode { - parent: None, - label, - navigation_range: target_type.syntax().text_range(), - node_range: it.syntax().text_range(), - kind: it.syntax().kind(), - detail: None, - deprecated: false, - }; - Some(node) - }, - ast::MacroCall(it) => { - match it.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) { - Some(path_segment) if path_segment.text() == "macro_rules" - => decl(it), - _ => None, - } - }, - _ => None, - } - } -} - -#[cfg(test)] -mod tests { - use expect::{expect, Expect}; - - use super::*; - - fn check(ra_fixture: &str, expect: Expect) { - let file = SourceFile::parse(ra_fixture).ok().unwrap(); - let structure = file_structure(&file); - expect.assert_debug_eq(&structure) - } - - #[test] - fn test_file_structure() { - check( - r#" -struct Foo { - x: i32 -} - -mod m { - fn bar1() {} - fn bar2(t: T) -> T {} - fn bar3(a: A, - b: B) -> Vec< - u32 - > {} -} - -enum E { X, Y(i32) } -type T = (); -static S: i32 = 92; -const C: i32 = 92; - -impl E {} - -impl fmt::Debug for E {} - -macro_rules! mc { - () => {} -} - -#[macro_export] -macro_rules! mcexp { - () => {} -} - -/// Doc comment -macro_rules! mcexp { - () => {} -} - -#[deprecated] -fn obsolete() {} - -#[deprecated(note = "for awhile")] -fn very_obsolete() {} -"#, - expect![[r#" - [ - StructureNode { - parent: None, - label: "Foo", - navigation_range: 8..11, - node_range: 1..26, - kind: STRUCT_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 0, - ), - label: "x", - navigation_range: 18..19, - node_range: 18..24, - kind: RECORD_FIELD_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "m", - navigation_range: 32..33, - node_range: 28..158, - kind: MODULE, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar1", - navigation_range: 43..47, - node_range: 40..52, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar2", - navigation_range: 60..64, - node_range: 57..81, - kind: FN_DEF, - detail: Some( - "fn(t: T) -> T", - ), - deprecated: false, - }, - StructureNode { - parent: Some( - 2, - ), - label: "bar3", - navigation_range: 89..93, - node_range: 86..156, - kind: FN_DEF, - detail: Some( - "fn(a: A, b: B) -> Vec< u32 >", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "E", - navigation_range: 165..166, - node_range: 160..180, - kind: ENUM_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 6, - ), - label: "X", - navigation_range: 169..170, - node_range: 169..170, - kind: ENUM_VARIANT, - detail: None, - deprecated: false, - }, - StructureNode { - parent: Some( - 6, - ), - label: "Y", - navigation_range: 172..173, - node_range: 172..178, - kind: ENUM_VARIANT, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "T", - navigation_range: 186..187, - node_range: 181..193, - kind: TYPE_ALIAS_DEF, - detail: Some( - "()", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "S", - navigation_range: 201..202, - node_range: 194..213, - kind: STATIC_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "C", - navigation_range: 220..221, - node_range: 214..232, - kind: CONST_DEF, - detail: Some( - "i32", - ), - deprecated: false, - }, - StructureNode { - parent: None, - label: "impl E", - navigation_range: 239..240, - node_range: 234..243, - kind: IMPL_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "impl fmt::Debug for E", - navigation_range: 265..266, - node_range: 245..269, - kind: IMPL_DEF, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mc", - navigation_range: 284..286, - node_range: 271..303, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mcexp", - navigation_range: 334..339, - node_range: 305..356, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "mcexp", - navigation_range: 387..392, - node_range: 358..409, - kind: MACRO_CALL, - detail: None, - deprecated: false, - }, - StructureNode { - parent: None, - label: "obsolete", - navigation_range: 428..436, - node_range: 411..441, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: true, - }, - StructureNode { - parent: None, - label: "very_obsolete", - navigation_range: 481..494, - node_range: 443..499, - kind: FN_DEF, - detail: Some( - "fn()", - ), - deprecated: true, - }, - ] - "#]], - ); - } -} -- cgit v1.2.3 From 0265778e86f7e130a921ab6307cfdcc0ad953fe0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 21:32:20 +0200 Subject: Don't use function signature for Display --- crates/ra_ide/src/display/function_signature.rs | 56 +------------------------ 1 file changed, 2 insertions(+), 54 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 9b7220d1f..77551117b 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -2,15 +2,12 @@ // FIXME: this modules relies on strings and AST way too much, and it should be // rewritten (matklad 2020-05-07) -use std::{ - convert::From, - fmt::{self, Display}, -}; +use std::convert::From; use hir::{Docs, Documentation, HasSource, HirDisplay}; use ra_ide_db::RootDatabase; use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; -use stdx::{split_delim, SepBy}; +use stdx::split_delim; use crate::display::{generic_parameters, where_predicates}; @@ -247,52 +244,3 @@ impl From<&'_ ast::FnDef> for FunctionSignature { } } } - -impl Display for FunctionSignature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if let Some(t) = &self.visibility { - write!(f, "{} ", t)?; - } - - if self.qualifier.is_async { - write!(f, "async ")?; - } - - if self.qualifier.is_const { - write!(f, "const ")?; - } - - if self.qualifier.is_unsafe { - write!(f, "unsafe ")?; - } - - if let Some(extern_abi) = &self.qualifier.extern_abi { - // Keyword `extern` is included in the string. - write!(f, "{} ", extern_abi)?; - } - - if let Some(name) = &self.name { - match self.kind { - CallableKind::Function => write!(f, "fn {}", name)?, - CallableKind::StructConstructor => write!(f, "struct {}", name)?, - CallableKind::VariantConstructor => write!(f, "{}", name)?, - } - } - - if !self.generic_parameters.is_empty() { - write!(f, "{}", self.generic_parameters.iter().sep_by(", ").surround_with("<", ">"))?; - } - - write!(f, "{}", self.parameters.iter().sep_by(", ").surround_with("(", ")"))?; - - if let Some(t) = &self.ret_type { - write!(f, " -> {}", t)?; - } - - if !self.where_predicates.is_empty() { - write!(f, "\nwhere {}", self.where_predicates.iter().sep_by(",\n "))?; - } - - Ok(()) - } -} -- cgit v1.2.3 From edc0190f7a2a701ef7c8534b053070212798cd8b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 21:33:11 +0200 Subject: Rename --- crates/ra_ide/src/display/short_label.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index d37260e96..5588130a1 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -9,7 +9,7 @@ pub(crate) trait ShortLabel { impl ShortLabel for ast::FnDef { fn short_label(&self) -> Option { - Some(crate::display::function_label(self)) + Some(crate::display::function_declaration(self)) } } -- cgit v1.2.3 From a5ae8b8b92748e1b876002799d160136a7836212 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 21:51:44 +0200 Subject: Inlay hints use callables --- crates/ra_ide/src/display/function_signature.rs | 96 +------------------------ 1 file changed, 1 insertion(+), 95 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 77551117b..f6e11357f 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -4,8 +4,7 @@ // rewritten (matklad 2020-05-07) use std::convert::From; -use hir::{Docs, Documentation, HasSource, HirDisplay}; -use ra_ide_db::RootDatabase; +use hir::Documentation; use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use stdx::split_delim; @@ -14,8 +13,6 @@ use crate::display::{generic_parameters, where_predicates}; #[derive(Debug)] pub(crate) enum CallableKind { Function, - StructConstructor, - VariantConstructor, } /// Contains information about a function signature @@ -56,97 +53,6 @@ pub(crate) struct FunctionQualifier { pub(crate) extern_abi: Option, } -impl FunctionSignature { - pub(crate) fn from_hir(db: &RootDatabase, function: hir::Function) -> Self { - let ast_node = function.source(db).value; - let mut res = FunctionSignature::from(&ast_node); - res.doc = function.docs(db); - res - } - - pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option { - let node: ast::StructDef = st.source(db).value; - if let ast::StructKind::Record(_) = node.kind() { - return None; - }; - - let mut params = vec![]; - let mut parameter_types = vec![]; - for field in st.fields(db).into_iter() { - let ty = field.signature_ty(db); - let raw_param = format!("{}", ty.display(db)); - - if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { - parameter_types.push(param_type.to_string()); - } else { - // useful when you have tuple struct - parameter_types.push(raw_param.clone()); - } - params.push(raw_param); - } - - Some(FunctionSignature { - kind: CallableKind::StructConstructor, - visibility: node.visibility().map(|n| n.syntax().text().to_string()), - // Do we need `const`? - qualifier: Default::default(), - name: node.name().map(|n| n.text().to_string()), - ret_type: node.name().map(|n| n.text().to_string()), - parameters: params, - parameter_names: vec![], - parameter_types, - generic_parameters: generic_parameters(&node), - where_predicates: where_predicates(&node), - doc: st.docs(db), - has_self_param: false, - }) - } - - pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) -> Option { - let node: ast::EnumVariant = variant.source(db).value; - match node.kind() { - ast::StructKind::Record(_) | ast::StructKind::Unit => return None, - _ => (), - }; - - let parent_name = variant.parent_enum(db).name(db).to_string(); - - let name = format!("{}::{}", parent_name, variant.name(db)); - - let mut params = vec![]; - let mut parameter_types = vec![]; - for field in variant.fields(db).into_iter() { - let ty = field.signature_ty(db); - let raw_param = format!("{}", ty.display(db)); - if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { - parameter_types.push(param_type.to_string()); - } else { - // The unwrap_or_else is useful when you have tuple - parameter_types.push(raw_param); - } - let name = field.name(db); - - params.push(format!("{}: {}", name, ty.display(db))); - } - - Some(FunctionSignature { - kind: CallableKind::VariantConstructor, - visibility: None, - // Do we need `const`? - qualifier: Default::default(), - name: Some(name), - ret_type: None, - parameters: params, - parameter_names: vec![], - parameter_types, - generic_parameters: vec![], - where_predicates: vec![], - doc: variant.docs(db), - has_self_param: false, - }) - } -} - impl From<&'_ ast::FnDef> for FunctionSignature { fn from(node: &ast::FnDef) -> FunctionSignature { fn param_list(node: &ast::FnDef) -> (bool, Vec, Vec) { -- cgit v1.2.3 From 3823c2dc1995ec261e36435662b8802c714e23d4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 22:05:43 +0200 Subject: Remove FunctionSignature --- crates/ra_ide/src/display/function_signature.rs | 152 ------------------------ 1 file changed, 152 deletions(-) delete mode 100644 crates/ra_ide/src/display/function_signature.rs (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs deleted file mode 100644 index f6e11357f..000000000 --- a/crates/ra_ide/src/display/function_signature.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! FIXME: write short doc here - -// FIXME: this modules relies on strings and AST way too much, and it should be -// rewritten (matklad 2020-05-07) -use std::convert::From; - -use hir::Documentation; -use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; -use stdx::split_delim; - -use crate::display::{generic_parameters, where_predicates}; - -#[derive(Debug)] -pub(crate) enum CallableKind { - Function, -} - -/// Contains information about a function signature -#[derive(Debug)] -pub(crate) struct FunctionSignature { - pub(crate) kind: CallableKind, - /// Optional visibility - pub(crate) visibility: Option, - /// Qualifiers like `async`, `unsafe`, ... - pub(crate) qualifier: FunctionQualifier, - /// Name of the function - pub(crate) name: Option, - /// Documentation for the function - pub(crate) doc: Option, - /// Generic parameters - pub(crate) generic_parameters: Vec, - /// Parameters of the function - pub(crate) parameters: Vec, - /// Parameter names of the function - pub(crate) parameter_names: Vec, - /// Parameter types of the function - pub(crate) parameter_types: Vec, - /// Optional return type - pub(crate) ret_type: Option, - /// Where predicates - pub(crate) where_predicates: Vec, - /// Self param presence - pub(crate) has_self_param: bool, -} - -#[derive(Debug, Default)] -pub(crate) struct FunctionQualifier { - // `async` and `const` are mutually exclusive. Do we need to enforcing it here? - pub(crate) is_async: bool, - pub(crate) is_const: bool, - pub(crate) is_unsafe: bool, - /// The string `extern ".."` - pub(crate) extern_abi: Option, -} - -impl From<&'_ ast::FnDef> for FunctionSignature { - fn from(node: &ast::FnDef) -> FunctionSignature { - fn param_list(node: &ast::FnDef) -> (bool, Vec, Vec) { - let mut res = vec![]; - let mut res_types = vec![]; - let mut has_self_param = false; - if let Some(param_list) = node.param_list() { - if let Some(self_param) = param_list.self_param() { - has_self_param = true; - let raw_param = self_param.syntax().text().to_string(); - - res_types.push( - raw_param - .split(':') - .nth(1) - .and_then(|it| it.get(1..)) - .unwrap_or_else(|| "Self") - .to_string(), - ); - res.push(raw_param); - } - - // macro-generated functions are missing whitespace - fn fmt_param(param: ast::Param) -> String { - let text = param.syntax().text().to_string(); - match split_delim(&text, ':') { - Some((left, right)) => format!("{}: {}", left.trim(), right.trim()), - _ => text, - } - } - - res.extend(param_list.params().map(fmt_param)); - res_types.extend(param_list.params().map(|param| { - let param_text = param.syntax().text().to_string(); - match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { - Some(it) => it.to_string(), - None => param_text, - } - })); - } - (has_self_param, res, res_types) - } - - fn param_name_list(node: &ast::FnDef) -> Vec { - let mut res = vec![]; - if let Some(param_list) = node.param_list() { - if let Some(self_param) = param_list.self_param() { - res.push(self_param.syntax().text().to_string()) - } - - res.extend( - param_list - .params() - .map(|param| { - Some( - param - .pat()? - .syntax() - .descendants() - .find_map(ast::Name::cast)? - .text() - .to_string(), - ) - }) - .map(|param| param.unwrap_or_default()), - ); - } - res - } - - let (has_self_param, parameters, parameter_types) = param_list(node); - - FunctionSignature { - kind: CallableKind::Function, - visibility: node.visibility().map(|n| n.syntax().text().to_string()), - qualifier: FunctionQualifier { - is_async: node.async_token().is_some(), - is_const: node.const_token().is_some(), - is_unsafe: node.unsafe_token().is_some(), - extern_abi: node.abi().map(|n| n.to_string()), - }, - name: node.name().map(|n| n.text().to_string()), - ret_type: node - .ret_type() - .and_then(|r| r.type_ref()) - .map(|n| n.syntax().text().to_string()), - parameters, - parameter_names: param_name_list(node), - parameter_types, - generic_parameters: generic_parameters(node), - where_predicates: where_predicates(node), - // docs are processed separately - doc: None, - has_self_param, - } - } -} -- cgit v1.2.3 From d7548a36a7e814a165b05ffcb9ec5b55e0b291da Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Jul 2020 12:42:48 +0200 Subject: Unclutter NavigationTarget API --- crates/ra_ide/src/display/navigation_target.rs | 81 +++++++++----------------- 1 file changed, 27 insertions(+), 54 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 8bf2428ed..6dcb9415a 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -22,15 +22,28 @@ use super::short_label::ShortLabel; /// code, like a function or a struct, but this is not strictly required. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NavigationTarget { - // FIXME: use FileRange? - file_id: FileId, - full_range: TextRange, - name: SmolStr, - kind: SyntaxKind, - focus_range: Option, - container_name: Option, - description: Option, - docs: Option, + pub file_id: FileId, + /// Range which encompasses the whole element. + /// + /// Should include body, doc comments, attributes, etc. + /// + /// Clients should use this range to answer "is the cursor inside the + /// element?" question. + pub full_range: TextRange, + /// A "most interesting" range withing the `full_range`. + /// + /// Typically, `full_range` is the whole syntax node, including doc + /// comments, and `focus_range` is the range of the identifier. "Most + /// interesting" range within the full range, typically the range of + /// identifier. + /// + /// Clients should place the cursor on this range when navigating to this target. + pub focus_range: Option, + pub name: SmolStr, + pub kind: SyntaxKind, + pub container_name: Option, + pub description: Option, + pub docs: Option, } pub(crate) trait ToNav { @@ -42,44 +55,9 @@ pub(crate) trait TryToNav { } impl NavigationTarget { - /// When `focus_range` is specified, returns it. otherwise - /// returns `full_range` - pub fn range(&self) -> TextRange { + pub fn focus_or_full_range(&self) -> TextRange { self.focus_range.unwrap_or(self.full_range) } - /// A "most interesting" range withing the `full_range`. - /// - /// Typically, `full_range` is the whole syntax node, - /// including doc comments, and `focus_range` is the range of the identifier. - pub fn focus_range(&self) -> Option { - self.focus_range - } - pub fn full_range(&self) -> TextRange { - self.full_range - } - pub fn file_id(&self) -> FileId { - self.file_id - } - - pub fn name(&self) -> &SmolStr { - &self.name - } - - pub fn container_name(&self) -> Option<&SmolStr> { - self.container_name.as_ref() - } - - pub fn kind(&self) -> SyntaxKind { - self.kind - } - - pub fn docs(&self) -> Option<&str> { - self.docs.as_deref() - } - - pub fn description(&self) -> Option<&str> { - self.description.as_deref() - } pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); @@ -107,17 +85,12 @@ impl NavigationTarget { #[cfg(test)] pub(crate) fn debug_render(&self) -> String { - let mut buf = format!( - "{} {:?} {:?} {:?}", - self.name(), - self.kind(), - self.file_id(), - self.full_range() - ); - if let Some(focus_range) = self.focus_range() { + let mut buf = + format!("{} {:?} {:?} {:?}", self.name, self.kind, self.file_id, self.full_range); + if let Some(focus_range) = self.focus_range { buf.push_str(&format!(" {:?}", focus_range)) } - if let Some(container_name) = self.container_name() { + if let Some(container_name) = &self.container_name { buf.push_str(&format!(" {}", container_name)) } buf -- cgit v1.2.3 From 2c268b9a5f4502271b0eec1071f6eaf4d535cea8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Jul 2020 13:28:21 +0200 Subject: Move tests --- crates/ra_ide/src/display/navigation_target.rs | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6dcb9415a..fd245705c 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -418,3 +418,74 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> } } } + +#[cfg(test)] +mod tests { + use expect::expect; + + use crate::{mock_analysis::single_file, Query}; + + #[test] + fn test_nav_for_symbol() { + let (analysis, _) = single_file( + r#" +enum FooInner { } +fn foo() { enum FooInner { } } +"#, + ); + + let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap(); + expect![[r#" + [ + NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 0..17, + focus_range: Some( + 5..13, + ), + name: "FooInner", + kind: ENUM_DEF, + container_name: None, + description: Some( + "enum FooInner", + ), + docs: None, + }, + NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 29..46, + focus_range: Some( + 34..42, + ), + name: "FooInner", + kind: ENUM_DEF, + container_name: Some( + "foo", + ), + description: Some( + "enum FooInner", + ), + docs: None, + }, + ] + "#]] + .assert_debug_eq(&navs); + } + + #[test] + fn test_world_symbols_are_case_sensitive() { + let (analysis, _) = single_file( + r#" +fn foo() {} +struct Foo; +"#, + ); + + let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap(); + assert_eq!(navs.len(), 2) + } +} -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index fd245705c..222cb3502 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -379,7 +379,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match_ast! { match node { - ast::FnDef(it) => it.doc_comment_text(), + ast::Fn(it) => it.doc_comment_text(), ast::StructDef(it) => it.doc_comment_text(), ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), @@ -404,7 +404,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match_ast! { match node { - ast::FnDef(it) => it.short_label(), + ast::Fn(it) => it.short_label(), ast::StructDef(it) => it.short_label(), ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 5588130a1..63863943a 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -7,7 +7,7 @@ pub(crate) trait ShortLabel { fn short_label(&self) -> Option; } -impl ShortLabel for ast::FnDef { +impl ShortLabel for ast::Fn { fn short_label(&self) -> Option { Some(crate::display::function_declaration(self)) } -- cgit v1.2.3 From eb2f8063444b11257111f4f8ade990ec810e0361 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:25:46 +0200 Subject: Rename TypeAliasDef -> TypeAlias --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 222cb3502..4f19c7ed4 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -384,7 +384,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), - ast::TypeAliasDef(it) => it.doc_comment_text(), + ast::TypeAlias(it) => it.doc_comment_text(), ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), ast::RecordFieldDef(it) => it.doc_comment_text(), @@ -409,7 +409,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), - ast::TypeAliasDef(it) => it.short_label(), + ast::TypeAlias(it) => it.short_label(), ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), ast::RecordFieldDef(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 63863943a..e2c95be06 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -47,7 +47,7 @@ impl ShortLabel for ast::Module { } } -impl ShortLabel for ast::TypeAliasDef { +impl ShortLabel for ast::TypeAlias { fn short_label(&self) -> Option { short_label_from_node(self, "type ") } -- cgit v1.2.3 From 0a9e3ccc262fbcbd4cdaab30384f8cb71584544b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:49:13 +0200 Subject: Rename FieldDef -> Field --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 4f19c7ed4..797d2d8e3 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -387,7 +387,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::TypeAlias(it) => it.doc_comment_text(), ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), - ast::RecordFieldDef(it) => it.doc_comment_text(), + ast::RecordField(it) => it.doc_comment_text(), ast::EnumVariant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), _ => None, @@ -412,7 +412,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::TypeAlias(it) => it.short_label(), ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), - ast::RecordFieldDef(it) => it.short_label(), + ast::RecordField(it) => it.short_label(), ast::EnumVariant(it) => it.short_label(), _ => None, } diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index e2c95be06..78a2598d6 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -65,7 +65,7 @@ impl ShortLabel for ast::StaticDef { } } -impl ShortLabel for ast::RecordFieldDef { +impl ShortLabel for ast::RecordField { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "") } -- cgit v1.2.3 From 1ae4721c9cfea746fce59a816b1c266bf373d6cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:36:46 +0200 Subject: Finalize union grammar --- crates/ra_ide/src/display/short_label.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 78a2598d6..730df1414 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -19,7 +19,7 @@ impl ShortLabel for ast::StructDef { } } -impl ShortLabel for ast::UnionDef { +impl ShortLabel for ast::Union { fn short_label(&self) -> Option { short_label_from_node(self, "union ") } -- cgit v1.2.3 From 216a5344c8ef3c3e430d2761dc8b1a7b60250a15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:50:40 +0200 Subject: Rename StructDef -> Struct --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 797d2d8e3..5686faaab 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -380,7 +380,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match_ast! { match node { ast::Fn(it) => it.doc_comment_text(), - ast::StructDef(it) => it.doc_comment_text(), + ast::Struct(it) => it.doc_comment_text(), ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), @@ -405,7 +405,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match_ast! { match node { ast::Fn(it) => it.short_label(), - ast::StructDef(it) => it.short_label(), + ast::Struct(it) => it.short_label(), ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 730df1414..504b884c5 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -13,7 +13,7 @@ impl ShortLabel for ast::Fn { } } -impl ShortLabel for ast::StructDef { +impl ShortLabel for ast::Struct { fn short_label(&self) -> Option { short_label_from_node(self, "struct ") } -- cgit v1.2.3 From 609680ef97dbf82c07b6b06e21aa366423892304 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:52:53 +0200 Subject: Rename EnumDef -> Enum --- crates/ra_ide/src/display/navigation_target.rs | 8 ++++---- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 5686faaab..02fefd6bb 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -381,7 +381,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match node { ast::Fn(it) => it.doc_comment_text(), ast::Struct(it) => it.doc_comment_text(), - ast::EnumDef(it) => it.doc_comment_text(), + ast::Enum(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), @@ -406,7 +406,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match node { ast::Fn(it) => it.short_label(), ast::Struct(it) => it.short_label(), - ast::EnumDef(it) => it.short_label(), + ast::Enum(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), @@ -446,7 +446,7 @@ fn foo() { enum FooInner { } } 5..13, ), name: "FooInner", - kind: ENUM_DEF, + kind: ENUM, container_name: None, description: Some( "enum FooInner", @@ -462,7 +462,7 @@ fn foo() { enum FooInner { } } 34..42, ), name: "FooInner", - kind: ENUM_DEF, + kind: ENUM, container_name: Some( "foo", ), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 504b884c5..5bf70937f 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -25,7 +25,7 @@ impl ShortLabel for ast::Union { } } -impl ShortLabel for ast::EnumDef { +impl ShortLabel for ast::Enum { fn short_label(&self) -> Option { short_label_from_node(self, "enum ") } -- cgit v1.2.3 From 1766aae145c6925a33e427f2fe6ef2a56c301665 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:56:53 +0200 Subject: Rename EnumVariant -> Variant --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 02fefd6bb..c30b91fe0 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -388,7 +388,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), ast::RecordField(it) => it.doc_comment_text(), - ast::EnumVariant(it) => it.doc_comment_text(), + ast::Variant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), _ => None, } @@ -413,7 +413,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), ast::RecordField(it) => it.short_label(), - ast::EnumVariant(it) => it.short_label(), + ast::Variant(it) => it.short_label(), _ => None, } } diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 5bf70937f..ddf1059ee 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -71,7 +71,7 @@ impl ShortLabel for ast::RecordField { } } -impl ShortLabel for ast::EnumVariant { +impl ShortLabel for ast::Variant { fn short_label(&self) -> Option { Some(self.name()?.text().to_string()) } -- cgit v1.2.3 From 3cd4112bdc924c132cb0eab9d064511a215421ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:02:20 +0200 Subject: Finalize const&static grammar --- crates/ra_ide/src/display/navigation_target.rs | 8 ++++---- crates/ra_ide/src/display/short_label.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index c30b91fe0..9e2c01245 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -385,8 +385,8 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), - ast::ConstDef(it) => it.doc_comment_text(), - ast::StaticDef(it) => it.doc_comment_text(), + ast::Const(it) => it.doc_comment_text(), + ast::Static(it) => it.doc_comment_text(), ast::RecordField(it) => it.doc_comment_text(), ast::Variant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), @@ -410,8 +410,8 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), - ast::ConstDef(it) => it.short_label(), - ast::StaticDef(it) => it.short_label(), + ast::Const(it) => it.short_label(), + ast::Static(it) => it.short_label(), ast::RecordField(it) => it.short_label(), ast::Variant(it) => it.short_label(), _ => None, diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index ddf1059ee..282f362f2 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -53,13 +53,13 @@ impl ShortLabel for ast::TypeAlias { } } -impl ShortLabel for ast::ConstDef { +impl ShortLabel for ast::Const { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "const ") } } -impl ShortLabel for ast::StaticDef { +impl ShortLabel for ast::Static { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "static ") } -- cgit v1.2.3 From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 9e2c01245..45fbc86ef 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -382,7 +382,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::Fn(it) => it.doc_comment_text(), ast::Struct(it) => it.doc_comment_text(), ast::Enum(it) => it.doc_comment_text(), - ast::TraitDef(it) => it.doc_comment_text(), + ast::Trait(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), ast::Const(it) => it.doc_comment_text(), @@ -407,7 +407,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::Fn(it) => it.short_label(), ast::Struct(it) => it.short_label(), ast::Enum(it) => it.short_label(), - ast::TraitDef(it) => it.short_label(), + ast::Trait(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), ast::Const(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 282f362f2..c600908a4 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -31,7 +31,7 @@ impl ShortLabel for ast::Enum { } } -impl ShortLabel for ast::TraitDef { +impl ShortLabel for ast::Trait { fn short_label(&self) -> Option { if self.unsafe_token().is_some() { short_label_from_node(self, "unsafe trait ") -- cgit v1.2.3 From 2e2642efccd5855e4158b01a006e7884a96982bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:51:43 +0200 Subject: Remove TypeAscriptionOwner --- crates/ra_ide/src/display/short_label.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide/src/display') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index c600908a4..bddf1bd47 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; +use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use stdx::format_to; pub(crate) trait ShortLabel { @@ -55,19 +55,19 @@ impl ShortLabel for ast::TypeAlias { impl ShortLabel for ast::Const { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "const ") + short_label_from_ty(self, self.ty(), "const ") } } impl ShortLabel for ast::Static { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "static ") + short_label_from_ty(self, self.ty(), "static ") } } impl ShortLabel for ast::RecordField { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "") + short_label_from_ty(self, self.ty(), "") } } @@ -77,13 +77,13 @@ impl ShortLabel for ast::Variant { } } -fn short_label_from_ascribed_node(node: &T, prefix: &str) -> Option +fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option where - T: NameOwner + VisibilityOwner + TypeAscriptionOwner, + T: NameOwner + VisibilityOwner, { let mut buf = short_label_from_node(node, prefix)?; - if let Some(type_ref) = node.ascribed_type() { + if let Some(type_ref) = ty { format_to!(buf, ": {}", type_ref.syntax()); } -- cgit v1.2.3