Skip to content

Commit 4b8cfee

Browse files
uoo723lgeiger
authored andcommitted
Improve virtualenv aware by searching subdirectories (#57)
* Improve virtualenv aware by searching subdirectories * Convert sync into async * Run prettier and switch from var to let/const
1 parent d4d272e commit 4b8cfee

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

lib/main.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,46 @@ class PythonLanguageClient extends AutoLanguageClient {
3131
async startServerProcess(projectPath) {
3232
await new Promise(resolve => atom.whenShellEnvironmentLoaded(resolve));
3333

34-
var venvPromise = new Directory(projectPath).getSubdirectory('bin')
35-
.getFile('python')
36-
.exists();
34+
const entries = await new Promise(resolve =>
35+
new Directory(projectPath).getEntries((error, entries) => {
36+
if (error === null) {
37+
resolve(entries);
38+
} else {
39+
resolve(null);
40+
}
41+
})
42+
);
43+
44+
let venvPath = null;
45+
46+
if (entries) {
47+
for (let entry of entries) {
48+
if (entry.isDirectory()) {
49+
if (
50+
entry.getBaseName() === "bin" &&
51+
(await entry.getFile("python").exists())
52+
) {
53+
venvPath = projectPath;
54+
break;
55+
} else {
56+
if (
57+
await entry
58+
.getSubdirectory("bin")
59+
.getFile("python")
60+
.exists()
61+
) {
62+
venvPath = entry.getPath();
63+
break;
64+
}
65+
}
66+
}
67+
}
68+
}
3769

38-
var pylsEnvironment = Object.assign({}, process.env);
70+
const pylsEnvironment = Object.assign({}, process.env);
3971

40-
if(await venvPromise) {
41-
pylsEnvironment['VIRTUAL_ENV'] = projectPath;
72+
if (venvPath) {
73+
pylsEnvironment["VIRTUAL_ENV"] = venvPath;
4274
}
4375

4476
const childProcess = cp.spawn(atom.config.get("ide-python.pylsPath"), {

0 commit comments

Comments
 (0)