Skip to content

feat(lsp): return load time errors as diagnostics#4940

Merged
benfdking merged 3 commits intomainfrom
working_on_small_pieces
Jul 9, 2025
Merged

feat(lsp): return load time errors as diagnostics#4940
benfdking merged 3 commits intomainfrom
working_on_small_pieces

Conversation

@benfdking
Copy link
Contributor

@benfdking benfdking commented Jul 9, 2025

  • adds path in places to make this as possible with
  • refreshes well on typing

image

@benfdking benfdking requested a review from Copilot July 9, 2025 10:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for surfacing load‐time configuration errors as LSP diagnostics in the editor.

  • Extends ConfigError to carry a source Path and updates all raise_config_error/ConfigError calls to include file locations.
  • Introduces context_error_to_diagnostic helpers in sqlmesh/lsp/errors.py and wires them into sqlmesh/lsp/main.py to convert ConfigError into LSP diagnostics.
  • Refactors versioning: moves version_id out of LSPContext into 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_id property that was removed from LSPContext. 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 for NoContext the method now continues and sends diagnostic refreshes even when no context exists. Consider restoring the return to 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 path from str | Path to only Path. 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:

@benfdking benfdking force-pushed the working_on_small_pieces branch from 349d420 to 28bd988 Compare July 9, 2025 10:37
- adds path in places to make this as possible with
- refreshes well on typing
@benfdking benfdking force-pushed the working_on_small_pieces branch from 28bd988 to 8230759 Compare July 9, 2025 10:38
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this here? it seems a bit dangerous

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes downstream much simpler, and nothing seems to be passing in a string?

@benfdking benfdking merged commit cccc5ea into main Jul 9, 2025
26 checks passed
@benfdking benfdking deleted the working_on_small_pieces branch July 9, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants