codemirror-languageserver icon indicating copy to clipboard operation
codemirror-languageserver copied to clipboard

How would you configure this if you don't have a server?

Open NullVoxPopuli opened this issue 3 years ago • 7 comments

I primarily work on backendless apps, and would not be able to host anything anywhere (other than static assets via CDN).

ideally, I'd like to import / bundle language servers with the codemirror bundle I'm building so I don't even need to worry about providing public asset path mapping (I totally understand this adds a lot to initial load time).

Is this possible today? Maybe via WebWorkers?

NullVoxPopuli avatar Jul 10 '22 16:07 NullVoxPopuli

Web Workers would be a feasible solution here I think. IIRC you'd still have to have a separate JS file for the worker itself, so no huge bundles for you :^)

For this to work, we'll want to add a Web Workers transport to @open-rpc/client-js (there's similar Window and IFrame transports there), then make sure it works if we pass it to the LanguageServerClient. I might look into that if I have time, but no promises here.

notpushkin avatar Nov 13 '22 22:11 notpushkin

Demo: https://codemirror-worker-lsp.ale.sh/ Source: https://gitlab.com/aedge/codemirror-web-workers-lsp-demo

The interesting bits are _transport.ts (the PostMessageWorkerTransport implementation) and _jsonWorker.ts (a JSON language server connected to Web Worker messaging). After defining those you can just call languageServerWithTransport in place of languageServer:

import { languageServerWithTransport } from 'codemirror-languageserver';
const ls = languageServerWithTransport({
	transport: new PostMessageWorkerTransport(new Worker(...)),
	rootUri: "file:///",
	workspaceFolders: null,
	documentUri: `file:///tsconfig.json`,
	languageId: "json",
});

EditorState.create({ extensions: [ ... ls ... ] })

notpushkin avatar Jan 02 '23 10:01 notpushkin

@notpushkin Thanks for sharing this. Can I borrow your comment and add it as an example to this project's README.md?

hjr265 avatar Jan 02 '23 12:01 hjr265

@hjr265 Sure!

Maybe it would be better to merge PostMessageWorkerTransport into @open-rpc/client-js first though, so that people don't end up copying it in every project? I was thinking about sending a PR later this week.

notpushkin avatar Jan 02 '23 22:01 notpushkin

@notpushkin That makes sense. I will wait for your signal then.

hjr265 avatar Jan 03 '23 03:01 hjr265

Status on the PostMessageWorkerTransport merging?

Would love to use this

DvvCz avatar Aug 23 '23 20:08 DvvCz

Unfortunately I had to deprioritize this. Sorry!

If anybody else wants to send a PR to @open-rpc/client-js, feel free to use my code.

notpushkin avatar Aug 23 '23 20:08 notpushkin