Skip to content
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

Support \example in codegen #3378

Merged
merged 23 commits into from Sep 20, 2023
Merged

Support \example in codegen #3378

merged 23 commits into from Sep 20, 2023

Conversation

jprochazk
Copy link
Member

@jprochazk jprochazk commented Sep 20, 2023

What

  • Adds support for \example tag which replaces existing dance around examples included via \py, \rs, and \cpp
  • Fixes whitespace handling of examples
    • Examples were not being properly indented:
      ///```
      ///// Log some very simple points.
      ///
      /// #include <rerun.hpp>
      ///
      /// namespace rr = rerun;
      ///
      /// int main() {
      /// auto rec = rr::RecordingStream("rerun_example_points3d_simple");
      /// rec.connect("127.0.0.1:9876").throw_on_failure();
      ///
      /// rec.log("points", rr::Points3D({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}}));
      /// }
      ///```
    • This fixes that by delegating the whitespace handling to the specific language implementation.
      • Python removes leading whitespace for doc comments (but not examples, as those are already unindented)
      • Rust and C++ adds the leading whitespace as necessary
        • Doc content is left as is for the most part, with some special handling around converting #[doc="..."] tokens to /// ...
        • Examples are indented with 1 space
  • Added Context, which means we can now collect errors instead of failing immediately on the first one.
    • For example, removing a few of the .rs code examples:
      couldn't open code example "/home/jp/rerun-io/rerun/docs/code-examples/clear_simple.rs"
      couldn't open code example "/home/jp/rerun-io/rerun/docs/code-examples/image_simple.rs"
      couldn't open code example "/home/jp/rerun-io/rerun/docs/code-examples/box2d_simple.rs"
      couldn't open code example "/home/jp/rerun-io/rerun/docs/code-examples/depth_image_simple.rs"
      

Checklist

@jprochazk jprochazk added 📖 documentation Improvements or additions to documentation 🧑‍💻 dev experience developer experience (excluding CI) codegen/idl labels Sep 20, 2023
@jprochazk jprochazk marked this pull request as draft September 20, 2023 09:37
@jprochazk jprochazk marked this pull request as ready for review September 20, 2023 10:08
@emilk emilk self-requested a review September 20, 2023 10:16
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

It's a shame to loose the example titles, but otherwise LGTM.

Nice to get that whitespace correct!

crates/re_types/definitions/rerun/archetypes/boxes3d.fbs Outdated Show resolved Hide resolved
let example = example.trim();
let path = base_path.join(format!("{example}.{extension}"));
let contents = std::fs::read_to_string(&path)
.with_context(|| format!("couldn't open code example {path:?}"))?;
Copy link
Member

Choose a reason for hiding this comment

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

In wonder if we should really require that all languages has all examples. Some examples only makes sense in some languages, e.g. an example of how to convert a python PIL image to a Rerun image, or similar.

I think it makes sense to require that each language has at least one example per archetype though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was going to add stricter checks (check that each archetype has an \example), but decided to hold off for now. I think this would be good to discuss during standup

crates/re_types_builder/src/codegen/cpp/mod.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/codegen/cpp/mod.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/codegen/common.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/context.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/context.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/context.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/context.rs Outdated Show resolved Hide resolved
crates/re_types_builder/src/context.rs Outdated Show resolved Hide resolved
@jprochazk jprochazk merged commit 224dd71 into main Sep 20, 2023
26 checks passed
@jprochazk jprochazk deleted the jan/codegen-example-tag branch September 20, 2023 13:40
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Super!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen/idl 🧑‍💻 dev experience developer experience (excluding CI) 📖 documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants