Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to access Client outside the callbacks #188

Closed
icsaszar opened this issue May 24, 2020 · 3 comments
Closed

Provide a way to access Client outside the callbacks #188

icsaszar opened this issue May 24, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@icsaszar
Copy link
Contributor

Currently tower-lsp works great for servers that use a task based model. But consider the case when
you have a file system watcher, as a process task/process that is idependent from the language server task.

let server = initialize_server(...);
let watcher = initialize_watcher(...);
futures::join!(server, watcher);

When the watcher sees a change, it reparses a file, does some analysis and sends the diagnostics to the client. The problem is how can it acces the Client that is normally provided by tower-lsp in the callbacks?

One way could be to set up the language server with a oneshot channel with the other process waiting on the other side and send the Client from the initialized method, but this seems a bit hacky.

What would be a much more elegant solution would be returning a clone of the client when the service is created, like this:

let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();

let (client, service, messages) = LspService::new(backend);
  // ^^^^^^ access to client
Server::new(stdin, stdout)
   .interleave(messages)
   .serve(service)
   .await;

Of course with the caveat that the client will panic if it's used before the server is initalized. But this can be solved by providing a method on the client that can be used to check if the server is initialized before sending a message.

As with other issues, this will be affected by #102 and related rewrite issues (#177, #58), so maybe it's worth waiting with this, as it's not a major inconvenience.

@icsaszar icsaszar changed the title Provide a way to acces Client outside the callbacks Provide a way to access Client outside the callbacks May 24, 2020
@ebkalderon
Copy link
Owner

Thanks for the suggestion, @icsaszar! I'm not fully convinced we should expose the Client outside the LspService, since I feel it somewhat breaks the encapsulation of server and client, design-wise, and I can't really imagine what access to the Client would be used for outside the server. Would you mind elaborating on a potential use case for this?

@ebkalderon ebkalderon added the enhancement New feature or request label Jun 20, 2020
@ebkalderon
Copy link
Owner

Is it not possible for the watcher to be spawned at initialization time as part of the server using tokio::spawn()?

@ebkalderon
Copy link
Owner

Continuing discussion in #189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants