Skip to content

Commit eb62c6a

Browse files
rob-a-boltonlgeiger
authored andcommitted
Made extension virtualenv aware by exporting VIRTUAL_ENV when bin/python detected from project root
1 parent 545e649 commit eb62c6a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/main.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const cp = require("child_process");
22
const { shell } = require("electron");
33
const { AutoLanguageClient } = require("atom-languageclient");
4+
const { Directory } = require("atom");
45

56
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
67
// adapted from http://stackoverflow.com/q/5474008
@@ -30,8 +31,19 @@ class PythonLanguageClient extends AutoLanguageClient {
3031
async startServerProcess(projectPath) {
3132
await new Promise(resolve => atom.whenShellEnvironmentLoaded(resolve));
3233

34+
var venvPromise = new Directory(projectPath).getSubdirectory('bin')
35+
.getFile('python')
36+
.exists();
37+
38+
var pylsEnvironment = Object.assign({}, process.env);
39+
40+
if(await venvPromise) {
41+
pylsEnvironment['VIRTUAL_ENV'] = projectPath;
42+
}
43+
3344
const childProcess = cp.spawn(atom.config.get("ide-python.pylsPath"), {
34-
cwd: projectPath
45+
cwd: projectPath,
46+
env: pylsEnvironment
3547
});
3648
childProcess.on("error", err =>
3749
atom.notifications.addError(

0 commit comments

Comments
 (0)