Skip to content

Commit 86a1e77

Browse files
remove tanstack; introduce getmodels;
1 parent d0fe631 commit 86a1e77

File tree

5 files changed

+98
-64
lines changed

5 files changed

+98
-64
lines changed

sqlmesh/lsp/custom.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,32 @@ class GetEnvironmentsResponse(CustomMethodResponseBaseClass):
175175
environments: t.Dict[str, EnvironmentInfo]
176176
pinned_environments: t.Set[str]
177177
default_target_environment: str
178+
179+
180+
GET_MODELS_FEATURE = "sqlmesh/get_models"
181+
182+
183+
class GetModelsRequest(CustomMethodRequestBaseClass):
184+
"""
185+
Request to get all models available for table diff.
186+
"""
187+
188+
pass
189+
190+
191+
class ModelInfo(PydanticModel):
192+
"""
193+
Information about a model for table diff.
194+
"""
195+
196+
name: str
197+
fqn: str
198+
description: t.Optional[str] = None
199+
200+
201+
class GetModelsResponse(CustomMethodResponseBaseClass):
202+
"""
203+
Response containing all models available for table diff.
204+
"""
205+
206+
models: t.List[ModelInfo]

sqlmesh/lsp/main.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SUPPORTED_METHODS_FEATURE,
3838
FORMAT_PROJECT_FEATURE,
3939
GET_ENVIRONMENTS_FEATURE,
40+
GET_MODELS_FEATURE,
4041
AllModelsRequest,
4142
AllModelsResponse,
4243
AllModelsForRenderRequest,
@@ -52,6 +53,9 @@
5253
GetEnvironmentsRequest,
5354
GetEnvironmentsResponse,
5455
EnvironmentInfo,
56+
GetModelsRequest,
57+
GetModelsResponse,
58+
ModelInfo,
5559
)
5660
from sqlmesh.lsp.hints import get_hints
5761
from sqlmesh.lsp.reference import (
@@ -130,6 +134,7 @@ def __init__(
130134
SUPPORTED_METHODS_FEATURE: self._custom_supported_methods,
131135
FORMAT_PROJECT_FEATURE: self._custom_format_project,
132136
GET_ENVIRONMENTS_FEATURE: self._custom_get_environments,
137+
GET_MODELS_FEATURE: self._custom_get_models,
133138
}
134139

135140
# Register LSP features (e.g., formatting, hover, etc.)
@@ -195,24 +200,6 @@ def _custom_get_environments(
195200
plan_id=env.plan_id or "",
196201
)
197202

198-
# Add prod if not present (mirroring web/server/api/endpoints/environments.py)
199-
if c.PROD not in environments:
200-
environments[c.PROD] = EnvironmentInfo(
201-
name=c.PROD,
202-
snapshots=[],
203-
start_at=str(to_timestamp(c.EPOCH)),
204-
plan_id="",
205-
)
206-
207-
# Add default target environment if not present
208-
if context.context.config.default_target_environment not in environments:
209-
environments[context.context.config.default_target_environment] = EnvironmentInfo(
210-
name=context.context.config.default_target_environment,
211-
snapshots=[],
212-
start_at=str(to_timestamp(c.EPOCH)),
213-
plan_id="",
214-
)
215-
216203
return GetEnvironmentsResponse(
217204
environments=environments,
218205
pinned_environments=context.context.config.pinned_environments,
@@ -227,6 +214,30 @@ def _custom_get_environments(
227214
default_target_environment="",
228215
)
229216

217+
def _custom_get_models(
218+
self, ls: LanguageServer, params: GetModelsRequest
219+
) -> GetModelsResponse:
220+
"""Get all models available for table diff."""
221+
try:
222+
context = self._context_get_or_load()
223+
models = [
224+
ModelInfo(
225+
name=model.name,
226+
fqn=model.fqn,
227+
description=model.description,
228+
)
229+
for model in context.context.models.values()
230+
# Filter for models that are suitable for table diff
231+
if model._path is not None # Has a file path
232+
]
233+
return GetModelsResponse(models=models)
234+
except Exception as e:
235+
ls.log_trace(f"Error getting table diff models: {e}")
236+
return GetModelsResponse(
237+
response_error=str(e),
238+
models=[],
239+
)
240+
230241
def _custom_api(
231242
self, ls: LanguageServer, request: ApiRequest
232243
) -> t.Union[

vscode/extension/src/commands/tableDiff.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export function showTableDiff(
2626
if (!activeEditor) {
2727
// No active editor, show a list of all models
2828
const allModelsResult = await lspClient.call_custom_method(
29-
'sqlmesh/all_models',
30-
{ textDocument: { uri: '' } },
29+
'sqlmesh/get_models',
30+
{},
3131
)
3232

3333
if (isErr(allModelsResult)) {
@@ -38,22 +38,22 @@ export function showTableDiff(
3838
}
3939

4040
if (
41-
!allModelsResult.value.model_completions ||
42-
allModelsResult.value.model_completions.length === 0
41+
!allModelsResult.value.models ||
42+
allModelsResult.value.models.length === 0
4343
) {
4444
vscode.window.showInformationMessage('No models found in the project')
4545
return
4646
}
4747

4848
// Let user choose from all models
49-
const items = allModelsResult.value.model_completions.map(
49+
const items = (allModelsResult.value.models as any[]).map(
5050
(model: any) => ({
5151
label: model.name,
52-
description: model.name,
52+
description: model.fqn,
5353
detail: model.description ? model.description : undefined,
5454
model: {
5555
name: model.name,
56-
fqn: model.name,
56+
fqn: model.fqn,
5757
description: model.description,
5858
},
5959
}),
@@ -353,8 +353,8 @@ export function showTableDiff(
353353
}
354354
case 'get_all_models': {
355355
const allModelsResult = await lspClient.call_custom_method(
356-
'sqlmesh/all_models',
357-
{ textDocument: { uri: '' } },
356+
'sqlmesh/get_models',
357+
{},
358358
)
359359

360360
let responseCallback: CallbackEvent
@@ -378,7 +378,7 @@ export function showTableDiff(
378378
ok: true,
379379
value: {
380380
ok: true,
381-
models: allModelsResult.value.model_completions || [],
381+
models: allModelsResult.value.models || [],
382382
},
383383
},
384384
},

vscode/extension/src/lsp/custom.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type CustomLSPMethods =
3333
| SupportedMethodsMethod
3434
| FormatProjectMethod
3535
| GetEnvironmentsMethod
36+
| GetTableDiffModelsMethod
3637

3738
interface AllModelsRequest {
3839
textDocument: {
@@ -42,20 +43,9 @@ interface AllModelsRequest {
4243

4344
interface AllModelsResponse extends BaseResponse {
4445
models: string[]
45-
model_completions: ModelCompletion[]
4646
keywords: string[]
47-
macros: MacroCompletion[]
4847
}
4948

50-
interface ModelCompletion {
51-
name: string
52-
description?: string
53-
}
54-
55-
interface MacroCompletion {
56-
name: string
57-
description?: string
58-
}
5949

6050
export interface AbstractAPICallRequest {
6151
endpoint: string
@@ -146,3 +136,22 @@ interface EnvironmentInfo {
146136
start_at: string
147137
plan_id: string
148138
}
139+
140+
export interface GetTableDiffModelsMethod {
141+
method: 'sqlmesh/get_models'
142+
request: GetModelsRequest
143+
response: GetModelsResponse
144+
}
145+
146+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
147+
interface GetModelsRequest {}
148+
149+
interface GetModelsResponse extends BaseResponse {
150+
models: ModelInfo[]
151+
}
152+
153+
interface ModelInfo {
154+
name: string
155+
fqn: string
156+
description: string | null | undefined
157+
}

vscode/react/src/main.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,37 @@
11
import { StrictMode } from 'react'
22
import ReactDOM from 'react-dom/client'
3-
import { RouterProvider, createRouter } from '@tanstack/react-router'
4-
5-
// Import the generated route tree
6-
import { routeTree } from './routeTree.gen'
7-
83
import reportWebVitals from './reportWebVitals.ts'
94
import { EventBusProvider } from './hooks/eventBus.tsx'
5+
import { TableDiffPage } from './pages/tablediff.tsx'
6+
import { LineagePage } from './pages/lineage.tsx'
107

11-
// Detect panel type and set initial route
8+
// Detect panel type
129
declare global {
1310
interface Window {
1411
__SQLMESH_PANEL_TYPE__?: string
1512
}
1613
}
1714

1815
const panelType = window.__SQLMESH_PANEL_TYPE__ || 'lineage'
19-
const initialRoute = panelType === 'tablediff' ? '/tablediff' : '/lineage'
20-
21-
// Create a new router instance
22-
const router = createRouter({
23-
routeTree,
24-
context: {},
25-
defaultPreload: 'intent',
26-
scrollRestoration: true,
27-
defaultStructuralSharing: true,
28-
defaultPreloadStaleTime: 0,
29-
})
3016

31-
// Register the router instance for type safety
32-
declare module '@tanstack/react-router' {
33-
interface Register {
34-
router: typeof router
17+
// component selector
18+
function App() {
19+
if (panelType === 'tablediff') {
20+
return <TableDiffPage />
3521
}
22+
23+
return <LineagePage />
3624
}
3725

3826
// Render the app
3927
const rootElement = document.getElementById('app')
4028
if (rootElement && !rootElement.innerHTML) {
4129
const root = ReactDOM.createRoot(rootElement)
4230

43-
// Navigate to the correct initial route based on panel type
44-
router.navigate({ to: initialRoute })
45-
4631
root.render(
4732
<StrictMode>
4833
<EventBusProvider>
49-
<RouterProvider router={router} />
34+
<App />
5035
</EventBusProvider>
5136
</StrictMode>,
5237
)

0 commit comments

Comments
 (0)