@@ -6,7 +6,7 @@ import { getProjectRoot } from "../common/utilities"
66import { execFile } from "child_process"
77import { promisify } from "util"
88import { isPythonModuleInstalled } from "../python"
9-
9+ import fs from "fs"
1010
1111export type sqlmesh_exec = {
1212 workspacePath : string ;
@@ -16,13 +16,18 @@ export type sqlmesh_exec = {
1616} ;
1717
1818/**
19- * Check if tcloud is installed in the current Python environment.
19+ * Returns true if the current project is a Tcloud project. To detect this we,
20+ * 1. Check if the project has a tcloud.yaml file in the project root. If it does, we assume it's a Tcloud project.
21+ * 2. Check if the project has tcloud installed in the Python environment.
2022 *
2123 * @returns A Result indicating whether tcloud is installed.
2224 */
23- export const is_tcloud_installed = async ( ) : Promise <
24- Result < boolean , string >
25- > => {
25+ export const isTcloudProject = async ( ) : Promise < Result < boolean , string > > => {
26+ const projectRoot = await getProjectRoot ( )
27+ const tcloudYamlPath = path . join ( projectRoot . uri . fsPath , "tcloud.yaml" )
28+ if ( fs . existsSync ( tcloudYamlPath ) ) {
29+ return ok ( true )
30+ }
2631 return isPythonModuleInstalled ( "tcloud" )
2732}
2833
@@ -60,7 +65,7 @@ export const sqlmesh_exec = async (): Promise<Result<sqlmesh_exec, string>> => {
6065 }
6166 if ( interpreterDetails . isVirtualEnvironment ) {
6267 traceLog ( "Using virtual environment" )
63- const tcloudInstalled = await is_tcloud_installed ( )
68+ const tcloudInstalled = await isTcloudProject ( )
6469 if ( isErr ( tcloudInstalled ) ) {
6570 return tcloudInstalled
6671 }
@@ -77,7 +82,7 @@ export const sqlmesh_exec = async (): Promise<Result<sqlmesh_exec, string>> => {
7782 VIRTUAL_ENV : path . dirname ( interpreterDetails . binPath ! ) ,
7883 PATH : interpreterDetails . binPath ! ,
7984 } ,
80- args :[ ] ,
85+ args : [ ] ,
8186 } )
8287 }
8388 const binPath = path . join ( interpreterDetails . binPath ! , "sqlmesh" )
@@ -123,7 +128,7 @@ export const sqlmesh_lsp_exec = async (): Promise<
123128 }
124129 if ( interpreterDetails . isVirtualEnvironment ) {
125130 traceLog ( "Using virtual environment" )
126- const tcloudInstalled = await is_tcloud_installed ( )
131+ const tcloudInstalled = await isTcloudProject ( )
127132 if ( isErr ( tcloudInstalled ) ) {
128133 return tcloudInstalled
129134 }
@@ -137,9 +142,9 @@ export const sqlmesh_lsp_exec = async (): Promise<
137142 await execFileAsync ( tcloudBin . value , [ "install_sqlmesh" ] , {
138143 cwd : workspacePath ,
139144 env : {
140- PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
141- VIRTUAL_ENV : path . dirname ( interpreterDetails . binPath ! ) ,
142- PATH : interpreterDetails . binPath ! ,
145+ PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
146+ VIRTUAL_ENV : path . dirname ( interpreterDetails . binPath ! ) ,
147+ PATH : interpreterDetails . binPath ! ,
143148 } ,
144149 } )
145150 }
0 commit comments