Skip to content

Commit

Permalink
feat: use spawn capabilities of language client
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 9, 2021
1 parent cb1db60 commit 1cd5126
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const cp = require("child_process")
const { shell } = require("electron")
const { AutoLanguageClient } = require("atom-languageclient")
const { detectVirtualEnv, detectPipEnv, replacePipEnvPathVar, sanitizeConfig } = require("./utils")
Expand Down Expand Up @@ -50,45 +49,46 @@ class PythonLanguageClient extends AutoLanguageClient {
pylsEnvironment["VIRTUAL_ENV"] = venvPath
}
const python = replacePipEnvPathVar(atom.config.get("ide-python.python"), venvPath)
const childProcess = cp.spawn(python, ["-m", "pyls"], {
const childProcess = super.spawn(python, ["-m", "pyls"], {
cwd: projectPath,
env: pylsEnvironment,
})
childProcess.on("error", (err) => {
const description =
err.code == "ENOENT"
? `No Python interpreter found at \`${python}\`.`
: `Could not spawn the Python interpreter \`${python}\`.`
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
dismissable: true,
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`,
})
})
return childProcess
}

childProcess.on("close", (code, signal) => {
if (code !== 0 && signal == null) {
atom.notifications.addError("Unable to start the Python language server.", {
dismissable: true,
buttons: [
{
text: "Install Instructions",
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python"),
},
{
text: "Download Python",
onDidClick: () => shell.openExternal("https://www.python.org/downloads/"),
},
],
description:
"Make sure to install `pyls` 0.19 or newer by running:\n" +
"```\n" +
`${python} -m pip install 'python-language-server[all]'\n` +
`${python} -m pip install git+https://github.com/tomv564/pyls-mypy.git\n` +
"```",
})
}
onSpawnError(err) {
const description =
err.code == "ENOENT"
? `No Python interpreter found at \`${python}\`.`
: `Could not spawn the Python interpreter \`${python}\`.`
atom.notifications.addError("`ide-python` could not launch your Python runtime.", {
dismissable: true,
description: `${description}<p>If you have Python installed please set "Python Executable" setting correctly. If you do not please install Python.</p>`,
})
return childProcess
}

onSpawnClose(code, signal) {
if (code !== 0 && signal == null) {
atom.notifications.addError("Unable to start the Python language server.", {
dismissable: true,
buttons: [
{
text: "Install Instructions",
onDidClick: () => atom.workspace.open("atom://config/packages/ide-python"),
},
{
text: "Download Python",
onDidClick: () => shell.openExternal("https://www.python.org/downloads/"),
},
],
description:
"Make sure to install `pyls` 0.19 or newer by running:\n" +
"```\n" +
`${python} -m pip install 'python-language-server[all]'\n` +
`${python} -m pip install git+https://github.com/tomv564/pyls-mypy.git\n` +
"```",
})
}
}

async getSuggestions(request) {
Expand Down

0 comments on commit 1cd5126

Please sign in to comment.