diff options
| author | Andre van Tonder <[email protected]> | 2025-08-31 14:53:03 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-30 23:53:03 -0500 |
| commit | fcfeac57c53b16c149e2da038a0b212b425f029b (patch) | |
| tree | 40682cdb9deb0bafb0a1380639a01524f500231f | |
| parent | 2946898934fe458bce56720203f1074ddc3c524c (diff) | |
| download | opencode-fcfeac57c53b16c149e2da038a0b212b425f029b.tar.gz opencode-fcfeac57c53b16c149e2da038a0b212b425f029b.zip | |
fix: resolve virtual envs for python LSP (#2155)
Co-authored-by: rekram1-node <[email protected]>
| -rw-r--r-- | packages/opencode/src/lsp/client.ts | 1 | ||||
| -rw-r--r-- | packages/opencode/src/lsp/server.ts | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/packages/opencode/src/lsp/client.ts b/packages/opencode/src/lsp/client.ts index a03a26514..c6ccfbb0d 100644 --- a/packages/opencode/src/lsp/client.ts +++ b/packages/opencode/src/lsp/client.ts @@ -60,6 +60,7 @@ export namespace LSPClient { return null }) connection.onRequest("workspace/configuration", async () => { + // Return server initialization options return [input.server.initialization ?? {}] }) connection.listen() diff --git a/packages/opencode/src/lsp/server.ts b/packages/opencode/src/lsp/server.ts index da743628d..9861a5798 100644 --- a/packages/opencode/src/lsp/server.ts +++ b/packages/opencode/src/lsp/server.ts @@ -298,6 +298,23 @@ export namespace LSPServer { args.push(...["run", js]) } args.push("--stdio") + + const initialization: Record<string, string> = {} + + const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter( + (p): p is string => p !== undefined, + ) + for (const venvPath of potentialVenvPaths) { + const isWindows = process.platform === "win32" + const potentialPythonPath = isWindows + ? path.join(venvPath, "Scripts", "python.exe") + : path.join(venvPath, "bin", "python") + if (await Bun.file(potentialPythonPath).exists()) { + initialization["pythonPath"] = potentialPythonPath + break + } + } + const proc = spawn(binary, args, { cwd: root, env: { @@ -307,6 +324,7 @@ export namespace LSPServer { }) return { process: proc, + initialization, } }, } |
