|
46 | 46 | FormatProjectRequest, |
47 | 47 | FormatProjectResponse, |
48 | 48 | CustomMethod, |
| 49 | + LIST_WORKSPACE_TESTS_FEATURE, |
| 50 | + ListWorkspaceTestsRequest, |
| 51 | + ListWorkspaceTestsResponse, |
| 52 | + LIST_DOCUMENT_TESTS_FEATURE, |
| 53 | + ListDocumentTestsRequest, |
| 54 | + ListDocumentTestsResponse, |
| 55 | + RUN_TEST_FEATURE, |
| 56 | + RunTestRequest, |
| 57 | + RunTestResponse, |
49 | 58 | ) |
50 | 59 | from sqlmesh.lsp.errors import ContextFailedError, context_error_to_diagnostic |
51 | 60 | from sqlmesh.lsp.helpers import to_lsp_range, to_sqlmesh_position |
@@ -127,11 +136,58 @@ def __init__( |
127 | 136 | API_FEATURE: self._custom_api, |
128 | 137 | SUPPORTED_METHODS_FEATURE: self._custom_supported_methods, |
129 | 138 | FORMAT_PROJECT_FEATURE: self._custom_format_project, |
| 139 | + LIST_WORKSPACE_TESTS_FEATURE: self._list_workspace_tests, |
| 140 | + LIST_DOCUMENT_TESTS_FEATURE: self._list_document_tests, |
| 141 | + RUN_TEST_FEATURE: self._run_test, |
130 | 142 | } |
131 | 143 |
|
132 | 144 | # Register LSP features (e.g., formatting, hover, etc.) |
133 | 145 | self._register_features() |
134 | 146 |
|
| 147 | + def _list_workspace_tests( |
| 148 | + self, |
| 149 | + ls: LanguageServer, |
| 150 | + params: ListWorkspaceTestsRequest, |
| 151 | + ) -> ListWorkspaceTestsResponse: |
| 152 | + """List all tests in the current workspace.""" |
| 153 | + try: |
| 154 | + context = self._context_get_or_load() |
| 155 | + tests = context.list_workspace_tests() |
| 156 | + return ListWorkspaceTestsResponse(tests=tests) |
| 157 | + except Exception as e: |
| 158 | + ls.log_trace(f"Error listing workspace tests: {e}") |
| 159 | + return ListWorkspaceTestsResponse(tests=[]) |
| 160 | + |
| 161 | + def _list_document_tests( |
| 162 | + self, |
| 163 | + ls: LanguageServer, |
| 164 | + params: ListDocumentTestsRequest, |
| 165 | + ) -> ListDocumentTestsResponse: |
| 166 | + """List tests for a specific document.""" |
| 167 | + try: |
| 168 | + uri = URI(params.textDocument.uri) |
| 169 | + context = self._context_get_or_load(uri) |
| 170 | + tests = context.get_document_tests(uri) |
| 171 | + return ListDocumentTestsResponse(tests=tests) |
| 172 | + except Exception as e: |
| 173 | + ls.log_trace(f"Error listing document tests: {e}") |
| 174 | + return ListDocumentTestsResponse(tests=[]) |
| 175 | + |
| 176 | + def _run_test( |
| 177 | + self, |
| 178 | + ls: LanguageServer, |
| 179 | + params: RunTestRequest, |
| 180 | + ) -> RunTestResponse: |
| 181 | + """Run a specific test.""" |
| 182 | + try: |
| 183 | + uri = URI(params.textDocument.uri) |
| 184 | + context = self._context_get_or_load(uri) |
| 185 | + result = context.run_test(uri, params.testName) |
| 186 | + return result |
| 187 | + except Exception as e: |
| 188 | + ls.log_trace(f"Error running test: {e}") |
| 189 | + return RunTestResponse(success=False, response_error=str(e)) |
| 190 | + |
135 | 191 | # All the custom LSP methods are registered here and prefixed with _custom |
136 | 192 | def _custom_all_models(self, ls: LanguageServer, params: AllModelsRequest) -> AllModelsResponse: |
137 | 193 | uri = URI(params.textDocument.uri) |
|
0 commit comments