ebkalderon / tower-lsp

Language Server Protocol implementation written in Rust
Apache License 2.0
952 stars 54 forks source link

Implement support for client initiated $/progress #385

Closed ebkalderon closed 6 months ago

ebkalderon commented 1 year ago

Added

This pull request introduces a new API for emitting $/progress notifications to the client. An example might look like this:

let progress = self
    .client
    .progress(work_done_token, "Progress Title")
    .with_message("Working...")
    .with_percentage(0)
    .begin()
    .await;

for percent in 1..=100 {
    tokio::time::sleep(std::time::Duration::from_millis(50)).await;
    let msg = format!("Working... [{percent}/100]");
    progress.report_with_message(msg, percent).await;
}

progress.finish_with_message("Done!").await;

Feedback on the API and implementation is most welcome! Adapters for Iterator and Stream are not currently included due to previously unforeseen complexity stemming from the type state pattern.

Closes #380.

ebkalderon commented 6 months ago

Looks like this PR has simmered for long enough that I think it should be safe to merge!

Feel-ix-343 commented 6 months ago

This is not compiling for me:

    Checking tower-lsp v0.20.0 (https://github.com/ebkalderon/tower-lsp?rev=49e1ce5#49e1ce54)
error[E0412]: cannot find type `WorkspaceDiagnosticRefresh` in this scope
   --> /home/felix/.cargo/git/checkouts/tower-lsp-c76aca49ec8e037c/49e1ce5/src/service/client.rs:350:29
    |
350 |         self.send_request::<WorkspaceDiagnosticRefresh>(()).await
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/felix/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lsp-types-0.94.1/src/workspace_diagnostic.rs:120:1
    |
120 | pub struct WorkspaceDiagnosticReport {
    | ------------------------------------ similarly named struct `WorkspaceDiagnosticReport` defined here
    |
help: a struct with a similar name exists
    |
350 |         self.send_request::<WorkspaceDiagnosticReport>(()).await
    |                             ~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing one of these items
    |
3   + use crate::request::WorkspaceDiagnosticRefresh;
    |
3   + use lsp_types::request::WorkspaceDiagnosticRefresh;
    |

For more information about this error, try `rustc --explain E0412`.
error: could not compile `tower-lsp` (lib) due to previous error
ebkalderon commented 6 months ago

@Feel-ix-343 Ouch, thanks for the report! Perhaps there were breaking changes to the lsp-types crate in the meantime while this PR was open and then last merged? Will investigate further when I have time and open a follow-up PR, if needed. In the meantime, would you mind opening an issue to track it, please? I'd really appreciate it. :smile: We can move further discussion over there.