Skip to content

Commit 7b43a35

Browse files
authored
fix(lsp): generate markdown including None (#4719)
1 parent af0d594 commit 7b43a35

2 files changed

Lines changed: 44 additions & 13 deletions

File tree

sqlmesh/lsp/description.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010
def generate_markdown_description(
1111
model: t.Union[SqlModel, ExternalModel, PythonModel, SeedModel],
1212
) -> t.Optional[str]:
13+
description = model.description
1314
columns = model.columns_to_types
1415
column_descriptions = model.column_descriptions
1516

16-
columns_table = (
17-
"\n".join(
18-
[
19-
f"| {column} | {column_type} | {column_descriptions.get(column, '')} |"
20-
for column, column_type in columns.items()
21-
]
22-
)
23-
if columns
24-
else ""
25-
)
17+
if columns is None:
18+
return description or None
2619

27-
table_header = "\n\n| Column | Type | Description |\n|--------|------|-------------|\n"
28-
return (
29-
f"{model.description}{table_header}{columns_table}" if columns_table else model.description
20+
columns_table = "\n".join(
21+
[
22+
f"| {column} | {column_type} | {column_descriptions.get(column, '')} |"
23+
for column, column_type in columns.items()
24+
]
3025
)
26+
27+
table_header = "| Column | Type | Description |\n|--------|------|-------------|\n"
28+
columns_text = table_header + columns_table
29+
return f"{description}\n\n{columns_text}" if description else columns_text

tests/lsp/test_description.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from sqlmesh.core.context import Context
2+
from sqlmesh.lsp.description import generate_markdown_description
3+
4+
5+
def test_model_description() -> None:
6+
context = Context(paths=["examples/sushi"])
7+
8+
model_no_description = context.get_model("sushi.order_items")
9+
markdown = generate_markdown_description(model_no_description)
10+
11+
assert markdown == (
12+
"| Column | Type | Description |\n"
13+
"|--------|------|-------------|\n"
14+
"| id | INT | |\n"
15+
"| order_id | INT | |\n"
16+
"| item_id | INT | |\n"
17+
"| quantity | INT | |\n"
18+
"| event_date | DATE | |"
19+
)
20+
21+
model_with_description = context.get_model("sushi.customers")
22+
markdown = generate_markdown_description(model_with_description)
23+
24+
assert markdown == (
25+
"Sushi customer data\n"
26+
"\n"
27+
"| Column | Type | Description |\n"
28+
"|--------|------|-------------|\n"
29+
"| customer_id | INT | customer_id uniquely identifies customers |\n"
30+
"| status | TEXT | |\n"
31+
"| zip | TEXT | |"
32+
)

0 commit comments

Comments
 (0)