Code Monkey home page Code Monkey logo

Comments (7)

notpushkin avatar notpushkin commented on May 23, 2024 5

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 ... ] })

from codemirror-languageserver.

hjr265 avatar hjr265 commented on May 23, 2024 1

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

from codemirror-languageserver.

notpushkin avatar notpushkin commented on May 23, 2024 1

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.

from codemirror-languageserver.

notpushkin avatar notpushkin commented on May 23, 2024

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.

from codemirror-languageserver.

notpushkin avatar notpushkin commented on May 23, 2024

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

from codemirror-languageserver.

hjr265 avatar hjr265 commented on May 23, 2024

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

from codemirror-languageserver.

DvvCz avatar DvvCz commented on May 23, 2024

Status on the PostMessageWorkerTransport merging?

Would love to use this

from codemirror-languageserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.