Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streams should implement vscode-jsonrpc's _ReadableStream and _WritableStream interfaces #119

Open
phated opened this issue Sep 20, 2023 · 2 comments
Labels
feature-request Request for new features or functionality
Milestone

Comments

@phated
Copy link

phated commented Sep 20, 2023

After seeing @dbaeumer's talk at WasmCon, I was inspired to compile the Noir LSP to WASI and hook it as the server component via the vscode-wasm harness. The current progress is available at noir-lang/vscode-noir#41

One of the workarounds I needed to do was stubbing the following interfaces:

interface _ReadableStream {
	onData(listener: (data: Uint8Array) => void): Disposable;
	onClose(listener: () => void): Disposable;
	onError(listener: (error: any) => void): Disposable;
	onEnd(listener: () => void): Disposable;
}

interface _WritableStream {
	onClose(listener: () => void): Disposable;
	onError(listener: (error: any) => void): Disposable;
	onEnd(listener: () => void): Disposable;
	write(data: Uint8Array): Promise<void>;
	write(data: string, encoding: _MessageBufferEncoding): Promise<void>;
	end(): void;
}

This allows me to use the Readable and Writable provided by this library as streams for ReadableStreamMessageReader and WriteableStreamMessageWriter. If this library implemented those interfaces, these streams could be used directly without any stubs.

@dbaeumer
Copy link
Member

@phated cool idea. I will ensure that this gets easier at least for WASI preview 2 which comes with stream interfaces itself.

@dbaeumer dbaeumer added the feature-request Request for new features or functionality label Sep 26, 2023
@dbaeumer dbaeumer added this to the October 2023 milestone Sep 26, 2023
@dbaeumer
Copy link
Member

I did some first work on this. However since we will move to the component model which comes with yet another stream implementation I will not make this official yet. But you might want to copy the code. It is here:

/* --------------------------------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

2 participants