(
w: &mut W,
mut properties: serde_json::Map<String, serde_json::Value>,
)
| 411 | } |
| 412 | |
| 413 | fn write_ast_node_from_object<W: Write>( |
| 414 | w: &mut W, |
| 415 | mut properties: serde_json::Map<String, serde_json::Value>, |
| 416 | ) -> Result { |
| 417 | let id: Option<i64> = properties.remove("id").and_then(|s| match s { |
| 418 | serde_json::Value::Null => None, |
| 419 | serde_json::Value::Number(n) if n.is_i64() => n.as_i64(), |
| 420 | _ => unreachable!("expected id to be int, got: {}", s), |
| 421 | }); |
| 422 | let span: Option<String> = properties.remove("span").and_then(|s| match s { |
| 423 | serde_json::Value::Null => None, |
| 424 | serde_json::Value::String(s) => Some(s), |
| 425 | _ => None, |
| 426 | // We previously used to error, but sqlparser now has a type that |
| 427 | // doesn't include spans, so we just ignore it. |
| 428 | // _ => unreachable!("expected span to be string, got: {}", s), |
| 429 | }); |
| 430 | let ty: Option<serde_json::Value> = properties.remove("ty"); |
| 431 | |
| 432 | let first_item = properties.into_iter().next(); |
| 433 | let (name, contents) = |
| 434 | first_item.unwrap_or_else(|| ("<empty>".into(), serde_json::Value::Null)); |
| 435 | |
| 436 | write!(w, r#"<details class=ast-node open tabindex=2>"#)?; |
| 437 | |
| 438 | { |
| 439 | write!(w, "<summary class=header>")?; |
| 440 | |
| 441 | let h2_id = id.map(|i| format!("id=ast-{i} ")).unwrap_or_default(); |
| 442 | write!(w, "<h2 {h2_id}class=clickable>{name}</h2>")?; |
| 443 | |
| 444 | if let Some(id) = id { |
| 445 | write!(w, r#"<span>id={id}</span>"#)?; |
| 446 | } |
| 447 | if let Some(span) = span { |
| 448 | write!(w, r#"<span class="span">{span}</span>"#)?; |
| 449 | } |
| 450 | if let Some(ty) = ty { |
| 451 | let ty_json = ty.to_string(); |
| 452 | if let Ok(ty) = serde_json::from_str::<pr::Ty>(&ty_json) { |
| 453 | let ty_prql = codegen::write_ty(&ty); |
| 454 | write!(w, r#"<span class="ty">{ty_prql}</span>"#)?; |
| 455 | } |
| 456 | } |
| 457 | write!(w, "</summary>")?; |
| 458 | } |
| 459 | |
| 460 | { |
| 461 | write!(w, r#"<content class="contents indent">"#)?; |
| 462 | write_json_ast_node(w, contents, true)?; |
| 463 | write!(w, "</content>")?; |
| 464 | } |
| 465 | |
| 466 | write!(w, "</details>") |
| 467 | } |
| 468 | |
| 469 | fn write_decl<W: Write>( |
| 470 | w: &mut W, |
no test coverage detected