diff --git a/lib/main.js b/lib/main.js index bb598094..0b61cd62 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,8 +45,22 @@ class PythonLanguageClient extends AutoLanguageClient { return "ide-python" } + getPyLs() { + if (this.pyls === undefined) { + let pyls = atom.config.get("ide-python.pyls") || "pylsp" + // check if it exists + if (whichSync(pyls, { nothrow: true }) === null) { + // use the other one if it doesn't exist + pyls = pyls === "pylsp" ? "pyls" : "pylsp" + } + // cache + this.pyls = pyls + } + return this.pyls + } + mapConfigurationObject(configuration) { - const lsp = configuration.pyls || "pylsp" + const lsp = this.getPyLs() return { [lsp]: { configurationSources: configuration.pylsConfigurationSources, @@ -71,13 +85,7 @@ class PythonLanguageClient extends AutoLanguageClient { this.python = replacePipEnvPathVar(pythonBin, venvPath) - let pyls = atom.config.get("ide-python.pyls") || "pylsp" - // check if it exists - if (whichSync(pyls, { nothrow: true }) === null) { - pyls = "pyls" - } - - const childProcess = super.spawn(this.python, ["-m", pyls], { + const childProcess = super.spawn(this.python, ["-m", this.getPyLs()], { cwd: projectPath, env: pylsEnvironment, })