-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add workspace support to forc-doc
#7268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7658c0e
to
a586bc5
Compare
CodSpeed Performance ReportMerging #7268 will not alter performanceComparing Summary
|
137dc56
to
84e0d8f
Compare
dafb3fd
to
02b5fea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good; however i think we can do without the pkg_manifest
and is_workspace
attributes on the DocContext
struct; example diff provided:
patch
diff --git a/forc-plugins/forc-doc/src/lib.rs b/forc-plugins/forc-doc/src/lib.rs
index 3a1b6346d..0fc3780f5 100644
--- a/forc-plugins/forc-doc/src/lib.rs
+++ b/forc-plugins/forc-doc/src/lib.rs
@@ -129,15 +129,24 @@ impl<'e> RenderPlan<'e> {
pub struct DocContext {
pub manifest: ManifestFile,
- pub pkg_manifest: Option<Box<PackageManifestFile>>,
pub doc_path: PathBuf,
pub engines: Engines,
pub build_plan: pkg::BuildPlan,
- pub is_workspace: bool,
pub workspace_name: String,
}
impl DocContext {
+ pub fn is_workspace(&self) -> bool {
+ matches!(self.manifest, ManifestFile::Workspace(_))
+ }
+
+ pub fn pkg_manifest(&self) -> Option<&PackageManifestFile> {
+ match &self.manifest {
+ ManifestFile::Package(pkg) => Some(pkg),
+ ManifestFile::Workspace(_) => None,
+ }
+ }
+
pub fn from_options(opts: &Command) -> Result<Self> {
// get manifest directory
let dir = if let Some(ref path) = opts.path {
@@ -155,15 +164,6 @@ impl DocContext {
.unwrap_or("workspace")
.to_string();
- // Handle Package vs Workspace manifests
- let is_workspace = matches!(&manifest, ManifestFile::Workspace(_));
-
- // Get package manifest for single packages (None for workspaces)
- let pkg_manifest = match &manifest {
- ManifestFile::Package(pkg_manifest) => Some(pkg_manifest.clone()),
- ManifestFile::Workspace(_) => None,
- };
-
// create doc path
let out_path = default_output_directory(manifest.dir());
let doc_dir = opts
@@ -181,7 +181,7 @@ impl DocContext {
let lock_path = manifest.lock_path()?;
// Check for empty workspaces
- if is_workspace && member_manifests.is_empty() {
+ if matches!(manifest, ManifestFile::Workspace(_)) && member_manifests.is_empty() {
bail!("Workspace contains no members");
}
@@ -196,23 +196,21 @@ impl DocContext {
Ok(Self {
manifest,
- pkg_manifest,
doc_path,
engines: Engines::default(),
build_plan,
- is_workspace,
workspace_name,
})
}
}
pub fn compile(ctx: &DocContext, opts: &Command) -> Result<impl Iterator<Item = Option<Programs>>> {
- if ctx.is_workspace {
+ if ctx.is_workspace() {
println_action_green(
"Compiling",
&format!("workspace ({})", ctx.manifest.dir().to_string_lossy()),
);
- } else if let Some(ref pkg_manifest) = ctx.pkg_manifest {
+ } else if let Some(pkg_manifest) = ctx.pkg_manifest() {
println_action_green(
"Compiling",
&format!(
@@ -247,7 +245,7 @@ pub fn compile_html(
let mut documented_libraries = Vec::new();
let raw_docs = if opts.no_deps {
- if let Some(ref pkg_manifest) = ctx.pkg_manifest {
+ if let Some(pkg_manifest) = ctx.pkg_manifest() {
// Single package mode
let Some(ty_program) = compile_results
.pop()
@@ -307,7 +305,7 @@ pub fn compile_html(
// Only document libraries that are workspace members
if matches!(ty_program.kind, TyProgramKind::Library { .. }) {
// Check if this package is a workspace member
- let is_workspace_member = if ctx.is_workspace {
+ let is_workspace_member = if ctx.is_workspace() {
ctx.manifest.member_manifests()?.iter().any(|(_, member)| {
member.project_name() == pkg_manifest_file.project_name()
})
@@ -339,7 +337,7 @@ pub fn compile_html(
};
// Create workspace index if this is a workspace
- if ctx.is_workspace && !documented_libraries.is_empty() {
+ if ctx.is_workspace() && !documented_libraries.is_empty() {
// Sort libraries alphabetically for consistent display
documented_libraries.sort_by(|a, b| a.name.cmp(&b.name));
create_workspace_index(
@@ -352,13 +350,13 @@ pub fn compile_html(
search::write_search_index(&ctx.doc_path, &raw_docs)?;
- let result = if ctx.is_workspace {
+ let result = if ctx.is_workspace() {
DocResult::Workspace {
name: ctx.workspace_name.clone(),
libraries: documented_libraries,
}
- } else if let Some(ref pkg_manifest) = ctx.pkg_manifest {
- DocResult::Package(pkg_manifest.clone())
+ } else if let Some(pkg_manifest) = ctx.pkg_manifest() {
+ DocResult::Package(Box::new(pkg_manifest.clone()))
} else {
unreachable!("Should have either workspace or package")
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Description
Adds workspace-level documentation support to
forc doc
. When invoked from the root of a workspace, it now generates a landing page that lists all member libraries along with their descriptions extracted directly from eachForc.toml
.Below is an example of the landing page generated when running
forc doc
at the root of thesway-libs
workspace.Closes #4103
Checklist
Breaking*
orNew Feature
labels where relevant.