Skip to content

Commit

Permalink
rune::doc: Fix rendering of conflicting hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 28, 2024
1 parent ce27ceb commit 7a35743
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
34 changes: 21 additions & 13 deletions crates/rune/src/doc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ pub(crate) fn build(
css.try_push(runedoc_css)?;

// Collect an ordered set of modules, so we have a baseline of what to render when.
let mut initial = VecDeque::new();
let mut initial = Vec::new();
let mut initial_seen = HashSet::new();

for item in context.iter_modules() {
let item = item?;
Expand All @@ -143,9 +144,15 @@ pub(crate) fn build(
.find(|m| matches!(&m.kind, Kind::Module))
.with_context(|| anyhow!("Missing meta for {item}"))?;

initial.try_push_back((Build::Module, meta))?;
if !initial_seen.try_insert(meta.hash)? {
continue;
}

initial.try_push((Build::Module, meta))?;
}

initial.sort_by_key(|(_, meta)| meta.item);

let search_index = RelativePath::new("index.js");
let root_index = RelativePath::new("index.html");

Expand All @@ -172,49 +179,46 @@ pub(crate) fn build(

let mut modules = Vec::new();
let mut builders = Vec::new();

let mut visited = HashSet::new();

while let Some((build, meta)) = queue.pop_front() {
if !visited.try_insert(meta.hash)? {
if !visited.try_insert((build, meta.hash))? {
tracing::error!(?build, ?meta.item, "Already visited");
continue;
}

cx.set_path(meta)?;

tracing::trace!(?build, ?meta.item, ?cx.state.path, "Building");

match build {
Build::Type => {
cx.set_path(meta)?;
let (builder, items) = self::type_::build(&mut cx, "Type", "type", meta)?;
builders.try_push(builder)?;
cx.index.try_extend(items)?;
}
Build::Trait => {
cx.set_path(meta)?;
let (builder, items) = self::type_::build(&mut cx, "Trait", "trait", meta)?;
builders.try_push(builder)?;
cx.index.try_extend(items)?;
}
Build::Struct => {
cx.set_path(meta)?;
let (builder, index) = self::type_::build(&mut cx, "Struct", "struct", meta)?;
builders.try_push(builder)?;
cx.index.try_extend(index)?;
}
Build::Enum => {
cx.set_path(meta)?;
let (builder, index) = self::type_::build(&mut cx, "Enum", "enum", meta)?;
builders.try_push(builder)?;
cx.index.try_extend(index)?;
}
Build::Macro => {
cx.set_path(meta)?;
builders.try_push(build_macro(&mut cx, meta)?)?;
}
Build::Function => {
cx.set_path(meta)?;
builders.try_push(build_function(&mut cx, meta)?)?;
}
Build::Module => {
cx.set_path(meta)?;
builders.try_push(module(&mut cx, meta, &mut queue)?)?;
modules.try_push((meta.item, cx.state.path.clone()))?;
}
Expand Down Expand Up @@ -813,6 +817,7 @@ impl<'m> Ctxt<'_, 'm> {
}
}

#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
enum Build {
Type,
Struct,
Expand Down Expand Up @@ -999,9 +1004,12 @@ fn module<'m>(
let mut traits = Vec::new();

for (_, name) in cx.context.iter_components(meta.item)? {
let lookup_item = meta.item.join([name])?;
let item = meta.item.join([name])?;
tracing::trace!(?item, "Looking up");

for m in cx.context.meta(&item)? {
tracing::trace!(?item, ?m.kind, "Found");

for m in cx.context.meta(&lookup_item)? {
match m.kind {
Kind::Type { .. } => {
queue.try_push_front((Build::Type, m))?;
Expand Down
7 changes: 5 additions & 2 deletions crates/rune/src/modules/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ fn round(this: f64) -> f64 {
this.round()
}

/// Test two integers for partial equality.
/// Clone a `f64`.
///
/// Note that since the type is copy, cloning has the same effect as assigning
/// it.
///
/// # Examples
///
Expand All @@ -392,7 +395,7 @@ fn round(this: f64) -> f64 {
/// a += 1.0;
///
/// assert_eq!(a, 6.0);
/// assert_eq!(b, 6.0);
/// assert_eq!(b, 5.0);
/// assert_eq!(c, 5.0);
/// ```
#[rune::function(keep, instance, protocol = CLONE)]
Expand Down
7 changes: 5 additions & 2 deletions crates/rune/src/modules/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ fn is_negative(this: i64) -> bool {
i64::is_negative(this)
}

/// Test two integers for partial equality.
/// Clone a `i64`.
///
/// Note that since the type is copy, cloning has the same effect as assigning
/// it.
///
/// # Examples
///
Expand All @@ -542,7 +545,7 @@ fn is_negative(this: i64) -> bool {
/// a += 1;
///
/// assert_eq!(a, 6);
/// assert_eq!(b, 6);
/// assert_eq!(b, 5);
/// assert_eq!(c, 5);
/// ```
#[rune::function(keep, instance, protocol = CLONE)]
Expand Down

0 comments on commit 7a35743

Please sign in to comment.