-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathplanDiff.ts
More file actions
66 lines (56 loc) · 1.68 KB
/
planDiff.ts
File metadata and controls
66 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as vscode from 'vscode'
import { LSPClient } from '../lsp/lsp'
import { isErr } from '@bus/result'
export function planDiff(lspClient?: LSPClient) {
return async () => {
if (!lspClient) {
vscode.window.showErrorMessage('LSP client not available')
return
}
const envResult = await lspClient.call_custom_method(
'sqlmesh/list_environments',
{},
)
if (isErr(envResult)) {
vscode.window.showErrorMessage(
`Failed to list environments: ${envResult.error.message}`,
)
return
}
const env = await vscode.window.showQuickPick(envResult.value.environments, {
placeHolder: 'Select environment to plan',
})
if (!env) {
return
}
const diffResult = await lspClient.call_custom_method('sqlmesh/plan_diff', {
environment: env,
})
if (isErr(diffResult)) {
vscode.window.showErrorMessage(
`Failed to get plan diff: ${diffResult.error.message}`,
)
return
}
if (!diffResult.value.diffs.length) {
vscode.window.showInformationMessage('No changes detected')
return
}
let selected = diffResult.value.diffs[0]
if (diffResult.value.diffs.length > 1) {
const pick = await vscode.window.showQuickPick(
diffResult.value.diffs.map(d => ({ label: d.name })),
{ placeHolder: 'Select a model diff to view' },
)
if (!pick) {
return
}
selected = diffResult.value.diffs.find(d => d.name === pick.label)!
}
const doc = await vscode.workspace.openTextDocument({
content: selected.diff,
language: 'diff',
})
await vscode.window.showTextDocument(doc, { preview: true })
}
}