Skip to content

Commit ba90166

Browse files
authored
feat(vscode): initialize on python as well (#4343)
1 parent 7530c3c commit ba90166

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

sqlmesh/lsp/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@ def __init__(
4040
def _register_features(self) -> None:
4141
"""Register LSP features on the internal LanguageServer instance."""
4242

43+
@self.server.feature(types.INITIALIZE)
44+
def initialize(ls: LanguageServer, params: types.InitializeParams) -> None:
45+
"""Initialize the server when the client connects."""
46+
try:
47+
if params.workspace_folders:
48+
# Try to find a SQLMesh config file in any workspace folder (only at the root level)
49+
for folder in params.workspace_folders:
50+
folder_path = Path(self._uri_to_path(folder.uri))
51+
# Only check for config files directly in the workspace directory
52+
for ext in ("py", "yml", "yaml"):
53+
config_path = folder_path / f"config.{ext}"
54+
if config_path.exists():
55+
try:
56+
# Use user-provided instantiator to build the context
57+
created_context = self.context_class(paths=[folder_path])
58+
self.lsp_context = LSPContext(created_context)
59+
ls.show_message(
60+
f"Loaded SQLMesh context from {config_path}",
61+
types.MessageType.Info,
62+
)
63+
return # Exit after successfully loading any config
64+
except Exception as e:
65+
ls.show_message(
66+
f"Error loading context from {config_path}: {e}",
67+
types.MessageType.Warning,
68+
)
69+
except Exception as e:
70+
ls.show_message(f"Error initializing SQLMesh context: {e}", types.MessageType.Error)
71+
4372
@self.server.feature(ALL_MODELS_FEATURE)
4473
def all_models(ls: LanguageServer, params: AllModelsRequest) -> AllModelsResponse:
4574
try:

vscode/extension/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"Other"
1818
],
1919
"activationEvents": [
20-
"onLanguage:sql"
20+
"onLanguage:sql",
21+
"onLanguage:python"
2122
],
2223
"extensionKind": [
2324
"workspace"

0 commit comments

Comments
 (0)