fix: resolve virtual envs for python LSP (#2155)
Co-authored-by: rekram1-node <aidenpcline@gmail.com>
This commit is contained in:
@@ -60,6 +60,7 @@ export namespace LSPClient {
|
|||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
connection.onRequest("workspace/configuration", async () => {
|
connection.onRequest("workspace/configuration", async () => {
|
||||||
|
// Return server initialization options
|
||||||
return [input.server.initialization ?? {}]
|
return [input.server.initialization ?? {}]
|
||||||
})
|
})
|
||||||
connection.listen()
|
connection.listen()
|
||||||
|
|||||||
@@ -298,6 +298,23 @@ export namespace LSPServer {
|
|||||||
args.push(...["run", js])
|
args.push(...["run", js])
|
||||||
}
|
}
|
||||||
args.push("--stdio")
|
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, {
|
const proc = spawn(binary, args, {
|
||||||
cwd: root,
|
cwd: root,
|
||||||
env: {
|
env: {
|
||||||
@@ -307,6 +324,7 @@ export namespace LSPServer {
|
|||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
process: proc,
|
process: proc,
|
||||||
|
initialization,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user