Skip to content

Commit

Permalink
Standardize the doc tags
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Mar 25, 2024
1 parent 3796e59 commit ba083ad
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions crates/re_types/definitions/rerun/archetypes/image.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace rerun.archetypes;
///
/// Rerun also supports compressed image encoded as JPEG, N12, and YUY2.
/// Using these formats can save a lot of bandwidth and memory.
/// \python To compress an image, use [`rerun.Image.compress`][].
/// \python To pass in an already encoded image, use [`rerun.ImageEncoded`][].
/// \rust See [`crate::components::TensorData`] for more.
/// \py To compress an image, use [`rerun.Image.compress`][].
/// \py To pass in an already encoded image, use [`rerun.ImageEncoded`][].
/// \rs See [`crate::components::TensorData`] for more.
/// \cpp See [`rerun::datatypes::TensorBuffer`] for more.
///
/// \cpp Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/definitions/rerun/archetypes/points2d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ table Points2D (

/// Optional colors for the points.
///
/// \python The colors are interpreted as RGB or RGBA in sRGB gamma-space,
/// \python As either 0-1 floats or 0-255 integers, with separate alpha.
/// \py The colors are interpreted as RGB or RGBA in sRGB gamma-space,
/// \py As either 0-1 floats or 0-255 integers, with separate alpha.
colors: [rerun.components.Color] ("attr.rerun.component_recommended", nullable, order: 2100);

// --- Optional ---
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/definitions/rerun/archetypes/points3d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ table Points3D (

/// Optional colors for the points.
///
/// \python The colors are interpreted as RGB or RGBA in sRGB gamma-space,
/// \python As either 0-1 floats or 0-255 integers, with separate alpha.
/// \py The colors are interpreted as RGB or RGBA in sRGB gamma-space,
/// \py As either 0-1 floats or 0-255 integers, with separate alpha.
colors: [rerun.components.Color] ("attr.rerun.component_recommended", nullable, order: 2100);

// --- Optional ---
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@ fn quote_field_docs(field: &ObjectField) -> TokenStream {
}

fn lines_from_docs(docs: &Docs) -> Vec<String> {
let mut lines = docs.doc_lines_for_untagged_and(&["cpp", "c++"]);
let mut lines = docs.doc_lines_for_untagged_and("cpp");

let required = true;
let examples = collect_snippets_for_api_docs(docs, "cpp", required).unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn index_page(kind: ObjectKind, order: u64, prelude: &str, objects: &[&Object])
fn object_page(reporter: &Reporter, object: &Object, object_map: &ObjectMap) -> String {
let is_unreleased = object.is_attr_set(crate::ATTR_DOCS_UNRELEASED);

let top_level_docs = object.docs.doc_lines_for_untagged_and(&[]);
let top_level_docs = object.docs.untagged();

if top_level_docs.is_empty() {
reporter.error(&object.virtpath, &object.fqname, "Undocumented object");
Expand Down
8 changes: 4 additions & 4 deletions crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ fn quote_obj_docs(obj: &Object) -> String {
}

fn lines_from_docs(docs: &Docs) -> Vec<String> {
let mut lines = docs.doc_lines_for_untagged_and(&["py", "python"]);
let mut lines = docs.doc_lines_for_untagged_and("py");

let examples = collect_snippets_for_api_docs(docs, "py", true).unwrap();
if !examples.is_empty() {
Expand Down Expand Up @@ -1208,7 +1208,7 @@ fn quote_doc_from_fields(objects: &Objects, fields: &Vec<ObjectField>) -> String
let mut lines = vec!["Must be one of:".to_owned(), String::new()];

for field in fields {
let mut content = field.docs.doc_lines_for_untagged_and(&["py", "python"]);
let mut content = field.docs.doc_lines_for_untagged_and("py");
for line in &mut content {
if line.starts_with(char::is_whitespace) {
line.remove(0);
Expand Down Expand Up @@ -1250,7 +1250,7 @@ fn quote_union_kind_from_fields(fields: &Vec<ObjectField>) -> String {
let mut lines = vec!["Possible values:".to_owned(), String::new()];

for field in fields {
let mut content = field.docs.doc_lines_for_untagged_and(&["py", "python"]);
let mut content = field.docs.doc_lines_for_untagged_and("py");
for line in &mut content {
if line.starts_with(char::is_whitespace) {
line.remove(0);
Expand Down Expand Up @@ -1950,7 +1950,7 @@ fn quote_init_method(
obj.fields
.iter()
.filter_map(|field| {
let doc_content = field.docs.doc_lines_for_untagged_and(&["py", "python"]);
let doc_content = field.docs.doc_lines_for_untagged_and("py");
if doc_content.is_empty() {
if !field.is_testing() && obj.fields.len() > 1 {
reporter.error(
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/rust/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ fn quote_obj_docs(reporter: &Reporter, obj: &Object) -> TokenStream {
}

fn doc_as_lines(reporter: &Reporter, virtpath: &str, fqname: &str, docs: &Docs) -> Vec<String> {
let mut lines = docs.doc_lines_for_untagged_and(&["rs", "rust"]);
let mut lines = docs.doc_lines_for_untagged_and("rs");

let examples = collect_snippets_for_api_docs(docs, "rs", true)
.map_err(|err| reporter.error(virtpath, fqname, err))
Expand Down
32 changes: 20 additions & 12 deletions crates/re_types_builder/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ impl Docs {
let mut tagged_docs = BTreeMap::new();

for cur_tag in all_tags {
assert!(
matches!(cur_tag.as_str(), "example" | "py" | "rs" | "cpp"),
"Unsupported tag: \\{cur_tag}"
);

tagged_docs.insert(
cur_tag.clone(),
tagged_lines
Expand Down Expand Up @@ -152,21 +157,24 @@ impl Docs {
}
}

/// Get all doc lines that are untagged, or match any of the given tags.
/// Get all doc lines that are untagged.
pub fn untagged(&self) -> Vec<String> {
self.doc_lines_for_untagged_and("")
}

/// Get all doc lines that are untagged, or match the given tag.
///
/// For instance, pass `["py"]` to get all lines that are untagged or starta with `"\python"`.
pub fn doc_lines_for_untagged_and(&self, tags: &[&str]) -> Vec<String> {
/// For instance, pass `"py"` to get all lines that are untagged or starta with `"\py"`.
pub fn doc_lines_for_untagged_and(&self, tag: &str) -> Vec<String> {
let mut lines = self.doc.clone();

for tag in tags {
lines.extend(
self.tagged_docs
.get(*tag)
.unwrap_or(&Vec::new())
.iter()
.cloned(),
);
}
lines.extend(
self.tagged_docs
.get(tag)
.unwrap_or(&Vec::new())
.iter()
.cloned(),
);

// NOTE: remove duplicated blank lines.
lines.dedup();
Expand Down

0 comments on commit ba083ad

Please sign in to comment.