Skip to content

Misc improvements - #49

Merged
Imberflur merged 22 commits into
mainfrom
misc-improvements-docs-tests
Oct 13, 2025
Merged

Misc improvements#49
Imberflur merged 22 commits into
mainfrom
misc-improvements-docs-tests

Conversation

@Imberflur

Copy link
Copy Markdown
Contributor

These are various changes I made while reading the code (or in response to notes I made while reading the code).

For various bits of behavior I wanted to understand and bugs I wanted confirm before fixing I added some new tests.

Summary of changes

Bug fixes

  • Fixed bug in reload_paths in certain cases where new files prefixed by existing paths would overwrite the existing file.
  • Fixed bug in reload_files where some files failing to load would lead to a mismatch in iteration over file IDs and file values.

Method reworks

  • Rename CtxNode::filter to CtxNode::iter_all_children and have the caller use Iterator::filter instead of taking a filter closure. This separates iterating all children and the filtering logic, which should make the logic more clear to readers.
  • Rename CtxNode::walk/walk_mut to CtxNode::node_at/node_at_mut and remove closure parameter. Instead return node reference that caller can use. Again this separate the concern of getting the node and doing things with it. In some cases this takes more lines, but it uses the Option methods familiar to many. Additionally, in one case this avoids needing to re-get the actual node.
  • Rename ref_kinds to refs_of_kind since it returns references of a specific kind rather than a list of kinds.

Misc

  • Documentation added to various methods and types.
  • Removed a few type aliases that were only used in a few places. IMO avoiding layers of indirection outweighs the benefits of aliases in these cases.
  • Minor improvements to bauble_test macro.
  • Remove unused default_uses parameter in value::register_assets.
  • Add TODOs to a couple places that may need further investigation.

…w files are introduced that are prefixed with the paths of existing files
since that is where it is used and it takes context as a parameter.
… testing if extra objects are produced over the expected values
@MavethGH MavethGH self-assigned this Sep 29, 2025
@hazelwiss hazelwiss self-assigned this Oct 6, 2025
Comment thread bauble/src/value/mod.rs Outdated
Comment thread bauble/src/value/symbols.rs Outdated
Comment thread bauble/src/context.rs
/// Returns the path that we got `Some` from and `R`.
///
/// Returns None if `path` doesn't exist.
/// Returns `None` if `path` doesn't exist or if all `visit`ed nodes produced `None`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated now that this returns a Result

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the inner walk_find_inner function was changed to return a result

@MavethGH MavethGH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No substantial issues that I can find. Just a few typos and documentation improvements.

@hazelwiss hazelwiss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah these changes look good to me too!

Comment thread bauble/src/context.rs

if let Some(redirect) = self.reference.redirect.as_ref()
&& let Some(mut reference) = root.walk(redirect.borrow(), |node| node.reference(root))
&& let Some(node) = root.node_at(redirect.borrow())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it ever be possible that a redirect leads to a node which is None? Seems like a case we might want to catch otherwise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to look into this. For reference, redirects are excusively used to implement default uses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it would be possible to add default uses that point to non-existent paths. I don't know how we want to handle that from a user standpoint though? Produce an error when building the Context? Perhaps this can be deferred to an issue, especially since the changes here don't modify the behavior for this case.

Also note that default uses apply to all namespaces, not just types . I'm not sure if that is intended.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#56

Comment thread bauble/src/context.rs
/// `path` doesn't need to be the path of a file, it can be the path of anything in a file.
///
/// Note, if a file `a` exists and a file `a::b::c` exists, `a::b` will get the ID of the file
/// at `a`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand the doc comment Note, if a file `a` exists and a file `a::b::c` exists, `a::b` will get the ID of the file at `a`. here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a file a::b::c exists, then a node will be created for b but this node will not be associated to a file necause there is no a::b file. walk_find will check the each parent node if the closure returns None for the node at the end of the provided path (in this example b). So it will return the file ID of a (if there is a file a).

If a::b::c didnt exist then b would not exist (as there is no file for it in this example).

When I discussed with Isse this behavior was at the time of writing to keep the option open for defining assets like foo::bar in-file without creating a foo submodule (or having some form of inline submodules).

Comment thread bauble/src/types.rs
Comment thread bauble/tests/integration.rs
@Imberflur
Imberflur merged commit e119a93 into main Oct 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants