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
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vscode/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"type": "string",
"default": "",
"markdownDescription": "The path to the SQLMesh project. If not set, the extension will try to find the project root automatically. If set, the extension will use the project root as the workspace path, e.g. it will run `sqlmesh` and `sqlmesh_lsp` in the project root. The path can be absolute `/Users/sqlmesh_user/sqlmesh_project/sushi` or relative `./project_folder/sushi` to the workspace root."
},
"sqlmesh.lspEntrypoint": {
"type": "string",
"default": "",
"markdownDescription": "The entry point for the SQLMesh LSP server. If not set the extension looks for the default lsp. If set, the extension will use the entry point as the LSP path, The path can be absolute `/Users/sqlmesh_user/sqlmesh_project/sushi/sqlmesh_lsp` or relative `./project_folder/sushi/sqlmesh_lsp` to the workspace root. It can also have arguments, e.g. `./project_folder/sushi/sqlmesh_lsp --port 5000`."
}
}
},
Expand Down Expand Up @@ -136,8 +141,10 @@
"dependencies": {
"@duckdb/node-api": "1.3.2-alpha.25",
"@types/fs-extra": "^11.0.4",
"@types/shell-quote": "^1.7.5",
"@vscode/python-extension": "^1.0.5",
"fs-extra": "^11.3.0",
"shell-quote": "^1.8.3",
"vscode-jsonrpc": "^8.2.1",
"vscode-languageclient": "^9.0.1",
"zod": "^3.25.76"
Expand Down
37 changes: 36 additions & 1 deletion vscode/extension/src/utilities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,59 @@ import path from 'path'
import fs from 'fs'
import { Result, err, ok } from '@bus/result'
import { traceVerbose, traceInfo } from './common/log'
import { parse } from 'shell-quote'
import { z } from 'zod'

export interface SqlmeshConfiguration {
projectPath: string
lspEntryPoint: string
}

/**
* Get the SQLMesh configuration from VS Code settings.
*
* @returns The SQLMesh configuration
*/
export function getSqlmeshConfiguration(): SqlmeshConfiguration {
function getSqlmeshConfiguration(): SqlmeshConfiguration {
const config = workspace.getConfiguration('sqlmesh')
const projectPath = config.get<string>('projectPath', '')
const lspEntryPoint = config.get<string>('lspEntrypoint', '')
return {
projectPath,
lspEntryPoint,
}
}

const stringsArray = z.array(z.string())

/**
* Get the SQLMesh LSP entry point from VS Code settings. undefined if not set
* it's expected to be a string in the format "command arg1 arg2 ...".
*/
export function getSqlmeshLspEntryPoint():
| {
entrypoint: string
args: string[]
}
| undefined {
const config = getSqlmeshConfiguration()
if (config.lspEntryPoint === '') {
return undefined
}
// Split the entry point into command and arguments
const parts = parse(config.lspEntryPoint)
const parsed = stringsArray.safeParse(parts)
if (!parsed.success) {
throw new Error(
`Invalid lspEntrypoint configuration: ${config.lspEntryPoint}. Expected a
string in the format "command arg1 arg2 ...".`,
)
}
const entrypoint = parsed.data[0]
const args = parsed.data.slice(1)
return { entrypoint, args }
}

/**
* Validate and resolve the project path from configuration.
* If no project path is configured, use the workspace folder.
Expand Down
30 changes: 21 additions & 9 deletions vscode/extension/src/utilities/sqlmesh/sqlmesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { execAsync } from '../exec'
import z from 'zod'
import { ProgressLocation, window } from 'vscode'
import { IS_WINDOWS } from '../isWindows'
import { resolveProjectPath } from '../config'
import { getSqlmeshLspEntryPoint, resolveProjectPath } from '../config'
import { isSemVerGreaterThanOrEqual } from '../semver'

export interface SqlmeshExecInfo {
Expand Down Expand Up @@ -413,15 +413,7 @@ export const ensureSqlmeshLspDependenciesInstalled = async (): Promise<
export const sqlmeshLspExec = async (): Promise<
Result<SqlmeshExecInfo, ErrorType>
> => {
const sqlmeshLSP = IS_WINDOWS ? 'sqlmesh_lsp.exe' : 'sqlmesh_lsp'
const projectRoot = await getProjectRoot()
const envVariables = await getPythonEnvVariables()
if (isErr(envVariables)) {
return err({
type: 'generic',
message: envVariables.error,
})
}
const resolvedPath = resolveProjectPath(projectRoot)
if (isErr(resolvedPath)) {
return err({
Expand All @@ -430,6 +422,26 @@ export const sqlmeshLspExec = async (): Promise<
})
}
const workspacePath = resolvedPath.value

const configuredLSPExec = getSqlmeshLspEntryPoint()
if (configuredLSPExec) {
traceLog(`Using configured SQLMesh LSP entry point: ${configuredLSPExec.entrypoint} ${configuredLSPExec.args.join(' ')}`)
return ok({
bin: configuredLSPExec.entrypoint,
workspacePath,
env: process.env,
args: configuredLSPExec.args,
})
}
const sqlmeshLSP = IS_WINDOWS ? 'sqlmesh_lsp.exe' : 'sqlmesh_lsp'
const envVariables = await getPythonEnvVariables()
if (isErr(envVariables)) {
return err({
type: 'generic',
message: envVariables.error,
})
}

const interpreterDetails = await getInterpreterDetails()
traceLog(`Interpreter details: ${JSON.stringify(interpreterDetails)}`)
if (interpreterDetails.path) {
Expand Down
Loading