Skip to content

Commit f26352a

Browse files
committed
temp [ci skip]
1 parent 502d9e0 commit f26352a

File tree

2 files changed

+56
-27
lines changed

2 files changed

+56
-27
lines changed

sqlmesh/core/loader.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def _load(path: Path) -> t.List[Model]:
349349
for row in YAML().load(file.read())
350350
]
351351
except Exception as ex:
352-
raise ConfigError(self._failed_to_load_model_error(path, ex))
352+
raise ConfigError(self._failed_to_load_model_error(path, ex), path)
353353

354354
for path in paths_to_load:
355355
self._track_file(path)
@@ -363,7 +363,8 @@ def _load(path: Path) -> t.List[Model]:
363363
raise ConfigError(
364364
self._failed_to_load_model_error(
365365
path, f"Duplicate external model name: '{model.name}'."
366-
)
366+
),
367+
path
367368
)
368369
models[model.fqn] = model
369370

@@ -375,7 +376,8 @@ def _load(path: Path) -> t.List[Model]:
375376
raise ConfigError(
376377
self._failed_to_load_model_error(
377378
path, f"Duplicate external model name: '{model.name}'."
378-
)
379+
),
380+
path,
379381
)
380382
models.update({model.fqn: model})
381383

@@ -402,13 +404,13 @@ def _load_requirements(self) -> t.Tuple[t.Dict[str, str], t.Set[str]]:
402404
args = [k.strip() for k in line.split("==")]
403405
if len(args) != 2:
404406
raise ConfigError(
405-
f"Invalid lock file entry '{line.strip()}'. Only 'dep==ver' is supported"
407+
f"Invalid lock file entry '{line.strip()}'. Only 'dep==ver' is supported", requirements_path
406408
)
407409
dep, ver = args
408410
other_ver = requirements.get(dep, ver)
409411
if ver != other_ver:
410412
raise ConfigError(
411-
f"Conflicting requirement {dep}: {ver} != {other_ver}. Fix your {c.REQUIREMENTS} file."
413+
f"Conflicting requirement {dep}: {ver} != {other_ver}. Fix your {c.REQUIREMENTS} file.", requirements_path
412414
)
413415
requirements[dep] = ver
414416

@@ -619,13 +621,14 @@ def _load_sql_models(
619621
raise ConfigError(
620622
self._failed_to_load_model_error(
621623
path, f"Duplicate SQL model name: '{model.name}'."
622-
)
624+
),
625+
path
623626
)
624627
elif model.enabled:
625628
model._path = path
626629
models[model.fqn] = model
627630
except Exception as ex:
628-
raise ConfigError(self._failed_to_load_model_error(path, ex))
631+
raise ConfigError(self._failed_to_load_model_error(path, ex), path)
629632

630633
return models
631634

@@ -678,7 +681,7 @@ def _load_python_models(
678681
if model.enabled:
679682
models[model.fqn] = model
680683
except Exception as ex:
681-
raise ConfigError(self._failed_to_load_model_error(path, ex))
684+
raise ConfigError(self._failed_to_load_model_error(path, ex), path)
682685

683686
finally:
684687
model_registry._dialect = None
@@ -782,7 +785,7 @@ def _load_metrics(self) -> UniqueKeyDict[str, MetricMeta]:
782785
metric = load_metric_ddl(expression, path=path, dialect=dialect)
783786
metrics[metric.name] = metric
784787
except SqlglotError as ex:
785-
raise ConfigError(f"Failed to parse metric definitions at '{path}': {ex}.")
788+
raise ConfigError(f"Failed to parse metric definitions at '{path}': {ex}.", path)
786789

787790
return metrics
788791

sqlmesh/lsp/main.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,13 @@ def initialize(ls: LanguageServer, params: types.InitializeParams) -> None:
321321
diagnostics = getattr(params.capabilities.text_document, "diagnostic", None)
322322
if diagnostics:
323323
self.client_supports_pull_diagnostics = True
324-
ls.log_trace("Client supports pull diagnostics")
324+
ls.show_message("Client supports pull diagnostics", types.MessageType.Info)
325325
else:
326326
self.client_supports_pull_diagnostics = False
327-
ls.log_trace("Client does not support pull diagnostics")
327+
ls.show_message("Client does not support pull diagnostics", types.MessageType.Info)
328328
else:
329329
self.client_supports_pull_diagnostics = False
330+
ls.show_message("Client capabilities not available", types.MessageType.Info)
330331

331332
if params.workspace_folders:
332333
# Store all workspace folders for later use
@@ -354,15 +355,22 @@ def initialize(ls: LanguageServer, params: types.InitializeParams) -> None:
354355
@self.server.feature(types.TEXT_DOCUMENT_DID_OPEN)
355356
def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> None:
356357
uri = URI(params.text_document.uri)
357-
context = self._context_get_or_load(ls, uri)
358-
359-
# Only publish diagnostics if client doesn't support pull diagnostics
360-
if not self.client_supports_pull_diagnostics:
361-
diagnostics = context.lint_model(uri)
362-
ls.publish_diagnostics(
363-
params.text_document.uri,
364-
LSPContext.diagnostics_to_lsp_diagnostics(diagnostics),
365-
)
358+
try:
359+
context = self._context_get_or_load(ls, uri)
360+
361+
# Only publish diagnostics if client doesn't support pull diagnostics
362+
if not self.client_supports_pull_diagnostics:
363+
diagnostics = context.lint_model(uri)
364+
ls.publish_diagnostics(
365+
params.text_document.uri,
366+
LSPContext.diagnostics_to_lsp_diagnostics(diagnostics),
367+
)
368+
except Exception as e:
369+
# Context loading failed, but don't crash the LSP
370+
ls.log_trace(f"Failed to load context in did_open: {e}")
371+
# Optionally publish empty diagnostics to clear any existing ones
372+
if not self.client_supports_pull_diagnostics:
373+
ls.publish_diagnostics(params.text_document.uri, [])
366374

367375
@self.server.feature(types.TEXT_DOCUMENT_DID_SAVE)
368376
def did_save(ls: LanguageServer, params: types.DidSaveTextDocumentParams) -> None:
@@ -769,7 +777,25 @@ def _get_diagnostics_for_uri(
769777
context = self._context_get_or_load(ls, uri)
770778
diagnostics = context.lint_model(uri)
771779
return LSPContext.diagnostics_to_lsp_diagnostics(diagnostics), 0
772-
except Exception:
780+
except Exception as e:
781+
# Check if there's a failed context state with configuration errors for this URI
782+
if isinstance(self.context_state, ContextFailed):
783+
error_message = self.context_state.error_message
784+
if isinstance(error_message, ConfigError) and error_message.location is not None:
785+
error_uri = URI.from_path(error_message.location)
786+
if error_uri.value == uri.value:
787+
# Return the configuration error as a diagnostic
788+
return [
789+
types.Diagnostic(
790+
range=types.Range(
791+
start=types.Position(line=0, character=0),
792+
end=types.Position(line=0, character=0),
793+
),
794+
message=str(error_message),
795+
severity=types.DiagnosticSeverity.Error,
796+
source="SQLMesh",
797+
)
798+
], 0
773799
return [], 0
774800

775801
def _context_get_or_load(
@@ -869,16 +895,17 @@ def _create_lsp_context(
869895
except Exception as e:
870896
# Only show the error message once
871897
if not self.has_raised_loading_error:
898+
location_info = f" at {e.location}" if isinstance(e, ConfigError) and e.location else ""
872899
self.server.show_message(
873-
f"Error creating context error type {type(e)}: {e.location} {e}",
900+
f"Error creating context error type {type(e)}: {e}{location_info}",
874901
types.MessageType.Error,
875902
)
876903
self.has_raised_loading_error = True
877904
error_message = e if isinstance(e, ConfigError) else str(e)
878-
if isinstance(e, ConfigError) and error_message.location is not None:
879-
self.server.show_message("hello", types.MessageType.Error)
880-
uri = URI.from_path(error_message.location)
881-
self.server.publish_diagnostics(
905+
if isinstance(e, ConfigError) and e.location is not None:
906+
uri = URI.from_path(e.location)
907+
ls.show_message(f"Publishing diagnostic to URI: {uri.value}", types.MessageType.Info)
908+
ls.publish_diagnostics(
882909
uri.value,
883910
[
884911
types.Diagnostic(
@@ -890,7 +917,6 @@ def _create_lsp_context(
890917
severity=types.DiagnosticSeverity.Error,
891918
)
892919
],
893-
str(1),
894920
)
895921

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

0 commit comments

Comments
 (0)