Skip to content

Commit

Permalink
Merge branch 'jm/fixes' of github.com:urbit/hoon-language-server into…
Browse files Browse the repository at this point in the history
… jm/fixes
  • Loading branch information
arthyn committed Apr 5, 2022
2 parents cd00c66 + 67b4832 commit 3aee637
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"engines": {
"node": "*"
},
"files": [
"bin/**",
"out/**"
],
"repository": {
"type": "git",
"url": "git+https://github.com/urbit/hoon-language-server.git"
},
"bin": {
"hoon-language-server": "bin/index.js"
},
"files": [
"bin/**",
"out/**"
],
"dependencies": {
"@types/eventsource": "^1.1.5",
"@types/lodash": "^4.14.149",
Expand Down
15 changes: 9 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { connect } from "urbit-airlock/lib/setup";
import { wait, request, Config } from "./util";

const logger = pino(
{ level: "info" }
pino.destination("/tmp/hoon-language-server.log")
);

interface RequestContinuation {
Expand All @@ -26,7 +26,6 @@ class Server {
subscription: number | null = null;
outstandingRequests: Map<string, RequestContinuation> = new Map();
constructor(private channel: Channel, private delay: number) {
logger.info('constructor');
this.connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(process.stdin),
new rpc.StreamMessageWriter(process.stdout)
Expand Down Expand Up @@ -91,14 +90,16 @@ class Server {
// const onUpdate =
// const onError = this.onSubscriptionErr.bind(this);

logger.info('started');
this.channel.subscribe(app, path, {
mark: "json",
onError: (e: any) => this.onSubscriptionErr(e),
onEvent: (u: any) => this.onSubscriptionUpdate(u),
onQuit: (e: any) => this.onSubscriptionErr(e)
});
new Promise(() => this.connection.listen());
new Promise(() => this.connection.listen()).catch(e => {
logger.error({ message: `error somewhere`, e });

});
}

// handlers
Expand All @@ -114,7 +115,6 @@ class Server {
}

onRequest(method: string, params: any[]) {
logger.info({ message: `caught request`, method });
const id = uniqueId();

if (method === "initialize") {
Expand All @@ -123,15 +123,18 @@ class Server {
logger.info({ message: `caught request`, id });
this.pokeRequest({ jsonrpc: "2.0", method, params, id });
return this.waitOnResponse(id).then(r => {
logger.info({ message: `returning request`, id, r });
return r;
}).catch(e => {
logger.error({ message: `error on request`, id, e });
});
}
}

waitOnResponse(id: string) {
return new Promise((resolve, reject) => {
this.outstandingRequests.set(id, resolve);
}).catch(e => {
logger.error({ message: "waitOnResponse", e });
});
}

Expand Down

0 comments on commit 3aee637

Please sign in to comment.