Skip to content

Commit 1cd5126

Browse files
committed
feat: use spawn capabilities of language client
1 parent cb1db60 commit 1cd5126

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

lib/main.js

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const cp = require("child_process")
21
const { shell } = require("electron")
32
const { AutoLanguageClient } = require("atom-languageclient")
43
const { detectVirtualEnv, detectPipEnv, replacePipEnvPathVar, sanitizeConfig } = require("./utils")
@@ -50,45 +49,46 @@ class PythonLanguageClient extends AutoLanguageClient {
5049
pylsEnvironment["VIRTUAL_ENV"] = venvPath
5150
}
5251
const python = replacePipEnvPathVar(atom.config.get("ide-python.python"), venvPath)
53-
const childProcess = cp.spawn(python, ["-m", "pyls"], {
52+
const childProcess = super.spawn(python, ["-m", "pyls"], {
5453
cwd: projectPath,
5554
env: pylsEnvironment,
5655
})
57-
childProcess.on("error", (err) => {
58-
const description =
59-
err.code == "ENOENT"
60-
? `No Python interpreter found at \`${python}\`.`
61-
: `Could not spawn the Python interpreter \`${python}\`.`
62-
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
63-
dismissable: true,
64-
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`,
65-
})
66-
})
56+
return childProcess
57+
}
6758

68-
childProcess.on("close", (code, signal) => {
69-
if (code !== 0 && signal == null) {
70-
atom.notifications.addError("Unable to start the Python language server.", {
71-
dismissable: true,
72-
buttons: [
73-
{
74-
text: "Install Instructions",
75-
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python"),
76-
},
77-
{
78-
text: "Download Python",
79-
onDidClick: () => shell.openExternal("https://www.python.org/downloads/"),
80-
},
81-
],
82-
description:
83-
"Make sure to install `pyls` 0.19 or newer by running:\n" +
84-
"```\n" +
85-
`${python} -m pip install 'python-language-server[all]'\n` +
86-
`${python} -m pip install git+https://github.com/tomv564/pyls-mypy.git\n` +
87-
"```",
88-
})
89-
}
59+
onSpawnError(err) {
60+
const description =
61+
err.code == "ENOENT"
62+
? `No Python interpreter found at \`${python}\`.`
63+
: `Could not spawn the Python interpreter \`${python}\`.`
64+
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
65+
dismissable: true,
66+
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`,
9067
})
91-
return childProcess
68+
}
69+
70+
onSpawnClose(code, signal) {
71+
if (code !== 0 && signal == null) {
72+
atom.notifications.addError("Unable to start the Python language server.", {
73+
dismissable: true,
74+
buttons: [
75+
{
76+
text: "Install Instructions",
77+
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python"),
78+
},
79+
{
80+
text: "Download Python",
81+
onDidClick: () => shell.openExternal("https://www.python.org/downloads/"),
82+
},
83+
],
84+
description:
85+
"Make sure to install `pyls` 0.19 or newer by running:\n" +
86+
"```\n" +
87+
`${python} -m pip install 'python-language-server[all]'\n` +
88+
`${python} -m pip install git+https://github.com/tomv564/pyls-mypy.git\n` +
89+
"```",
90+
})
91+
}
9292
}
9393

9494
async getSuggestions(request) {

0 commit comments

Comments
 (0)