Create a server-initiated work-done progress token and send the `window/workDoneProgress/create` request to the client. Returns `Some(token)` on success, `None` when there is no client or the client rejects the request. The caller should pass the returned token to [`progress_begin`], [`progress_report`], and [`progress_end`].
(&self, token_name: &str)
| 1727 | /// returned token to [`progress_begin`], [`progress_report`], and |
| 1728 | /// [`progress_end`]. |
| 1729 | pub(crate) async fn progress_create(&self, token_name: &str) -> Option<NumberOrString> { |
| 1730 | use tower_lsp::lsp_types::request::WorkDoneProgressCreate; |
| 1731 | |
| 1732 | // Per the LSP spec, servers must only use |
| 1733 | // window/workDoneProgress/create when the client signals |
| 1734 | // support via the window.workDoneProgress capability. |
| 1735 | if !self |
| 1736 | .supports_work_done_progress |
| 1737 | .load(std::sync::atomic::Ordering::Relaxed) |
| 1738 | { |
| 1739 | return None; |
| 1740 | } |
| 1741 | |
| 1742 | let client = self.client.as_ref()?; |
| 1743 | let token = NumberOrString::String(token_name.to_string()); |
| 1744 | let params = WorkDoneProgressCreateParams { |
| 1745 | token: token.clone(), |
| 1746 | }; |
| 1747 | // Use a timeout to avoid deadlocking the service loop. |
| 1748 | // progress_create is a server-to-client request; if the |
| 1749 | // client is busy (e.g. flooding didClose/hover), awaiting |
| 1750 | // indefinitely could block the handler and starve other |
| 1751 | // requests. Progress reporting is best-effort, so timing |
| 1752 | // out is harmless. |
| 1753 | match tokio::time::timeout( |
| 1754 | std::time::Duration::from_secs(2), |
| 1755 | client.send_request::<WorkDoneProgressCreate>(params), |
| 1756 | ) |
| 1757 | .await |
| 1758 | { |
| 1759 | Ok(Ok(())) => Some(token), |
| 1760 | _ => None, |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | /// Send a `WorkDoneProgressBegin` notification for the given token. |
| 1765 | /// |
no test coverage detected