You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 clientServer::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.
The text was updated successfully, but these errors were encountered:
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
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?
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.
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 bytower-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:
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.
The text was updated successfully, but these errors were encountered: