Skip to content

Commit fcfeac5

Browse files
fix: resolve virtual envs for python LSP (#2155)
Co-authored-by: rekram1-node <[email protected]>
1 parent 2946898 commit fcfeac5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/opencode/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export namespace LSPClient {
6060
return null
6161
})
6262
connection.onRequest("workspace/configuration", async () => {
63+
// Return server initialization options
6364
return [input.server.initialization ?? {}]
6465
})
6566
connection.listen()

packages/opencode/src/lsp/server.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ export namespace LSPServer {
298298
args.push(...["run", js])
299299
}
300300
args.push("--stdio")
301+
302+
const initialization: Record<string, string> = {}
303+
304+
const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter(
305+
(p): p is string => p !== undefined,
306+
)
307+
for (const venvPath of potentialVenvPaths) {
308+
const isWindows = process.platform === "win32"
309+
const potentialPythonPath = isWindows
310+
? path.join(venvPath, "Scripts", "python.exe")
311+
: path.join(venvPath, "bin", "python")
312+
if (await Bun.file(potentialPythonPath).exists()) {
313+
initialization["pythonPath"] = potentialPythonPath
314+
break
315+
}
316+
}
317+
301318
const proc = spawn(binary, args, {
302319
cwd: root,
303320
env: {
@@ -307,6 +324,7 @@ export namespace LSPServer {
307324
})
308325
return {
309326
process: proc,
327+
initialization,
310328
}
311329
},
312330
}

0 commit comments

Comments
 (0)