Skip to content

Commit 27a2fae

Browse files
committed
fix(lsp): context is singleton in vscode
1 parent 7b43a35 commit 27a2fae

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

sqlmesh/lsp/main.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ def _create_lsp_context(self, paths: t.List[Path]) -> t.Optional[LSPContext]:
106106
A new LSPContext instance wrapping the created context, or None if creation fails
107107
"""
108108
try:
109-
context = self.context_class(paths=paths)
110-
lsp_context = LSPContext(context)
111-
self.lsp_context = lsp_context
112-
return lsp_context
109+
context = None
110+
if self.lsp_context is None:
111+
context = self.context_class(paths=paths)
112+
else:
113+
self.lsp_context.context.load()
114+
context = self.lsp_context.context
115+
self.lsp_context = LSPContext(context)
116+
return self.lsp_context
113117
except Exception as e:
114118
self.server.log_trace(f"Error creating context: {e}")
115119
return None
@@ -293,8 +297,12 @@ def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> Non
293297

294298
@self.server.feature(types.TEXT_DOCUMENT_DID_CHANGE)
295299
def did_change(ls: LanguageServer, params: types.DidChangeTextDocumentParams) -> None:
300+
if self.lsp_context is None:
301+
current_path = Path.cwd()
302+
self._ensure_context_in_folder(current_path)
296303
uri = URI(params.text_document.uri)
297304
context = self._context_get_or_load(uri)
305+
298306
models = context.map[uri.to_path()]
299307
if models is None or not isinstance(models, ModelTarget):
300308
return
@@ -731,9 +739,8 @@ def _ensure_context_for_document(
731739
for a config.py or config.yml file in the parent directories.
732740
"""
733741
if self.lsp_context is not None:
734-
context = self.lsp_context
735-
context.context.load() # Reload or refresh context
736-
self.lsp_context = LSPContext(context.context)
742+
self.lsp_context.context.load()
743+
self.lsp_context = LSPContext(self.lsp_context.context)
737744
return
738745

739746
# No context yet: try to find config and load it

0 commit comments

Comments
 (0)