diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 5d61c9f3a..960bfc4d0 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -5,7 +5,7 @@ use cairo_lang_diagnostics::{DiagnosticAdded, Maybe}; use cairo_lang_doc::parser::DocumentationCommentToken; use cairo_lang_semantic::items::functions::GenericFunctionId; use cairo_lang_semantic::items::us::SemanticUseEx; -use cairo_lang_semantic::items::visibility::{self, Visibility}; +use cairo_lang_semantic::items::visibility::Visibility; use cairo_lang_semantic::resolve::ResolvedGenericItem; use cairo_lang_syntax::node::helpers::QueryAttrs; use cairo_lang_utils::{LookupIntern, Upcast}; @@ -46,24 +46,15 @@ impl Crate { include_private_items: bool, ) -> Maybe { let root_module_id = ModuleId::CrateRoot(crate_id); - let root_module = Module::new(db, root_module_id, root_module_id, include_private_items)?; + let root_module = Module::new(db, root_module_id, include_private_items)?; Ok(Self { root_module }) } } -fn is_visible_in_module( - db: &ScarbDocDatabase, - root_module_id: ModuleId, - element_id: &dyn TopLevelLanguageElementId, -) -> Maybe { - let cotaining_module_id = element_id.parent_module(db); - match db.module_item_info_by_name(cotaining_module_id, element_id.name(db.upcast()))? { - Some(module_item_info) => Ok(visibility::peek_visible_in( - db, - module_item_info.visibility, - cotaining_module_id, - root_module_id, - )), +fn is_public(db: &ScarbDocDatabase, element_id: &dyn TopLevelLanguageElementId) -> Maybe { + let containing_module_id = element_id.parent_module(db); + match db.module_item_info_by_name(containing_module_id, element_id.name(db.upcast()))? { + Some(module_item_info) => Ok(matches!(module_item_info.visibility, Visibility::Public)), None => Ok(false), } } @@ -180,7 +171,6 @@ impl Module { pub fn new( db: &ScarbDocDatabase, module_id: ModuleId, - root_module_id: ModuleId, include_private_items: bool, ) -> Maybe { let item_data = match module_id { @@ -195,10 +185,8 @@ impl Module { let should_include_item = |id: &dyn TopLevelLanguageElementId| { let syntax_node = id.stable_location(db.upcast()).syntax_node(db.upcast()); - Ok( - (include_private_items || is_visible_in_module(db, root_module_id, id)?) - && !is_doc_hidden_attr(db, &syntax_node), - ) + Ok((include_private_items || is_public(db, id)?) + && !is_doc_hidden_attr(db, &syntax_node)) }; let module_pubuses = ModulePubUses::new(db, module_id); @@ -224,7 +212,7 @@ impl Module { let structs = filter_map_item_id_to_item( chain!(module_structs.keys(), module_pubuses.use_structs.iter()), should_include_item, - |id| Struct::new(db, *id, root_module_id, include_private_items), + |id| Struct::new(db, *id, include_private_items), )?; let module_enums = db.module_enums(module_id)?; @@ -340,27 +328,13 @@ impl Module { module_pubuses.use_submodules.iter() ), should_include_item, - |id| { - Module::new( - db, - ModuleId::Submodule(*id), - root_module_id, - include_private_items, - ) - }, + |id| Module::new(db, ModuleId::Submodule(*id), include_private_items), )?; let reexported_crates_as_modules: Vec = module_pubuses .use_crates .iter() - .map(|id| { - Module::new( - db, - ModuleId::CrateRoot(*id), - root_module_id, - include_private_items, - ) - }) + .map(|id| Module::new(db, ModuleId::CrateRoot(*id), include_private_items)) .collect::>()?; submodules.extend(reexported_crates_as_modules); @@ -617,12 +591,7 @@ pub struct Struct { } impl Struct { - pub fn new( - db: &ScarbDocDatabase, - id: StructId, - root_module_id: ModuleId, - include_private_items: bool, - ) -> Maybe { + pub fn new(db: &ScarbDocDatabase, id: StructId, include_private_items: bool) -> Maybe { let members = db.struct_members(id)?; let item_data = ItemData::new( @@ -633,21 +602,15 @@ impl Struct { let members = members .iter() .filter_map(|(_, semantic_member)| { - match is_visible_in_module(db, root_module_id, &semantic_member.id) { - Ok(visible) => { - let syntax_node = &semantic_member - .id - .stable_location(db.upcast()) - .syntax_node(db.upcast()); - if (include_private_items || visible) - && !is_doc_hidden_attr(db, syntax_node) - { - Some(Ok(Member::new(db, semantic_member.id))) - } else { - None - } - } - Err(e) => Some(Err(e)), + let visible = matches!(semantic_member.visibility, Visibility::Public); + let syntax_node = &semantic_member + .id + .stable_location(db.upcast()) + .syntax_node(db.upcast()); + if (include_private_items || visible) && !is_doc_hidden_attr(db, syntax_node) { + Some(Ok(Member::new(db, semantic_member.id))) + } else { + None } }) .collect::>>()?; diff --git a/extensions/scarb-doc/tests/code/code_5.cairo b/extensions/scarb-doc/tests/code/code_5.cairo index 5a894c757..e34d865ed 100644 --- a/extensions/scarb-doc/tests/code/code_5.cairo +++ b/extensions/scarb-doc/tests/code/code_5.cairo @@ -88,7 +88,7 @@ pub mod PublicParent { private_field: felt252 } - /// Parent publi crate struct + /// Parent public crate struct pub(crate) struct PublicCrateParentStructure { /// Public struct field pub public_field: felt252, diff --git a/extensions/scarb-doc/tests/data/json_private_items_excluded.json b/extensions/scarb-doc/tests/data/json_private_items_excluded.json index 8052ee999..13aa72dfd 100644 --- a/extensions/scarb-doc/tests/data/json_private_items_excluded.json +++ b/extensions/scarb-doc/tests/data/json_private_items_excluded.json @@ -36,679 +36,25 @@ "signature": "pub fn child_public_function()", "full_path": "hello_world::PublicParent::PublicChild::child_public_function" } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PublicParent::PublicChild::child_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicChildStructure", - "doc": "Child public struct", - "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicChild::PublicCrateChildStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicChild::PublicChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicChildEnum", - "doc": "Child public enum", - "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicChild::PublicChildEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicChild::PublicCrateChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicChild::PublicCrateChildEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - }, - { - "item_data": { - "name": "PublicCrateChild", - "doc": "Public crate child module", - "signature": null, - "full_path": "hello_world::PublicParent::PublicCrateChild" - }, - "submodules": [], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "child_public_function", - "doc": "Child public function", - "signature": "pub fn child_public_function()", - "full_path": "hello_world::PublicParent::PublicCrateChild::child_public_function" - } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PublicParent::PublicCrateChild::child_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicChildStructure", - "doc": "Child public struct", - "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicCrateChildStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicChildEnum", - "doc": "Child public enum", - "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicChildEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicCrateChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicCrateChild::PublicCrateChildEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - } - ], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "parent_public_function", - "doc": "Parent public function", - "signature": "pub fn parent_public_function()", - "full_path": "hello_world::PublicParent::parent_public_function" - } - }, - { - "item_data": { - "name": "parent_public_crate_function", - "doc": "Parent public crate function", - "signature": "pub(crate) fn parent_public_crate_function()", - "full_path": "hello_world::PublicParent::parent_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicParentStructure", - "doc": "Parent public struct", - "signature": "pub struct PublicParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicParentStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateParentStructure", - "doc": "Parent publi crate struct", - "signature": "pub(crate) struct PublicCrateParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicParent::PublicCrateParentStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicParentEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicParentEnum", - "doc": "Parent public enum", - "signature": "pub enum PublicParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicParentEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicParent::PublicCrateParentEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateParentEnum", - "doc": "Parent public crate enum", - "signature": "pub(crate) enum PublicCrateParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicParent::PublicCrateParentEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - }, - { - "item_data": { - "name": "PublicCrateParent", - "doc": "Public crate parent module", - "signature": null, - "full_path": "hello_world::PublicCrateParent" - }, - "submodules": [ - { - "item_data": { - "name": "PublicChild", - "doc": "Public child module", - "signature": null, - "full_path": "hello_world::PublicCrateParent::PublicChild" - }, - "submodules": [], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "child_public_function", - "doc": "Child public function", - "signature": "pub fn child_public_function()", - "full_path": "hello_world::PublicCrateParent::PublicChild::child_public_function" - } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PublicCrateParent::PublicChild::child_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicChildStructure", - "doc": "Child public struct", - "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicCrateChildStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicChildEnum", - "doc": "Child public enum", - "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicChildEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicCrateChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicChild::PublicCrateChildEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - }, - { - "item_data": { - "name": "PublicCrateChild", - "doc": "Public crate child module", - "signature": null, - "full_path": "hello_world::PublicCrateParent::PublicCrateChild" - }, - "submodules": [], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "child_public_function", - "doc": "Child public function", - "signature": "pub fn child_public_function()", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::child_public_function" - } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::child_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicChildStructure", - "doc": "Child public struct", - "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicCrateChildStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicChildEnum", - "doc": "Child public enum", - "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicChildEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicCrateChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateChild::PublicCrateChildEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - } - ], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "parent_public_function", - "doc": "Parent public function", - "signature": "pub fn parent_public_function()", - "full_path": "hello_world::PublicCrateParent::parent_public_function" - } - }, - { - "item_data": { - "name": "parent_public_crate_function", - "doc": "Parent public crate function", - "signature": "pub(crate) fn parent_public_crate_function()", - "full_path": "hello_world::PublicCrateParent::parent_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], - "item_data": { - "name": "PublicParentStructure", - "doc": "Parent public struct", - "signature": "pub struct PublicParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicParentStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateParentStructure", - "doc": "Parent public struct", - "signature": "pub(crate) struct PublicCrateParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateParentStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicParentEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicParentEnum", - "doc": "Parent public enum", - "signature": "pub enum PublicParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicParentEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateParent::PublicCrateParentEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateParentEnum", - "doc": "Parent public crate enum", - "signature": "pub(crate) enum PublicCrateParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateParent::PublicCrateParentEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - }, - { - "item_data": { - "name": "PrivateParent", - "doc": "Private parent module", - "signature": null, - "full_path": "hello_world::PrivateParent" - }, - "submodules": [ - { - "item_data": { - "name": "PublicChild", - "doc": "Public child module", - "signature": null, - "full_path": "hello_world::PrivateParent::PublicChild" - }, - "submodules": [], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "child_public_function", - "doc": "Child public function", - "signature": "pub fn child_public_function()", - "full_path": "hello_world::PrivateParent::PublicChild::child_public_function" - } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PrivateParent::PublicChild::child_public_crate_function" - } } ], "structs": [ { - "members": [], - "item_data": { - "name": "PublicChildStructure", - "doc": "Child public struct", - "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicChild::PublicCrateChildStructure" - } - } - ], - "enums": [ - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicChild::PublicChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicChildEnum", - "doc": "Child public enum", - "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicChild::PublicChildEnum" - } - }, - { - "variants": [ + "members": [ { "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicChild::PublicCrateChildEnum::PUBLIC_VARIANT" + "name": "public_field", + "doc": "Public struct field", + "signature": "pub public_field: felt252", + "full_path": "hello_world::PublicParent::PublicChild::PublicChildStructure::public_field" } } ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicChild::PublicCrateChildEnum" - } - } - ], - "type_aliases": [], - "impl_aliases": [], - "traits": [], - "impls": [], - "extern_types": [], - "extern_functions": [] - }, - { - "item_data": { - "name": "PublicCrateChild", - "doc": "Public crate child module", - "signature": null, - "full_path": "hello_world::PrivateParent::PublicCrateChild" - }, - "submodules": [], - "constants": [], - "free_functions": [ - { - "item_data": { - "name": "child_public_function", - "doc": "Child public function", - "signature": "pub fn child_public_function()", - "full_path": "hello_world::PrivateParent::PublicCrateChild::child_public_function" - } - }, - { - "item_data": { - "name": "child_public_crate_function", - "doc": "Child crate public function", - "signature": "pub(crate) fn child_public_crate_function()", - "full_path": "hello_world::PrivateParent::PublicCrateChild::child_public_crate_function" - } - } - ], - "structs": [ - { - "members": [], "item_data": { "name": "PublicChildStructure", "doc": "Child public struct", "signature": "pub struct PublicChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicChildStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateChildStructure", - "doc": "Child public crate struct", - "signature": "pub(crate) struct PublicCrateChildStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicCrateChildStructure" + "full_path": "hello_world::PublicParent::PublicChild::PublicChildStructure" } } ], @@ -720,7 +66,7 @@ "name": "PUBLIC_VARIANT", "doc": "Public enum variant", "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicChildEnum::PUBLIC_VARIANT" + "full_path": "hello_world::PublicParent::PublicChild::PublicChildEnum::PUBLIC_VARIANT" } } ], @@ -728,25 +74,7 @@ "name": "PublicChildEnum", "doc": "Child public enum", "signature": "pub enum PublicChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicChildEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicCrateChildEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateChildEnum", - "doc": "Child public crate enum", - "signature": "pub(crate) enum PublicCrateChildEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateChild::PublicCrateChildEnum" + "full_path": "hello_world::PublicParent::PublicChild::PublicChildEnum" } } ], @@ -765,35 +93,27 @@ "name": "parent_public_function", "doc": "Parent public function", "signature": "pub fn parent_public_function()", - "full_path": "hello_world::PrivateParent::parent_public_function" - } - }, - { - "item_data": { - "name": "parent_public_crate_function", - "doc": "Parent public crate function", - "signature": "pub(crate) fn parent_public_crate_function()", - "full_path": "hello_world::PrivateParent::parent_public_crate_function" + "full_path": "hello_world::PublicParent::parent_public_function" } } ], "structs": [ { - "members": [], + "members": [ + { + "item_data": { + "name": "public_field", + "doc": "Public struct field", + "signature": "pub public_field: felt252", + "full_path": "hello_world::PublicParent::PublicParentStructure::public_field" + } + } + ], "item_data": { "name": "PublicParentStructure", "doc": "Parent public struct", "signature": "pub struct PublicParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicParentStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateParentStructure", - "doc": "Parent public struct", - "signature": "pub(crate) struct PublicCrateParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateParentStructure" + "full_path": "hello_world::PublicParent::PublicParentStructure" } } ], @@ -805,7 +125,7 @@ "name": "PUBLIC_VARIANT", "doc": "Public enum variant", "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicParentEnum::PUBLIC_VARIANT" + "full_path": "hello_world::PublicParent::PublicParentEnum::PUBLIC_VARIANT" } } ], @@ -813,25 +133,7 @@ "name": "PublicParentEnum", "doc": "Parent public enum", "signature": "pub enum PublicParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicParentEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PrivateParent::PublicCrateParentEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateParentEnum", - "doc": "Parent public crate enum", - "signature": "pub(crate) enum PublicCrateParentEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PrivateParent::PublicCrateParentEnum" + "full_path": "hello_world::PublicParent::PublicParentEnum" } } ], @@ -852,59 +154,26 @@ "signature": "pub fn public_function()", "full_path": "hello_world::public_function" } - }, - { - "item_data": { - "name": "public_crate_function", - "doc": "Public crate function", - "signature": "pub(crate) fn public_crate_function()", - "full_path": "hello_world::public_crate_function" - } - }, - { - "item_data": { - "name": "private_function", - "doc": "Private function", - "signature": "fn private_function()", - "full_path": "hello_world::private_function" - } - }, - { - "item_data": { - "name": "main", - "doc": null, - "signature": "fn main()", - "full_path": "hello_world::main" - } } ], "structs": [ { - "members": [], + "members": [ + { + "item_data": { + "name": "public_field", + "doc": "Public struct field", + "signature": "pub public_field: felt252", + "full_path": "hello_world::PublicStructure::public_field" + } + } + ], "item_data": { "name": "PublicStructure", "doc": "Public struct", "signature": "pub struct PublicStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", "full_path": "hello_world::PublicStructure" } - }, - { - "members": [], - "item_data": { - "name": "PublicCrateStructure", - "doc": "Public crate struct", - "signature": "pub(crate) struct PublicCrateStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PublicCrateStructure" - } - }, - { - "members": [], - "item_data": { - "name": "PrivateStructure", - "doc": "Private struct", - "signature": "struct PrivateStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", - "full_path": "hello_world::PrivateStructure" - } } ], "enums": [ @@ -925,42 +194,6 @@ "signature": "pub enum PublicEnum {\n PUBLIC_VARIANT,\n}", "full_path": "hello_world::PublicEnum" } - }, - { - "variants": [ - { - "item_data": { - "name": "PUBLIC_VARIANT", - "doc": "Public enum variant", - "signature": "PUBLIC_VARIANT", - "full_path": "hello_world::PublicCrateEnum::PUBLIC_VARIANT" - } - } - ], - "item_data": { - "name": "PublicCrateEnum", - "doc": "Public crate enum", - "signature": "pub(crate) enum PublicCrateEnum {\n PUBLIC_VARIANT,\n}", - "full_path": "hello_world::PublicCrateEnum" - } - }, - { - "variants": [ - { - "item_data": { - "name": "PRIVATE_VARIANT", - "doc": "Private enum variant", - "signature": "PRIVATE_VARIANT", - "full_path": "hello_world::PrivateEnum::PRIVATE_VARIANT" - } - } - ], - "item_data": { - "name": "PrivateEnum", - "doc": "Private enum", - "signature": "enum PrivateEnum {\n PRIVATE_VARIANT,\n}", - "full_path": "hello_world::PrivateEnum" - } } ], "type_aliases": [], diff --git a/extensions/scarb-doc/tests/data/json_private_items_included.json b/extensions/scarb-doc/tests/data/json_private_items_included.json index e8e30e39b..4427dab5a 100644 --- a/extensions/scarb-doc/tests/data/json_private_items_included.json +++ b/extensions/scarb-doc/tests/data/json_private_items_included.json @@ -717,7 +717,7 @@ ], "item_data": { "name": "PublicCrateParentStructure", - "doc": "Parent publi crate struct", + "doc": "Parent public crate struct", "signature": "pub(crate) struct PublicCrateParentStructure {\n pub public_field: felt252,\n pub(crate) public_crate_field: felt252,\n private_field: felt252,\n}", "full_path": "hello_world::PublicParent::PublicCrateParentStructure" }