diff --git a/lib/main.js b/lib/main.js index 301798c1..4c5efe15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,14 +31,46 @@ class PythonLanguageClient extends AutoLanguageClient { async startServerProcess(projectPath) { await new Promise(resolve => atom.whenShellEnvironmentLoaded(resolve)); - var venvPromise = new Directory(projectPath).getSubdirectory('bin') - .getFile('python') - .exists(); + const entries = await new Promise(resolve => + new Directory(projectPath).getEntries((error, entries) => { + if (error === null) { + resolve(entries); + } else { + resolve(null); + } + }) + ); + + let venvPath = null; + + if (entries) { + for (let entry of entries) { + if (entry.isDirectory()) { + if ( + entry.getBaseName() === "bin" && + (await entry.getFile("python").exists()) + ) { + venvPath = projectPath; + break; + } else { + if ( + await entry + .getSubdirectory("bin") + .getFile("python") + .exists() + ) { + venvPath = entry.getPath(); + break; + } + } + } + } + } - var pylsEnvironment = Object.assign({}, process.env); + const pylsEnvironment = Object.assign({}, process.env); - if(await venvPromise) { - pylsEnvironment['VIRTUAL_ENV'] = projectPath; + if (venvPath) { + pylsEnvironment["VIRTUAL_ENV"] = venvPath; } const childProcess = cp.spawn(atom.config.get("ide-python.pylsPath"), {