Skip to content

Commit

Permalink
Add support for nested submodules to forc doc (FuelLabs#4333)
Browse files Browse the repository at this point in the history
## Description
Sort of hacky, but this PR fixes the support for nested submodules. I've
opened FuelLabs#4371 as a follow up to fix this. It also fixes a bug I found
while working on this, which was merging modules of the same name, even
if they were in different folders.

[Screencast from 2023-03-28
17-44-07.webm](https://user-images.githubusercontent.com/57543709/228384162-f94249db-66d8-42dd-9c77-33a31b633a8b.webm)

## Checklist

- [x] I have linked to any relevant issues. Closes FuelLabs#3929 Closes FuelLabs#4370 
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
eureka-cpu authored Apr 1, 2023
1 parent 123c9e7 commit 95cb67d
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 187 deletions.
9 changes: 4 additions & 5 deletions forc-plugins/forc-doc/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sway_core::{
pub(crate) type Documentation = Vec<Document>;
/// A finalized Document ready to be rendered. We want to retain all
/// information including spans, fields on structs, variants on enums etc.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct Document {
pub(crate) module_info: ModuleInfo,
pub(crate) item_header: ItemHeader,
Expand Down Expand Up @@ -127,8 +127,7 @@ impl Document {
}
}
}
// if there is another submodule we need to go a level deeper
if let Some((_, submodule)) = typed_submodule.module.submodules.first() {
for (_, submodule) in &typed_submodule.module.submodules {
Document::from_ty_submodule(
decl_engine,
submodule,
Expand All @@ -152,10 +151,10 @@ impl Renderable for Document {
}
}

pub(crate) type ModulePrefix = String;
pub(crate) type ModulePrefixes = Vec<String>;
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub(crate) struct ModuleInfo {
pub(crate) module_prefixes: Vec<ModulePrefix>,
pub(crate) module_prefixes: ModulePrefixes,
pub(crate) attributes: Option<String>,
}
impl ModuleInfo {
Expand Down
289 changes: 107 additions & 182 deletions forc-plugins/forc-doc/src/render.rs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions forc-plugins/forc-doc/src/tests/data/nested_subdirs/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = 'core'
source = 'path+from-root-2E974E96B45CBA16'

[[package]]
name = 'nested_subdirs'
source = 'member'
dependencies = ['core']
8 changes: 8 additions & 0 deletions forc-plugins/forc-doc/src/tests/data/nested_subdirs/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "lib.sw"
license = "Apache-2.0"
name = "nested_subdirs"

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library;

mod sub_dir;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library;

mod folder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library;

mod lib_one;
mod lib_two;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library;

pub struct Foo {
foo: u32,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library;

pub enum Bar {
bar: u32,
}

0 comments on commit 95cb67d

Please sign in to comment.