Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions sqlmesh/lsp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

import typing as t
from pydantic import field_validator
from sqlmesh.utils.pydantic import PydanticModel
from sqlmesh.lsp.custom import (
CustomMethodRequestBaseClass,
CustomMethodResponseBaseClass,
)
from web.server.models import LineageColumn, Model

API_FEATURE = "sqlmesh/api"


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


class ApiResponseGetModels(PydanticModel):
class BaseAPIResponse(CustomMethodResponseBaseClass):
error: t.Optional[str] = None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is error needed here and why is response_error not enough? I wen thought the code but can't understand its purpose of inheriting from CustomMethodResponseBaseClass



class ApiResponseGetModels(BaseAPIResponse):
"""
Response from the SQLMesh API for the get_models endpoint.
"""
Expand All @@ -53,15 +60,15 @@ def sanitize_datetime_fields(cls, data: t.List[Model]) -> t.List[Model]:
return data


class ApiResponseGetLineage(PydanticModel):
class ApiResponseGetLineage(BaseAPIResponse):
"""
Response from the SQLMesh API for the get_lineage endpoint.
"""

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


class ApiResponseGetColumnLineage(PydanticModel):
class ApiResponseGetColumnLineage(BaseAPIResponse):
"""
Response from the SQLMesh API for the get_column_lineage endpoint.
"""
Expand Down
28 changes: 19 additions & 9 deletions sqlmesh/lsp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
import typing as t
from sqlmesh.utils.pydantic import PydanticModel


class CustomMethodRequestBaseClass(PydanticModel):
pass


class CustomMethodResponseBaseClass(PydanticModel):
# Prefixing, so guaranteed not to collide
response_error: t.Optional[str] = None


ALL_MODELS_FEATURE = "sqlmesh/all_models"


class AllModelsRequest(PydanticModel):
class AllModelsRequest(CustomMethodRequestBaseClass):
"""
Request to get all the models that are in the current project.
"""

textDocument: types.TextDocumentIdentifier


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


class RenderModelRequest(PydanticModel):
class RenderModelRequest(CustomMethodRequestBaseClass):
textDocumentUri: str


Expand All @@ -41,7 +51,7 @@ class RenderModelEntry(PydanticModel):
rendered_query: str


class RenderModelResponse(PydanticModel):
class RenderModelResponse(CustomMethodResponseBaseClass):
"""
Response to render a model.
"""
Expand All @@ -63,11 +73,11 @@ class ModelForRendering(PydanticModel):
uri: str


class AllModelsForRenderRequest(PydanticModel):
class AllModelsForRenderRequest(CustomMethodRequestBaseClass):
pass


class AllModelsForRenderResponse(PydanticModel):
class AllModelsForRenderResponse(CustomMethodResponseBaseClass):
"""
Response to get all the models that are in the current project for rendering purposes.
"""
Expand All @@ -94,7 +104,7 @@ class CustomMethod(PydanticModel):
name: str


class SupportedMethodsResponse(PydanticModel):
class SupportedMethodsResponse(CustomMethodResponseBaseClass):
"""
Response containing all supported custom LSP methods.
"""
Expand All @@ -105,15 +115,15 @@ class SupportedMethodsResponse(PydanticModel):
FORMAT_PROJECT_FEATURE = "sqlmesh/format_project"


class FormatProjectRequest(PydanticModel):
class FormatProjectRequest(CustomMethodRequestBaseClass):
"""
Request to format all models in the current project.
"""

pass


class FormatProjectResponse(PydanticModel):
class FormatProjectResponse(CustomMethodResponseBaseClass):
"""
Response to format project request.
"""
Expand Down
Loading