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
38 changes: 6 additions & 32 deletions vscode/extension/src/commands/format.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { traceLog } from '../utilities/common/log'
import { sqlmeshExec } from '../utilities/sqlmesh/sqlmesh'
import { err, isErr, ok, Result } from '@bus/result'
import * as vscode from 'vscode'
import { ErrorType, handleError } from '../utilities/errors'
import { AuthenticationProviderTobikoCloud } from '../auth/auth'
import { execAsync } from '../utilities/exec'
import { LSPClient } from '../lsp/lsp'

export const format =
Expand All @@ -30,39 +28,15 @@ export const format =
const internalFormat = async (
lsp: LSPClient | undefined,
): Promise<Result<undefined, ErrorType>> => {
try {
// Try LSP method first
if (lsp) {
const response = await lsp.call_custom_method(
'sqlmesh/format_project',
{},
)
if (isErr(response)) {
return response
}
return ok(undefined)
}
} catch (error) {
traceLog(`LSP format failed, falling back to CLI: ${JSON.stringify(error)}`)
}

// Fallback to CLI method if LSP is not available
// TODO This is a solution in order to be backwards compatible in the cases
// where the LSP method is not implemented yet. This should be removed at
// some point in the future.
const exec = await sqlmeshExec()
if (isErr(exec)) {
return exec
}
const result = await execAsync(`${exec.value.bin}`, ['format'], {
cwd: exec.value.workspacePath,
env: exec.value.env,
})
if (result.exitCode !== 0) {
if (lsp === undefined) {
return err({
type: 'generic',
message: `Error executing sqlmesh format: ${result.stderr}`,
message: 'LSP is not available',
})
}
const response = await lsp.call_custom_method('sqlmesh/format_project', {})
if (isErr(response)) {
return response
}
return ok(undefined)
}
103 changes: 0 additions & 103 deletions vscode/extension/src/utilities/sqlmesh/sqlmesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,109 +262,6 @@ export const ensureSqlmeshEnterpriseInstalled = async (): Promise<
return installationLock
}

/**
* Get the sqlmesh executable for the current workspace.
*
* @deprecated Use LSP instead of direct sqlmesh execution for any new functionality.
*/
export const sqlmeshExec = async (): Promise<
Result<SqlmeshExecInfo, ErrorType>
> => {
const sqlmesh = IS_WINDOWS ? 'sqlmesh.exe' : 'sqlmesh'
const projectRoot = await getProjectRoot()
const resolvedPath = resolveProjectPath(projectRoot)
if (isErr(resolvedPath)) {
return err({
type: 'generic',
message: resolvedPath.error,
})
}
const envVariables = await getPythonEnvVariables()
if (isErr(envVariables)) {
return err({
type: 'generic',
message: envVariables.error,
})
}
const workspacePath = resolvedPath.value
const interpreterDetails = await getInterpreterDetails()
traceLog(`Interpreter details: ${JSON.stringify(interpreterDetails)}`)
if (interpreterDetails.path) {
traceVerbose(
`Using interpreter from Python extension: ${interpreterDetails.path.join(
' ',
)}`,
)
}
if (interpreterDetails.isVirtualEnvironment) {
traceLog('Using virtual environment')
const isTcloudInstalled = await isTcloudProject()
if (isErr(isTcloudInstalled)) {
return err({
type: 'generic',
message: isTcloudInstalled.error,
})
}
if (isTcloudInstalled.value) {
const tcloudBin = await getTcloudBin()
if (isErr(tcloudBin)) {
return tcloudBin
}
const isSignedIn = await isSignedIntoTobikoCloud()
if (!isSignedIn) {
return err({
type: 'not_signed_in',
})
}
const ensured = await ensureSqlmeshEnterpriseInstalled()
if (isErr(ensured)) {
return ensured
}
return ok({
bin: tcloudBin.value.bin,
workspacePath,
env: tcloudBin.value.env,
args: ["sqlmesh"],
})
}
const binPath = path.join(interpreterDetails.binPath!, sqlmesh)
traceLog(`Bin path: ${binPath}`)
const env = await getSqlmeshEnvironment()
if (isErr(env)) {
return err({
type: 'generic',
message: env.error,
})
}
return ok({
bin: binPath,
workspacePath,
env: env.value,
args: [],
})
} else {
const exists = await doesExecutableExist(sqlmesh)
if (!exists) {
return err({
type: 'sqlmesh_not_found',
})
}
const env = await getSqlmeshEnvironment()
if (isErr(env)) {
return err({
type: 'generic',
message: env.error,
})
}
return ok({
bin: sqlmesh,
workspacePath,
env: env.value,
args: [],
})
}
}

/**
* Ensure that the sqlmesh_lsp dependencies are installed.
*
Expand Down
Loading