Skip to content

Commit 04201bc

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

3 files changed

Lines changed: 30 additions & 9 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

vscode/extension/tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { _electron as electron, Page } from '@playwright/test'
55

66
// Absolute path to the VS Code executable you downloaded in step 1.
77
export const VS_CODE_EXE = fs.readJsonSync(
8-
'.vscode-test/paths.json',
8+
path.join(__dirname, '..', '.vscode-test', 'paths.json'),
99
).executablePath
1010
// Where your extension lives on disk
1111
export const EXT_PATH = path.resolve(__dirname, '..')

vscode/react/src/pages/lineage.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ function Lineage() {
7373
const { on } = useEventBus()
7474
const queryClient = useQueryClient()
7575

76-
const { data: models, isLoading: isLoadingModels } = useApiModels()
76+
const { data: models, isLoading: isLoadingModels, error } = useApiModels()
7777
const rpc = useRpc()
78+
7879
React.useEffect(() => {
7980
const fetchFirstTimeModelIfNotSet = async (
8081
models: Model[],
@@ -143,6 +144,19 @@ function Lineage() {
143144
}
144145
}, [on, queryClient, modelsRecord])
145146

147+
console.log(
148+
'thigns',
149+
isLoadingModels,
150+
models,
151+
modelsRecord,
152+
selectedModel,
153+
error,
154+
)
155+
156+
if (error) {
157+
return <div>Error: {JSON.stringify(error.message)}</div>
158+
}
159+
146160
if (
147161
isLoadingModels ||
148162
models === undefined ||

0 commit comments

Comments
 (0)