Skip to content

Commit

Permalink
allow remote ships
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-fitzgerald committed Mar 31, 2020
1 parent 42c2635 commit c9295f3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eventsource": "^1.0.7",
"lodash": "^4.17.15",
"pino": "^5.15.0",
"urbit-airlock": "0.0.1",
"urbit-airlock": "0.0.2",
"vscode-languageserver": "^5.2.1",
"yargs": "^15.1.0"
},
Expand Down
60 changes: 35 additions & 25 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ const logger = pino(
{ level: "trace" },
pino.destination("/tmp/hoon-language-server.log")
);
const url = "http://localhost";
const app = "language-server";
const path = "/primary";
const ship = "zod";

interface RequestContinuation {
(result: any): void;
}

const app = "language-server";
const path = "/primary";

class Server {
connection: rpc.MessageConnection;
subscription: number | null = null;
outstandingRequests: Map<string, RequestContinuation> = new Map();
constructor(private channel: Channel, private config: Config) {
constructor(private channel: Channel, private delay: number) {
this.connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(process.stdin),
new rpc.StreamMessageWriter(process.stdout)
Expand Down Expand Up @@ -106,7 +105,7 @@ class Server {
onNotification(method: string, params: any[]) {
logger.debug({ method, params });
if (method === "textDocument/didSave") {
wait(this.config.delay).then(() => {
wait(this.delay).then(() => {
logger.debug("Delayed didSave");
this.pokeNotification({ jsonrpc: "2.0", method, params });
});
Expand All @@ -116,7 +115,6 @@ class Server {

onRequest(method: string, params: any[]) {
const id = uniqueId();
logger.debug({ method });

if (method === "initialize") {
return this.initialise();
Expand Down Expand Up @@ -170,28 +168,40 @@ class Server {
}
}

let password = "lidlut-tabwed-pillex-ridrup";

const _config: Config = yargs.options({
port: {
alias: "p",
default: 80,
description: "HTTP port of the running urbit"
},
delay: {
alias: "d",
default: 0
}
}).argv;

(async function main() {
const connection = await connect(ship, url, 80, password);
const { ship, url, code: password, port, delay }: Config = yargs.options({
port: {
alias: "p",
default: 80,
description: "HTTP port of the running urbit"
},
delay: {
alias: "d",
default: 0,
description: "Delay for running didSave events"
},
url: {
alias: "u",
default: "http://localhost",
description: "URL of the running urbit"
},
ship: {
alias: "s",
default: "zod",
description: "@p of the running urbit, without leading sig"
},
code: {
alias: "c",
default: "lidlut-tabwed-pillex-ridrup",
description: "+code of the running urbit"
}
}).argv;

const channel = new Channel(connection);
const connection = await connect(ship, url, port, password);

const config = { port: 80, delay: 500 };
const channel = new Channel(connection);

const server = new Server(channel, config);
const server = new Server(channel, delay);

server.serve();
})();
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as http from "http";
export interface Config {
port: number;
delay: number;
url: string;
code: string;
ship: string;
}

interface HttpResponse {
req: http.ClientRequest;
res: http.IncomingMessage;
Expand Down

0 comments on commit c9295f3

Please sign in to comment.