Skip to content

Commit d34d24c

Browse files
committed
fix(lsp): read self.context_state instead of stale local variable in _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>
1 parent 8f092ac commit d34d24c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sqlmesh/lsp/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,8 @@ def _context_get_or_load(self, document_uri: t.Optional[URI] = None) -> LSPConte
10741074
loaded_sqlmesh_message(self.server)
10751075
else:
10761076
self._ensure_context_for_document(document_uri)
1077-
if isinstance(state, ContextLoaded):
1078-
return state.lsp_context
1077+
if isinstance(self.context_state, ContextLoaded):
1078+
return self.context_state.lsp_context
10791079
raise RuntimeError("Context failed to load")
10801080

10811081
def _ensure_context_for_document(

0 commit comments

Comments
 (0)