FurqanSoftware / codemirror-languageserver

Language Server integration for CodeMirror 6
BSD 3-Clause "New" or "Revised" License
183 stars 24 forks source link

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

Open NullVoxPopuli opened 2 years ago

NullVoxPopuli commented 2 years ago

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?

notpushkin commented 1 year ago

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 commented 1 year ago

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 ... ] })
hjr265 commented 1 year ago

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

notpushkin commented 1 year ago

@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.

hjr265 commented 1 year ago

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

DvvCz commented 1 year ago

Status on the PostMessageWorkerTransport merging?

Would love to use this

notpushkin commented 1 year ago

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.