Skip to content

Commit 2c1ed26

Browse files
authored
feat(lsp): custom methods always return errors (#4708)
1 parent 97407d7 commit 2c1ed26

File tree

4 files changed

+170
-139
lines changed

4 files changed

+170
-139
lines changed

sqlmesh/lsp/api.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
import typing as t
1111
from pydantic import field_validator
12-
from sqlmesh.utils.pydantic import PydanticModel
12+
from sqlmesh.lsp.custom import (
13+
CustomMethodRequestBaseClass,
14+
CustomMethodResponseBaseClass,
15+
)
1316
from web.server.models import LineageColumn, Model
1417

1518
API_FEATURE = "sqlmesh/api"
1619

1720

18-
class ApiRequest(PydanticModel):
21+
class ApiRequest(CustomMethodRequestBaseClass):
1922
"""
2023
Request to call the SQLMesh API.
2124
This is a generic request that can be used to call any API endpoint.
@@ -28,7 +31,11 @@ class ApiRequest(PydanticModel):
2831
body: t.Optional[t.Dict[str, t.Any]] = None
2932

3033

31-
class ApiResponseGetModels(PydanticModel):
34+
class BaseAPIResponse(CustomMethodResponseBaseClass):
35+
error: t.Optional[str] = None
36+
37+
38+
class ApiResponseGetModels(BaseAPIResponse):
3239
"""
3340
Response from the SQLMesh API for the get_models endpoint.
3441
"""
@@ -53,15 +60,15 @@ def sanitize_datetime_fields(cls, data: t.List[Model]) -> t.List[Model]:
5360
return data
5461

5562

56-
class ApiResponseGetLineage(PydanticModel):
63+
class ApiResponseGetLineage(BaseAPIResponse):
5764
"""
5865
Response from the SQLMesh API for the get_lineage endpoint.
5966
"""
6067

6168
data: t.Dict[str, t.List[str]]
6269

6370

64-
class ApiResponseGetColumnLineage(PydanticModel):
71+
class ApiResponseGetColumnLineage(BaseAPIResponse):
6572
"""
6673
Response from the SQLMesh API for the get_column_lineage endpoint.
6774
"""

sqlmesh/lsp/custom.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@
22
import typing as t
33
from sqlmesh.utils.pydantic import PydanticModel
44

5+
6+
class CustomMethodRequestBaseClass(PydanticModel):
7+
pass
8+
9+
10+
class CustomMethodResponseBaseClass(PydanticModel):
11+
# Prefixing, so guaranteed not to collide
12+
response_error: t.Optional[str] = None
13+
14+
515
ALL_MODELS_FEATURE = "sqlmesh/all_models"
616

717

8-
class AllModelsRequest(PydanticModel):
18+
class AllModelsRequest(CustomMethodRequestBaseClass):
919
"""
1020
Request to get all the models that are in the current project.
1121
"""
1222

1323
textDocument: types.TextDocumentIdentifier
1424

1525

16-
class AllModelsResponse(PydanticModel):
26+
class AllModelsResponse(CustomMethodResponseBaseClass):
1727
"""
1828
Response to get all the models that are in the current project.
1929
"""
@@ -26,7 +36,7 @@ class AllModelsResponse(PydanticModel):
2636
RENDER_MODEL_FEATURE = "sqlmesh/render_model"
2737

2838

29-
class RenderModelRequest(PydanticModel):
39+
class RenderModelRequest(CustomMethodRequestBaseClass):
3040
textDocumentUri: str
3141

3242

@@ -41,7 +51,7 @@ class RenderModelEntry(PydanticModel):
4151
rendered_query: str
4252

4353

44-
class RenderModelResponse(PydanticModel):
54+
class RenderModelResponse(CustomMethodResponseBaseClass):
4555
"""
4656
Response to render a model.
4757
"""
@@ -63,11 +73,11 @@ class ModelForRendering(PydanticModel):
6373
uri: str
6474

6575

66-
class AllModelsForRenderRequest(PydanticModel):
76+
class AllModelsForRenderRequest(CustomMethodRequestBaseClass):
6777
pass
6878

6979

70-
class AllModelsForRenderResponse(PydanticModel):
80+
class AllModelsForRenderResponse(CustomMethodResponseBaseClass):
7181
"""
7282
Response to get all the models that are in the current project for rendering purposes.
7383
"""
@@ -94,7 +104,7 @@ class CustomMethod(PydanticModel):
94104
name: str
95105

96106

97-
class SupportedMethodsResponse(PydanticModel):
107+
class SupportedMethodsResponse(CustomMethodResponseBaseClass):
98108
"""
99109
Response containing all supported custom LSP methods.
100110
"""
@@ -105,15 +115,15 @@ class SupportedMethodsResponse(PydanticModel):
105115
FORMAT_PROJECT_FEATURE = "sqlmesh/format_project"
106116

107117

108-
class FormatProjectRequest(PydanticModel):
118+
class FormatProjectRequest(CustomMethodRequestBaseClass):
109119
"""
110120
Request to format all models in the current project.
111121
"""
112122

113123
pass
114124

115125

116-
class FormatProjectResponse(PydanticModel):
126+
class FormatProjectResponse(CustomMethodResponseBaseClass):
117127
"""
118128
Response to format project request.
119129
"""

0 commit comments

Comments
 (0)