Skip to content

Commit 2b4a98e

Browse files
committed
fixup problem with repl closing connection too soon.
An RPC connectio will close if its reader becomes closed, so we can't pass in a finite Readable as the default
1 parent aba5c65 commit 2b4a98e

File tree

4 files changed

+19
-58
lines changed

4 files changed

+19
-58
lines changed

deno.lock

Lines changed: 1 addition & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/repl.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ import type { RPCEndpoint } from "./types.ts";
22
import { readline } from "./readline.ts";
33
import process from "node:process";
44
import completions from "./completions.json" with { type: "json" };
5-
import { each, spawn } from "effection";
5+
import { each } from "effection";
66
import { useCancellationToken } from "./cancellation-token.ts";
77

8-
export function* repl(server: RPCEndpoint) {
9-
yield* spawn(function* () {
10-
for (let notification of yield* each(server.notifications)) {
11-
let [method, params] = notification;
12-
console.log(`Notification: ${method} ${JSON.stringify(params, null, 2)}`);
13-
yield* each.next();
14-
}
15-
});
16-
8+
export function* repl(server: RPCEndpoint, commands: string[]) {
179
let lines = readline({
1810
prompt: "LSP> ",
1911
input: process.stdin,
@@ -25,6 +17,12 @@ export function* repl(server: RPCEndpoint) {
2517
},
2618
});
2719

20+
if (commands.length) {
21+
console.log(`x
22+
|
23+
${commands.map((c) => `+-> ${c}`).join("\n")}`);
24+
}
25+
2826
for (let line of yield* each(lines)) {
2927
let pattern = /([\w\/]+)\((.*)\)/;
3028
let match = pattern.exec(line);
@@ -38,7 +36,9 @@ export function* repl(server: RPCEndpoint) {
3836

3937
let token = yield* useCancellationToken();
4038

41-
let response = yield* server.request([method, args, token]);
39+
let arg = args.length === 1 ? args[0] : args;
40+
41+
let response = yield* server.request([method, arg, token]);
4242

4343
console.log(JSON.stringify(response, null, 2));
4444
} catch (e) {

lib/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function start(opts: LSPXOptions): Operation<RPCEndpoint> {
2222
args,
2323
stdin: "piped",
2424
stdout: "piped",
25-
stderr: "inherit",
25+
stderr: "piped",
2626
});
2727
let server = yield* useConnection({
2828
read: process.stdout,
@@ -34,7 +34,7 @@ export function start(opts: LSPXOptions): Operation<RPCEndpoint> {
3434
let multiplexer = yield* useMultiplexer({ servers });
3535

3636
let client = yield* useConnection({
37-
read: opts.input ?? ReadableStream.from([]),
37+
read: opts.input ?? new ReadableStream(),
3838
write: opts.output ?? new WritableStream(),
3939
});
4040

main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ await main(function* (argv) {
2121
},
2222
}).parse(argv);
2323

24-
let lspx = yield* start({ ...opts, commands: opts.lsp });
25-
2624
if (opts.interactive) {
27-
yield* repl(lspx);
25+
let lspx = yield* start({ ...opts, commands: opts.lsp });
26+
yield* repl(lspx, opts.lsp);
2827
} else {
28+
let input = Deno.stdin.readable;
29+
let output = Deno.stdout.writable;
30+
let lspx = yield* start({ input, output, ...opts, commands: opts.lsp });
2931
for (let [method] of yield* each(lspx.notifications)) {
3032
if (method === "exit") {
3133
break;

0 commit comments

Comments
 (0)