From 55f0fa0001a02b4de4e143a98bdbcedb0b512f67 Mon Sep 17 00:00:00 2001 From: Kevin Rose Date: Thu, 12 Oct 2017 21:34:59 -0500 Subject: [PATCH] get env w/o 100% CPU usage --- lib/main.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 121c050e..5049daa0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,5 +1,4 @@ const cp = require("child_process"); -const shellEnv = require("shell-env"); const { shell } = require("electron"); const { AutoLanguageClient } = require("atom-languageclient"); @@ -7,6 +6,10 @@ const { AutoLanguageClient } = require("atom-languageclient"); // adapted from http://stackoverflow.com/q/5474008 const PYTHON_REGEX = /(([^\d\W]|[\u00A0-\uFFFF])[\w.\u00A0-\uFFFF]*)|\.$/; +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + class PythonLanguageClient extends AutoLanguageClient { getGrammarScopes() { return ["source.python"]; @@ -29,10 +32,12 @@ class PythonLanguageClient extends AutoLanguageClient { } async startServerProcess(projectPath) { - const env = await shellEnv(); + while (!atom.shellEnvironmentLoaded) { + await sleep(100); + } const childProcess = cp.spawn(atom.config.get("ide-python.pylsPath"), { cwd: projectPath, - env: env + env: atom.getLoadSettings().env }); childProcess.on("error", err => atom.notifications.addError( @@ -56,7 +61,7 @@ class PythonLanguageClient extends AutoLanguageClient { } ) ); - return childProcess; + return childProcess; } async getSuggestions(request) {