Skip to content

Commit 8590b37

Browse files
committed
make work
1 parent 2b4acda commit 8590b37

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

sqlmesh/lsp/main.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
"""A Language Server Protocol (LSP) server for SQL with SQLMesh integration."""
33

4+
import itertools
45
import logging
56
import typing as t
67
from contextlib import suppress
@@ -16,7 +17,7 @@
1617

1718
logger = logging.getLogger(__name__)
1819

19-
GLOBAL_CONTEXT: t.Optional[Context,] = None
20+
GLOBAL_CONTEXT: t.Optional[Context] = None
2021
FILE_MAP: t.Dict[str, t.Union[Model, ModelAudit]] = {}
2122

2223

@@ -31,22 +32,16 @@ def ensure_context_for_document(document: TextDocument) -> TextDocument:
3132
GLOBAL_CONTEXT.load()
3233
if document.uri in FILE_MAP:
3334
return document
34-
else:
35-
for model in GLOBAL_CONTEXT._models.values():
36-
if model._path is None:
37-
continue
38-
path = model._path.resolve()
39-
if path == document.path:
40-
FILE_MAP[document.uri] = model
41-
return document
42-
for audit in GLOBAL_CONTEXT._audits.values():
43-
if audit._path is None:
44-
continue
45-
path = audit._path.resolve()
46-
if path == document.path:
47-
FILE_MAP[document.uri] = audit
48-
return document
49-
return document
35+
for model in itertools.chain(
36+
GLOBAL_CONTEXT._models.values(), GLOBAL_CONTEXT._audits.values()
37+
):
38+
if model._path is None:
39+
continue
40+
path = model._path.resolve()
41+
if path == document.path:
42+
FILE_MAP[document.uri] = model
43+
return document
44+
return document
5045

5146
# If there is no context, load the context and then call this function again
5247
path = Path(document.path).resolve()

0 commit comments

Comments
 (0)