Skip to content

Commit 86669b7

Browse files
authored
Merge pull request #389 from atom-community/fix-finding-pyls
2 parents c66cecc + 902102b commit 86669b7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/main.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,22 @@ class PythonLanguageClient extends AutoLanguageClient {
4545
return "ide-python"
4646
}
4747

48+
getPyLs() {
49+
if (this.pyls === undefined) {
50+
let pyls = atom.config.get("ide-python.pyls") || "pylsp"
51+
// check if it exists
52+
if (whichSync(pyls, { nothrow: true }) === null) {
53+
// use the other one if it doesn't exist
54+
pyls = pyls === "pylsp" ? "pyls" : "pylsp"
55+
}
56+
// cache
57+
this.pyls = pyls
58+
}
59+
return this.pyls
60+
}
61+
4862
mapConfigurationObject(configuration) {
49-
const lsp = configuration.pyls || "pylsp"
63+
const lsp = this.getPyLs()
5064
return {
5165
[lsp]: {
5266
configurationSources: configuration.pylsConfigurationSources,
@@ -71,13 +85,7 @@ class PythonLanguageClient extends AutoLanguageClient {
7185

7286
this.python = replacePipEnvPathVar(pythonBin, venvPath)
7387

74-
let pyls = atom.config.get("ide-python.pyls") || "pylsp"
75-
// check if it exists
76-
if (whichSync(pyls, { nothrow: true }) === null) {
77-
pyls = "pyls"
78-
}
79-
80-
const childProcess = super.spawn(this.python, ["-m", pyls], {
88+
const childProcess = super.spawn(this.python, ["-m", this.getPyLs()], {
8189
cwd: projectPath,
8290
env: pylsEnvironment,
8391
})

0 commit comments

Comments
 (0)