Skip to content

Commit e15779a

Browse files
committed
fixing sqlmesh lsp missing
1 parent 878fdf1 commit e15779a

4 files changed

Lines changed: 46 additions & 21 deletions

File tree

vscode/extension/src/utilities/errors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { traceInfo } from './common/log'
99
export type ErrorType =
1010
| ErrorTypeGeneric
1111
| { type: 'not_signed_in' }
12+
| { type: 'sqlmesh_not_found' }
1213
| { type: 'sqlmesh_lsp_not_found' }
1314
// tcloud_bin_not_found is used when the tcloud executable is not found. This is likely to happen if the user
1415
// opens a project that has a `tcloud.yaml` file but doesn't have tcloud installed.
@@ -85,6 +86,8 @@ export async function handleError(
8586
return
8687
case 'not_signed_in':
8788
return handleNotSignedInError(authProvider)
89+
case 'sqlmesh_not_found':
90+
return handleSqlmeshNotFoundError()
8891
case 'sqlmesh_lsp_not_found':
8992
return handleSqlmeshLspNotFoundError()
9093
case 'sqlmesh_lsp_dependencies_missing':
@@ -118,6 +121,14 @@ const handleNotSignedInError = async (
118121
}
119122
}
120123

124+
/**
125+
* Handles the case where the sqlmesh executable is not found.
126+
*/
127+
const handleSqlmeshNotFoundError = async (): Promise<void> => {
128+
traceInfo('handleSqlmeshNotFoundError')
129+
await window.showErrorMessage('SQLMesh not found, please check installation')
130+
}
131+
121132
/**
122133
* Handles the case where the sqlmesh_lsp is not found.
123134
*/

vscode/extension/src/utilities/sqlmesh/sqlmesh.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ export const sqlmeshExec = async (): Promise<
287287
args: [],
288288
})
289289
} else {
290+
const exists = await doesExecutableExist(sqlmesh)
291+
if (!exists) {
292+
return err({
293+
type: 'sqlmesh_not_found',
294+
})
295+
}
290296
return ok({
291297
bin: sqlmesh,
292298
workspacePath,
@@ -384,22 +390,28 @@ export const sqlmeshLspExec = async (): Promise<
384390
type: 'not_signed_in',
385391
})
386392
}
393+
const exists = await doesExecutableExist(sqlmeshLSP)
394+
if (!exists) {
395+
return err({
396+
type: 'sqlmesh_lsp_not_found',
397+
})
398+
}
387399
const ensured = await ensureSqlmeshEnterpriseInstalled()
388400
if (isErr(ensured)) {
389401
return ensured
390402
}
391403
}
392-
const ensuredDependencies = await ensureSqlmeshLspDependenciesInstalled()
393-
if (isErr(ensuredDependencies)) {
394-
return ensuredDependencies
395-
}
396404
const binPath = path.join(interpreterDetails.binPath!, sqlmeshLSP)
397405
traceLog(`Bin path: ${binPath}`)
398406
if (!fs.existsSync(binPath)) {
399407
return err({
400408
type: 'sqlmesh_lsp_not_found',
401409
})
402410
}
411+
const ensuredDependencies = await ensureSqlmeshLspDependenciesInstalled()
412+
if (isErr(ensuredDependencies)) {
413+
return ensuredDependencies
414+
}
403415
return ok({
404416
bin: binPath,
405417
workspacePath,
@@ -411,6 +423,12 @@ export const sqlmeshLspExec = async (): Promise<
411423
args: [],
412424
})
413425
} else {
426+
const exists = await doesExecutableExist(sqlmeshLSP)
427+
if (!exists) {
428+
return err({
429+
type: 'sqlmesh_lsp_not_found',
430+
})
431+
}
414432
return ok({
415433
bin: sqlmeshLSP,
416434
workspacePath,
@@ -419,3 +437,13 @@ export const sqlmeshLspExec = async (): Promise<
419437
})
420438
}
421439
}
440+
441+
async function doesExecutableExist(executable: string): Promise<boolean> {
442+
if (process.platform === 'win32') {
443+
const result = await execAsync('where.exe', [executable])
444+
return result.exitCode === 0
445+
} else {
446+
const result = await execAsync('which', [executable])
447+
return result.exitCode === 0
448+
}
449+
}

vscode/extension/tests/bad_setup.spec.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test('missing LSP dependencies shows install prompt', async ({}, testInfo) => {
7474
}
7575
})
7676

77-
test('lineage, no sqlmesh found', async ({}, testInfo) => {
77+
test('lineage, no sqlmesh found', async ({}) => {
7878
const tempDir = await fs.mkdtemp(
7979
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
8080
)
@@ -103,21 +103,7 @@ test('lineage, no sqlmesh found', async ({}, testInfo) => {
103103
await openLineageView(window)
104104

105105
// Assert shows that sqlmesh is not installed
106-
await window.waitForSelector('text=SQLMesh language server not found')
107-
108-
// Assert cannot see wrong notifications
109-
await expect(window.locator('LSP dependencies missing')).not.toBeVisible()
110-
111-
// Cancel the notification
112-
await window.getByRole('button', { name: 'Cancel' }).click()
113-
114-
// When cancel notification, the lineage view should show the error
115-
await expect(
116-
window.locator('text=SQLMesh language server not found'),
117-
).toBeVisible()
118-
119-
// Assert cannot see the Loading models text
120-
await expect(window.locator('text=Loading models...')).not.toBeVisible()
106+
await window.waitForSelector('text=SQLMesh LSP not found')
121107

122108
await close()
123109
} finally {

vscode/extension/tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ export const openLineageView = async (window: Page): Promise<void> => {
147147
)
148148
await window.keyboard.type('Lineage: Focus On View')
149149
await window.keyboard.press('Enter')
150-
}
150+
}

0 commit comments

Comments
 (0)