Skip to main content

dsl_completion/
render.rs

1//! Markdown renderers for table and column completion items.
2//!
3//! Keyword / type / function documentation is delegated to
4//! [`dsl_knowledge::render_markdown`] so we have one canonical source of
5//! truth for those bodies.
6
7use dsl_catalog::{Column, Table, display_type};
8
9pub fn table(t: &Table) -> String {
10  let mut s = format!("**table** `{}.{}`\n\n", t.schema, t.name);
11  if t.columns.is_empty() {
12    s.push_str("_no columns cached -- run :DBRefresh after switching connections_\n");
13    return s;
14  }
15  s.push_str("| column | type |\n");
16  s.push_str("|--------|------|\n");
17  for c in &t.columns {
18    s.push_str(&format!("| `{}` | `{}` |\n", c.name, display_type(&c.data_type)));
19  }
20  s
21}
22
23pub fn column(t: &Table, c: &Column) -> String {
24  // Blank lines between fields so markdown renders them as separate
25  // paragraphs instead of collapsing onto one line.
26  format!(
27    "**column** `{}.{}.{}`\n\n\
28         - **type:** `{}`\n\
29         - **nullable:** `{}`\n",
30    t.schema,
31    t.name,
32    c.name,
33    display_type(&c.data_type),
34    c.nullable
35  )
36}