Skip to content

fix(lsp): read self.context_state instead of stale local variable in _context_get_or_load#5747

Open
jthurlburt wants to merge 1 commit intoSQLMesh:mainfrom
jthurlburt:fix/lsp-stale-context-state
Open

fix(lsp): read self.context_state instead of stale local variable in _context_get_or_load#5747
jthurlburt wants to merge 1 commit intoSQLMesh:mainfrom
jthurlburt:fix/lsp-stale-context-state

Conversation

@jthurlburt
Copy link
Copy Markdown

Summary

  • _context_get_or_load captures self.context_state into local variable state at line 1065
  • After _create_lsp_context() or _ensure_context_for_document() successfully updates self.context_state to ContextLoaded, the final check at line 1077 reads the stale local state (still NoContext) instead of self.context_state
  • This causes the method to always raise RuntimeError("Context failed to load") on the first didOpen, even when context loading succeeds

Impact

The LSP logs "Loaded SQLMesh Context" then immediately crashes on the first textDocument/didOpen. In VS Code, this puts the extension client into a permanent "Client got disposed and can't be restarted" state. Affects both the specified_paths code path (via initializationOptions.project_paths) and the _ensure_context_for_document fallback path.

Fix

Read self.context_state instead of the stale local state variable on lines 1077-1078.

Test plan

  • Verified fix locally on 0.231.0 and 0.232.0 — LSP hover, go-to-definition, references, and diagnostics all work after patch
  • make style passes (ruff, ruff-format, mypy, valid migrations)
  • Confirmed bug is present on upstream main

…_context_get_or_load

_context_get_or_load captures self.context_state into a local variable
`state` at the top of the method. After _create_lsp_context() or
_ensure_context_for_document() successfully updates self.context_state
to ContextLoaded, the final check on line 1077 reads the stale local
`state` (still NoContext) instead of self.context_state.

This causes the method to always raise RuntimeError("Context failed to
load") on the first didOpen, even when context loading succeeds. The
LSP logs "Loaded SQLMesh Context" then immediately crashes. In VS Code,
this puts the client into a permanent "Client got disposed and can't be
restarted" state.

Signed-off-by: jthurlburt <jthurlburt818@gmail.com>
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.

1 participant