Giter Club home page Giter Club logo

Comments (6)

cactusdualcore avatar cactusdualcore commented on September 23, 2024 1

Considering that the vsc extension might need a significant rewrite, it might be a good idea to "move" it into this repo as well. Might make versioning and updating easier.

from cargo-wgsl.

cactusdualcore avatar cactusdualcore commented on September 23, 2024

I think the tower-lsp crate might be potentially useful too. It uses lsp-types internally, but includes much functionality of an lsp server already, like concurrently handling incoming requests and routing, than lsp-server.
This uses tokio already so tower seems like a natural choice to me.

from cargo-wgsl.

cactusdualcore avatar cactusdualcore commented on September 23, 2024

I'd like to quickly show tower-lsp here

// this is shared data for handlers e.g. config. It must be thread safe
pub struct MyLanguageServer { client: Client /* other fields can go here */ }

The LanguageServer trait is how to respond to requests

#[tower_lsp::async_trait]
impl LanguageServer for MyLanguageServer {
    // `InitializeParams` includes client-side configs among other things.
    // The crate passes immutable refs, so working with `self` is inconvenient, because it requires
    // thread-safe (`Sync`) interior mutability. Both `tokio` and the `once_cell` crate have a `OnceCell`
    // which I find make it easier. I prefer the latter because of its cleaner interface.
    async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
        Ok(InitializeResult::default())
    }

    // called upon requesting graceful shut down. This is different from process exit.
    async fn shutdown(&self) -> Result<()> { Ok(()) }

    // LSP events are modeled as functions on this trait, which makes implementing them straightforward,
    // but all references are immutable so they have have the same inconveniences as `initialize` 
    async fn did_open(&self, params: DidOpenTextDocumentParams) {}
}

This is how to start the server

let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
    let stdin = tokio::io::stdin();
    let stdout = tokio::io::stdout();
    let (service, socket) = LspService::new(MyLanguageServer::new); // MyLanguageServer::new(Client) -> Self
    Server::new(stdin, stdout, socket).serve(service).await;
})

from cargo-wgsl.

Runi-c avatar Runi-c commented on September 23, 2024

@PolyMeilex Would you be open to a PR migrating the current functionality of cargo-wgsl to LSP using tower-lsp as suggested above? Potentially with a companion PR for vscode-wgsl to support it as well?

from cargo-wgsl.

PolyMeilex avatar PolyMeilex commented on September 23, 2024

Sure, as long as we have vscode PR for that as well, my implementation got stuck on that as far as I remember, as I was too lazy to port the extension 😄

I did not see the need for tower-lsp when doing my impl, but if that makes your life or code simpler, then sure feel free to go ahead with that.

from cargo-wgsl.

cactusdualcore avatar cactusdualcore commented on September 23, 2024

tower-lsp is great because it requires barely any boilerplate. So less code to maintain.

from cargo-wgsl.

Related Issues (7)

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.