codemirror-languageserver
codemirror-languageserver copied to clipboard
How would you configure this if you don't have a server?
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?
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.
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 Thanks for sharing this. Can I borrow your comment and add it as an example to this project's README.md?
@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 That makes sense. I will wait for your signal then.
Status on the PostMessageWorkerTransport merging?
Would love to use this
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.