Skip to content

Commit 502d9e0

Browse files
committed
feat(vscode): returning load errors to diagnostics
[ci skip]
1 parent 533aee0 commit 502d9e0

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

examples/sushi/models/customer_revenue_by_day.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ MODEL (
66
batch_size 10,
77
),
88
owner jen,
9+
owners test,
910
cron '@daily',
1011
dialect hive,
1112
tags expensive,
13+
tag sadf,
1214
grain (customer_id, event_date),
1315
);
1416

sqlmesh/core/model/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def validate_extra_and_required_fields(
265265
klass: t.Type[PydanticModel],
266266
provided_fields: t.Set[str],
267267
entity_name: str,
268+
path: t.Optional[Path] = None,
268269
) -> None:
269270
missing_required_fields = klass.missing_required_fields(provided_fields)
270271
if missing_required_fields:
@@ -293,7 +294,8 @@ def validate_extra_and_required_fields(
293294
similar_msg = "\n\n " + "\n ".join(similar) if similar else ""
294295

295296
raise_config_error(
296-
f"Invalid field name{'s' if len(extra_fields) > 1 else ''} present in the {entity_name}: {extra_field_names}{similar_msg}"
297+
f"Invalid field name{'s' if len(extra_fields) > 1 else ''} present in the {entity_name}: {extra_field_names}{similar_msg}",
298+
path,
297299
)
298300

299301

sqlmesh/core/model/definition.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,10 @@ def _create_model(
24342434
**kwargs: t.Any,
24352435
) -> Model:
24362436
validate_extra_and_required_fields(
2437-
klass, {"name", *kwargs} - {"grain", "table_properties"}, "MODEL block"
2437+
klass,
2438+
{"name", *kwargs} - {"grain", "table_properties"},
2439+
"MODEL block",
2440+
path,
24382441
)
24392442

24402443
for prop in PROPERTIES:

sqlmesh/lsp/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def _reload_context_and_publish_diagnostics(
287287
),
288288
)
289289

290-
# Only publish diagnostics if client doesn't support pull diagnostics
290+
# Only publish diagnostics if the client doesn't support pull
291+
# diagnostics
291292
if not self.client_supports_pull_diagnostics:
292293
diagnostics = self.context_state.lsp_context.lint_model(uri)
293294
ls.publish_diagnostics(
@@ -869,15 +870,15 @@ def _create_lsp_context(
869870
# Only show the error message once
870871
if not self.has_raised_loading_error:
871872
self.server.show_message(
872-
f"Error creating context: {e}",
873+
f"Error creating context error type {type(e)}: {e.location} {e}",
873874
types.MessageType.Error,
874875
)
875876
self.has_raised_loading_error = True
876-
self.server.log_trace(f"Error creating context: {e}")
877877
error_message = e if isinstance(e, ConfigError) else str(e)
878-
if isinstance(error_message, ConfigError) and error_message.location is not None:
878+
if isinstance(e, ConfigError) and error_message.location is not None:
879+
self.server.show_message("hello", types.MessageType.Error)
879880
uri = URI.from_path(error_message.location)
880-
ls.publish_diagnostics(
881+
self.server.publish_diagnostics(
881882
uri.value,
882883
[
883884
types.Diagnostic(
@@ -889,6 +890,7 @@ def _create_lsp_context(
889890
severity=types.DiagnosticSeverity.Error,
890891
)
891892
],
893+
str(1),
892894
)
893895

894896
# Store the error in context state such that later requests can

0 commit comments

Comments
 (0)