|
31 | 31 | RENDER_MODEL_FEATURE, |
32 | 32 | SUPPORTED_METHODS_FEATURE, |
33 | 33 | FORMAT_PROJECT_FEATURE, |
| 34 | + LIST_ENVIRONMENTS_FEATURE, |
| 35 | + PLAN_DIFF_FEATURE, |
34 | 36 | AllModelsRequest, |
35 | 37 | AllModelsResponse, |
36 | 38 | AllModelsForRenderRequest, |
|
43 | 45 | FormatProjectRequest, |
44 | 46 | FormatProjectResponse, |
45 | 47 | CustomMethod, |
| 48 | + ListEnvironmentsRequest, |
| 49 | + ListEnvironmentsResponse, |
| 50 | + PlanDiffRequest, |
| 51 | + PlanDiffResponse, |
| 52 | + PlanDiffEntry, |
46 | 53 | ) |
47 | 54 | from sqlmesh.lsp.hints import get_hints |
48 | 55 | from sqlmesh.lsp.reference import ( |
@@ -89,6 +96,8 @@ def __init__( |
89 | 96 | API_FEATURE: self._custom_api, |
90 | 97 | SUPPORTED_METHODS_FEATURE: self._custom_supported_methods, |
91 | 98 | FORMAT_PROJECT_FEATURE: self._custom_format_project, |
| 99 | + LIST_ENVIRONMENTS_FEATURE: self._custom_list_environments, |
| 100 | + PLAN_DIFF_FEATURE: self._custom_plan_diff, |
92 | 101 | } |
93 | 102 |
|
94 | 103 | # Register LSP features (e.g., formatting, hover, etc.) |
@@ -211,6 +220,37 @@ def _custom_api( |
211 | 220 |
|
212 | 221 | raise NotImplementedError(f"API request not implemented: {request.url}") |
213 | 222 |
|
| 223 | + def _custom_list_environments( |
| 224 | + self, ls: LanguageServer, params: ListEnvironmentsRequest |
| 225 | + ) -> ListEnvironmentsResponse: |
| 226 | + if self.lsp_context is None: |
| 227 | + current_path = Path.cwd() |
| 228 | + self._ensure_context_in_folder(current_path) |
| 229 | + if self.lsp_context is None: |
| 230 | + raise RuntimeError("No context found") |
| 231 | + |
| 232 | + envs = self.lsp_context.context._new_state_sync().get_environments_summary() |
| 233 | + return ListEnvironmentsResponse(environments=[e.name for e in envs]) |
| 234 | + |
| 235 | + def _custom_plan_diff(self, ls: LanguageServer, params: PlanDiffRequest) -> PlanDiffResponse: |
| 236 | + if self.lsp_context is None: |
| 237 | + current_path = Path.cwd() |
| 238 | + self._ensure_context_in_folder(current_path) |
| 239 | + if self.lsp_context is None: |
| 240 | + raise RuntimeError("No context found") |
| 241 | + |
| 242 | + plan = self.lsp_context.context.plan_builder( |
| 243 | + params.environment, |
| 244 | + skip_tests=True, |
| 245 | + skip_backfill=True, |
| 246 | + ).build() |
| 247 | + |
| 248 | + diffs = [ |
| 249 | + PlanDiffEntry(name=name, diff=plan.context_diff.text_diff(name)) |
| 250 | + for name in plan.context_diff.modified_snapshots |
| 251 | + ] |
| 252 | + return PlanDiffResponse(diffs=diffs) |
| 253 | + |
214 | 254 | def _custom_supported_methods( |
215 | 255 | self, ls: LanguageServer, params: SupportedMethodsRequest |
216 | 256 | ) -> SupportedMethodsResponse: |
|
0 commit comments