feat(lsp): return load time errors as diagnostics#4940
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds support for surfacing load‐time configuration errors as LSP diagnostics in the editor.
- Extends
ConfigErrorto carry a sourcePathand updates allraise_config_error/ConfigErrorcalls to include file locations. - Introduces
context_error_to_diagnostichelpers insqlmesh/lsp/errors.pyand wires them intosqlmesh/lsp/main.pyto convertConfigErrorinto LSP diagnostics. - Refactors versioning: moves
version_idout ofLSPContextinto the context‐state dataclasses (NoContext,ContextLoaded,ContextFailed).
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sqlmesh/utils/errors.py | Added location field to ConfigError and updated raise_config_error to pass file paths. |
| sqlmesh/lsp/main.py | Injected version_id into context‐state, integrated context_error_to_diagnostic, and catch ConfigError for per‐file diagnostics. |
| sqlmesh/lsp/errors.py | New error‐to‐diagnostic mapping functions. |
| sqlmesh/lsp/context.py | Removed old version_id from LSPContext class. |
| sqlmesh/core/model/common.py | Changed validate_extra_and_required_fields and callers to pass path. |
| sqlmesh/core/model/definition.py | Updated validate_extra_and_required_fields calls to include path. |
| sqlmesh/core/loader.py | Propagated path into all ConfigError raises. |
Comments suppressed due to low confidence (5)
sqlmesh/lsp/context.py:38
- The docstring still references a
version_idproperty that was removed fromLSPContext. Please update or remove this documentation block to avoid confusion.
This is a version ID for the context. It is used to track changes to the context. It can be used to
sqlmesh/lsp/main.py:230
- The early-return was changed to a
pass, so forNoContextthe method now continues and sends diagnostic refreshes even when no context exists. Consider restoring thereturnto avoid running downstream logic on a non-loaded context.
if isinstance(self.context_state, NoContext):
sqlmesh/core/loader.py:1015
- The error message no longer includes the file path, which makes debugging harder. Consider restoring it, e.g.,
f"Failed to load macro file '{path}': {e}".
raise ConfigError(f"Failed to load macro file: {e}", path)
sqlmesh/core/model/common.py:44
- You narrowed
pathfromstr | Pathto onlyPath. If callers ever pass a string, this will break. Consider allowing both types or converting internally.
path: t.Optional[Path] = None,
sqlmesh/lsp/main.py:780
- The previous broad
except Exception:block was removed, so non-config errors will now escape this method and may crash the server. Consider adding a catch-all fallback below this block to return an empty diagnostic list.
except ConfigError as config_error:
349d420 to
28bd988
Compare
- adds path in places to make this as possible with - refreshes well on typing
28bd988 to
8230759
Compare
| variables: t.Optional[t.Dict[str, t.Any]] = None, | ||
| used_variables: t.Optional[t.Set[str]] = None, | ||
| path: t.Optional[str | Path] = None, | ||
| path: t.Optional[Path] = None, |
Contributor
There was a problem hiding this comment.
why did you change this here? it seems a bit dangerous
Contributor
Author
There was a problem hiding this comment.
It makes downstream much simpler, and nothing seems to be passing in a string?
themisvaltinos
approved these changes
Jul 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.