Skip to content

Commit

Permalink
switch to tcp socket
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Feb 1, 2018
1 parent 9c2f992 commit 06c43ef
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const cp = require("child_process");
const net = require('net');
const { AutoLanguageClient } = require("atom-languageclient");

class PythonLanguageClient extends AutoLanguageClient {
class RLanguageClient extends AutoLanguageClient {
getGrammarScopes() {
return ["source.r"];
}
Expand All @@ -11,16 +12,36 @@ class PythonLanguageClient extends AutoLanguageClient {
getServerName() {
return "rls";
}
getConnectionType() {
return "socket";
}
startServerProcess(projectPath) {
const childProcess = cp.spawn(
atom.config.get("ide-r.RPath"),
[
"--quiet", "--slave", "-e", "languageserver::run()"
], {
cwd: projectPath,
PATH: process.env.PATH
return new Promise((resolve, reject) => {
let childProcess
const server = net.createServer(socket => {
// When the language server connects, grab socket, stop listening and resolve
this.socket = socket
server.close()
resolve(childProcess)
})
server.listen(0, '127.0.0.1', () => {
// Once we have a port assigned spawn the Language Server with the port
console.log("listening at ", server.address().port);
childProcess = this.spawnServer(projectPath, server.address().port);
})
})
childProcess.on("error", err =>
}
spawnServer(projectPath, port) {
const childProcess = cp.spawn(
atom.config.get("ide-r.RPath"),
[
"--quiet", "--slave", "-e", `languageserver::run(debug=T,port=${port})`
],
{
cwd: projectPath,
PATH: process.env.PATH
});
childProcess.on("error", err => {
atom.notifications.addError(
"Unable to start the R language server.",
{
Expand All @@ -37,9 +58,16 @@ class PythonLanguageClient extends AutoLanguageClient {
"Make sure you have both R and languageserver installed.\n"
}
)
);
});
childProcess.on("close", code => {
console.log('[rls] connection close');
});
childProcess.stderr.on('data', function(buf) {
console.log('[rls] %s', String(buf));
});
return childProcess;
}

}

module.exports = new PythonLanguageClient();
module.exports = new RLanguageClient();

0 comments on commit 06c43ef

Please sign in to comment.