From 027d4d229d7be91630de95d0d3ef004327828bd6 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 8 Apr 2019 12:20:28 +0300 Subject: Move navigation_target to display/navigation_target --- crates/ra_ide_api/src/display/navigation_target.rs | 251 +++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 crates/ra_ide_api/src/display/navigation_target.rs (limited to 'crates/ra_ide_api/src/display') diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs new file mode 100644 index 000000000..f6d7f3192 --- /dev/null +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -0,0 +1,251 @@ +use ra_db::FileId; +use ra_syntax::{ + SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast, + SyntaxKind::{self, NAME}, +}; +use hir::{ModuleSource, FieldSource, Name, ImplItem}; + +use crate::{FileSymbol, db::RootDatabase}; + +/// `NavigationTarget` represents and element in the editor's UI which you can +/// click on to navigate to a particular piece of code. +/// +/// Typically, a `NavigationTarget` corresponds to some element in the source +/// code, like a function or a struct, but this is not strictly required. +#[derive(Debug, Clone)] +pub struct NavigationTarget { + file_id: FileId, + name: SmolStr, + kind: SyntaxKind, + full_range: TextRange, + focus_range: Option, + container_name: Option, +} + +impl NavigationTarget { + /// When `focus_range` is specified, returns it. otherwise + /// returns `full_range` + pub fn range(&self) -> TextRange { + self.focus_range.unwrap_or(self.full_range) + } + + 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 file_id(&self) -> FileId { + self.file_id + } + + pub fn full_range(&self) -> TextRange { + 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(crate) fn from_bind_pat(file_id: FileId, pat: &ast::BindPat) -> NavigationTarget { + NavigationTarget::from_named(file_id, pat) + } + + pub(crate) fn from_symbol(symbol: FileSymbol) -> NavigationTarget { + NavigationTarget { + file_id: symbol.file_id, + name: symbol.name.clone(), + kind: symbol.ptr.kind(), + full_range: symbol.ptr.range(), + focus_range: symbol.name_range, + container_name: symbol.container_name.clone(), + } + } + + pub(crate) fn from_scope_entry( + file_id: FileId, + name: Name, + ptr: SyntaxNodePtr, + ) -> NavigationTarget { + NavigationTarget { + file_id, + name: name.to_string().into(), + full_range: ptr.range(), + focus_range: None, + kind: NAME, + container_name: None, + } + } + + pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget { + let (file_id, source) = module.definition_source(db); + let file_id = file_id.as_original_file(); + let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); + match source { + ModuleSource::SourceFile(node) => { + NavigationTarget::from_syntax(file_id, name, None, node.syntax()) + } + ModuleSource::Module(node) => { + NavigationTarget::from_syntax(file_id, name, None, node.syntax()) + } + } + } + + 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((file_id, source)) = module.declaration_source(db) { + let file_id = file_id.as_original_file(); + return NavigationTarget::from_syntax(file_id, name, None, source.syntax()); + } + NavigationTarget::from_module(db, module) + } + + pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget { + let (file_id, fn_def) = func.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*fn_def) + } + + pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget { + let (file_id, field) = field.source(db); + let file_id = file_id.original_file(db); + match field { + FieldSource::Named(it) => NavigationTarget::from_named(file_id, &*it), + FieldSource::Pos(it) => { + NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax()) + } + } + } + + pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { + match adt_def { + hir::AdtDef::Struct(s) => { + let (file_id, node) = s.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::AdtDef::Enum(s) => { + let (file_id, node) = s.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + } + } + + pub(crate) fn from_def(db: &RootDatabase, module_def: hir::ModuleDef) -> NavigationTarget { + match module_def { + hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), + hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func), + hir::ModuleDef::Struct(s) => { + let (file_id, node) = s.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::Const(s) => { + let (file_id, node) = s.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::Static(s) => { + let (file_id, node) = s.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::Enum(e) => { + let (file_id, node) = e.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::EnumVariant(var) => { + let (file_id, node) = var.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::Trait(e) => { + let (file_id, node) = e.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + hir::ModuleDef::TypeAlias(e) => { + let (file_id, node) = e.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + } + } + + pub(crate) fn from_impl_block( + db: &RootDatabase, + impl_block: hir::ImplBlock, + ) -> NavigationTarget { + let (file_id, node) = impl_block.source(db); + NavigationTarget::from_syntax( + file_id.as_original_file(), + "impl".into(), + None, + node.syntax(), + ) + } + + pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget { + match impl_item { + ImplItem::Method(f) => NavigationTarget::from_function(db, f), + ImplItem::Const(c) => { + let (file_id, node) = c.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + ImplItem::TypeAlias(a) => { + let (file_id, node) = a.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*node) + } + } + } + + #[cfg(test)] + pub(crate) fn assert_match(&self, expected: &str) { + let actual = self.debug_render(); + test_utils::assert_eq_text!(expected.trim(), actual.trim(),); + } + + #[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() { + buf.push_str(&format!(" {:?}", focus_range)) + } + if let Some(container_name) = self.container_name() { + buf.push_str(&format!(" {}", container_name)) + } + buf + } + + /// Allows `NavigationTarget` to be created from a `NameOwner` + pub(crate) fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget { + let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); + let focus_range = node.name().map(|it| it.syntax().range()); + NavigationTarget::from_syntax(file_id, name, focus_range, node.syntax()) + } + + fn from_syntax( + file_id: FileId, + name: SmolStr, + focus_range: Option, + node: &SyntaxNode, + ) -> NavigationTarget { + NavigationTarget { + file_id, + name, + kind: node.kind(), + full_range: node.range(), + focus_range, + // ptr: Some(LocalSyntaxPtr::new(node)), + container_name: None, + } + } +} -- cgit v1.2.3 From 7821c56be7fc1699f6fb748e45f4765162b75ba9 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 8 Apr 2019 16:04:58 +0300 Subject: Move structure to display/structure --- .../display/snapshots/tests__file_structure.snap | 182 ++++++++++++++++++++ crates/ra_ide_api/src/display/structure.rs | 190 +++++++++++++++++++++ 2 files changed, 372 insertions(+) create mode 100644 crates/ra_ide_api/src/display/snapshots/tests__file_structure.snap create mode 100644 crates/ra_ide_api/src/display/structure.rs (limited to 'crates/ra_ide_api/src/display') diff --git a/crates/ra_ide_api/src/display/snapshots/tests__file_structure.snap b/crates/ra_ide_api/src/display/snapshots/tests__file_structure.snap new file mode 100644 index 000000000..32dd99484 --- /dev/null +++ b/crates/ra_ide_api/src/display/snapshots/tests__file_structure.snap @@ -0,0 +1,182 @@ +--- +created: "2019-04-08T09:44:50.196004400Z" +creator: insta@0.7.4 +source: crates/ra_ide_api/src/display/structure.rs +expression: structure +--- +[ + 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: NAMED_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_BLOCK, + detail: None, + deprecated: false + }, + StructureNode { + parent: None, + label: "impl fmt::Debug for E", + navigation_range: [265; 266), + node_range: [245; 269), + kind: IMPL_BLOCK, + detail: None, + deprecated: false + }, + StructureNode { + parent: None, + label: "obsolete", + navigation_range: [288; 296), + node_range: [271; 301), + kind: FN_DEF, + detail: Some( + "fn()" + ), + deprecated: true + }, + StructureNode { + parent: None, + label: "very_obsolete", + navigation_range: [341; 354), + node_range: [303; 359), + kind: FN_DEF, + detail: Some( + "fn()" + ), + deprecated: true + } +] diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs new file mode 100644 index 000000000..ec2c9bbc6 --- /dev/null +++ b/crates/ra_ide_api/src/display/structure.rs @@ -0,0 +1,190 @@ +use crate::TextRange; + +use ra_syntax::{ + algo::visit::{visitor, Visitor}, + ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner}, + AstNode, SourceFile, SyntaxKind, SyntaxNode, 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, +} + +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().map(|&n| n); + 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 { + decl_with_type_ref(node, node.ascribed_type()) + } + + fn decl_with_type_ref( + node: &N, + type_ref: Option<&ast::TypeRef>, + ) -> 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().range(), + node_range: node.syntax().range(), + kind: node.syntax().kind(), + detail, + deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"), + }) + } + + fn collapse_ws(node: &SyntaxNode, output: &mut String) { + let mut can_insert_ws = false; + for line in node.text().chunks().flat_map(|chunk| chunk.lines()) { + let line = line.trim(); + if line.is_empty() { + if can_insert_ws { + output.push_str(" "); + can_insert_ws = false; + } + } else { + output.push_str(line); + can_insert_ws = true; + } + } + } + + visitor() + .visit(|fn_def: &ast::FnDef| { + let mut detail = String::from("fn"); + if let Some(type_param_list) = fn_def.type_param_list() { + collapse_ws(type_param_list.syntax(), &mut detail); + } + if let Some(param_list) = fn_def.param_list() { + collapse_ws(param_list.syntax(), &mut detail); + } + if let Some(ret_type) = fn_def.ret_type() { + detail.push_str(" "); + collapse_ws(ret_type.syntax(), &mut detail); + } + + decl_with_detail(fn_def, Some(detail)) + }) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(|td: &ast::TypeAliasDef| decl_with_type_ref(td, td.type_ref())) + .visit(decl_with_ascription::) + .visit(decl_with_ascription::) + .visit(decl_with_ascription::) + .visit(|im: &ast::ImplBlock| { + let target_type = im.target_type()?; + let target_trait = im.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().range(), + node_range: im.syntax().range(), + kind: im.syntax().kind(), + detail: None, + deprecated: false, + }; + Some(node) + }) + .accept(node)? +} + +#[cfg(test)] +mod tests { + use super::*; + use insta::assert_debug_snapshot_matches; + + #[test] + fn test_file_structure() { + let file = SourceFile::parse( + 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 {} + +#[deprecated] +fn obsolete() {} + +#[deprecated(note = "for awhile")] +fn very_obsolete() {} +"#, + ); + let structure = file_structure(&file); + assert_debug_snapshot_matches!("file_structure", structure); + } +} -- cgit v1.2.3 From fead60aa27e54d3ce48819c30d1db59c52d856c9 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 8 Apr 2019 16:34:59 +0300 Subject: Move FunctionSignature to display/function_signature --- .../ra_ide_api/src/display/function_signature.rs | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 crates/ra_ide_api/src/display/function_signature.rs (limited to 'crates/ra_ide_api/src/display') diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs new file mode 100644 index 000000000..d09950bce --- /dev/null +++ b/crates/ra_ide_api/src/display/function_signature.rs @@ -0,0 +1,101 @@ +use super::{where_predicates, generic_parameters}; +use crate::db; +use std::fmt::{self, Display}; +use join_to_string::join; +use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; +use std::convert::From; +use hir::{Docs, Documentation}; + +/// Contains information about a function signature +#[derive(Debug)] +pub struct FunctionSignature { + /// Optional visibility + pub visibility: Option, + /// Name of the function + pub name: Option, + /// Documentation for the function + pub doc: Option, + /// Generic parameters + pub generic_parameters: Vec, + /// Parameters of the function + pub parameters: Vec, + /// Optional return type + pub ret_type: Option, + /// Where predicates + pub where_predicates: Vec, +} + +impl FunctionSignature { + pub(crate) fn with_doc_opt(mut self, doc: Option) -> Self { + self.doc = doc; + self + } + + pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { + let doc = function.docs(db); + let (_, ast_node) = function.source(db); + FunctionSignature::from(&*ast_node).with_doc_opt(doc) + } +} + +impl From<&'_ ast::FnDef> for FunctionSignature { + fn from(node: &ast::FnDef) -> FunctionSignature { + fn param_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| param.syntax().text().to_string())); + } + res + } + + FunctionSignature { + visibility: node.visibility().map(|n| n.syntax().text().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: param_list(node), + generic_parameters: generic_parameters(node), + where_predicates: where_predicates(node), + // docs are processed separately + doc: None, + } + } +} + +impl Display for FunctionSignature { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if let Some(t) = &self.visibility { + write!(f, "{} ", t)?; + } + + if let Some(name) = &self.name { + write!(f, "fn {}", name)?; + } + + if !self.generic_parameters.is_empty() { + join(self.generic_parameters.iter()) + .separator(", ") + .surround_with("<", ">") + .to_fmt(f)?; + } + + join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?; + + if let Some(t) = &self.ret_type { + write!(f, " -> {}", t)?; + } + + if !self.where_predicates.is_empty() { + write!(f, "\nwhere ")?; + join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?; + } + + Ok(()) + } +} -- cgit v1.2.3 From 07f0069f342afa17536aa4b9db4250f4d6c83954 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 9 Apr 2019 14:43:11 +0300 Subject: Move display related things from hover to display --- crates/ra_ide_api/src/display/navigation_target.rs | 82 +++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/display') diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index f6d7f3192..3c518faf5 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -1,7 +1,9 @@ -use ra_db::FileId; +use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ - SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast, + SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, TreeArc, SyntaxKind::{self, NAME}, + ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner}, + algo::visit::{visitor, Visitor}, }; use hir::{ModuleSource, FieldSource, Name, ImplItem}; @@ -248,4 +250,80 @@ impl NavigationTarget { container_name: None, } } + + pub(crate) fn node(&self, db: &RootDatabase) -> Option> { + let source_file = db.parse(self.file_id()); + let source_file = source_file.syntax(); + let node = source_file + .descendants() + .find(|node| node.kind() == self.kind() && node.range() == self.full_range())? + .to_owned(); + Some(node) + } + + pub(crate) fn docs(&self, db: &RootDatabase) -> Option { + let node = self.node(db)?; + fn doc_comments(node: &N) -> Option { + node.doc_comment_text() + } + + visitor() + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .accept(&node)? + } + + /// Get a description of this node. + /// + /// e.g. `struct Name`, `enum Name`, `fn Name` + pub(crate) fn description(&self, db: &RootDatabase) -> Option { + // FIXME: After type inference is done, add type information to improve the output + let node = self.node(db)?; + + fn visit_ascribed_node(node: &T, prefix: &str) -> Option + where + T: NameOwner + VisibilityOwner + TypeAscriptionOwner, + { + let mut string = visit_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 visit_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) + } + + visitor() + .visit(|node: &ast::FnDef| Some(crate::display::function_label(node))) + .visit(|node: &ast::StructDef| visit_node(node, "struct ")) + .visit(|node: &ast::EnumDef| visit_node(node, "enum ")) + .visit(|node: &ast::TraitDef| visit_node(node, "trait ")) + .visit(|node: &ast::Module| visit_node(node, "mod ")) + .visit(|node: &ast::TypeAliasDef| visit_node(node, "type ")) + .visit(|node: &ast::ConstDef| visit_ascribed_node(node, "const ")) + .visit(|node: &ast::StaticDef| visit_ascribed_node(node, "static ")) + .visit(|node: &ast::NamedFieldDef| visit_ascribed_node(node, "")) + .visit(|node: &ast::EnumVariant| Some(node.name()?.text().to_string())) + .accept(&node)? + } } -- cgit v1.2.3