| 711 | } |
| 712 | |
| 713 | async fn references(&self, params: ReferenceParams) -> Result<Option<Vec<Location>>> { |
| 714 | let uri = params.text_document_position.text_document.uri.to_string(); |
| 715 | let position = params.text_document_position.position; |
| 716 | let include_declaration = params.context.include_declaration; |
| 717 | let token = match params.work_done_progress_params.work_done_token { |
| 718 | Some(t) => Some(t), |
| 719 | None => self.progress_create("find_references").await, |
| 720 | }; |
| 721 | |
| 722 | if let Some(ref tok) = token { |
| 723 | self.progress_begin(tok, "Find References", Some("Scanning…".to_string())) |
| 724 | .await; |
| 725 | } |
| 726 | |
| 727 | // Run on a blocking thread so the async runtime stays free to |
| 728 | // flush progress notifications to the client. |
| 729 | // |
| 730 | // We wrap spawn_blocking inside tokio::spawn so the blocking |
| 731 | // task is always awaited to completion even if tower-lsp |
| 732 | // cancels this handler future via $/cancelRequest. Without |
| 733 | // this wrapper, dropping the handler future detaches the |
| 734 | // spawn_blocking JoinHandle, and tower-lsp 0.20 may corrupt |
| 735 | // its internal state when the orphaned task completes. |
| 736 | let backend = self.clone_for_blocking(); |
| 737 | let uri_clone = uri.clone(); |
| 738 | let result = tokio::spawn(async move { |
| 739 | tokio::task::spawn_blocking(move || { |
| 740 | backend.handle_with_position("references", &uri_clone, position, |content, pos| { |
| 741 | backend |
| 742 | .find_references(&uri_clone, content, pos, include_declaration) |
| 743 | .map(|locs| { |
| 744 | locs.into_iter() |
| 745 | .map(|l| backend.translate_location(l)) |
| 746 | .collect() |
| 747 | }) |
| 748 | }) |
| 749 | }) |
| 750 | .await |
| 751 | .unwrap_or(Ok(None)) |
| 752 | }) |
| 753 | .await |
| 754 | .unwrap_or(Ok(None)); |
| 755 | |
| 756 | if let Some(ref tok) = token { |
| 757 | self.progress_end(tok, Some("Done".to_string())).await; |
| 758 | } |
| 759 | |
| 760 | result |
| 761 | } |
| 762 | |
| 763 | async fn code_action(&self, params: CodeActionParams) -> Result<Option<CodeActionResponse>> { |
| 764 | let uri = params.text_document.uri.to_string(); |