Opens or refreshes a file in all matching LSP clients. Mirrors the TS `LSP.touchFile(input, waitForDiagnostics)`. - Reads the file content from disk - For each registered client whose id matches the file's language, calls `open_document` (which internally handles didOpen vs didChange) - If `wait_for_diagnostics` is true, waits briefly for diagnostics to arrive
(
&self,
path: &Path,
wait_for_diagnostics: bool,
)
| 850 | /// calls `open_document` (which internally handles didOpen vs didChange) |
| 851 | /// - If `wait_for_diagnostics` is true, waits briefly for diagnostics to arrive |
| 852 | pub async fn touch_file( |
| 853 | &self, |
| 854 | path: &Path, |
| 855 | wait_for_diagnostics: bool, |
| 856 | ) -> Result<(), LspError> { |
| 857 | let language = detect_language(path); |
| 858 | let content = tokio::fs::read_to_string(path) |
| 859 | .await |
| 860 | .map_err(|e| LspError::IoError(e))?; |
| 861 | |
| 862 | let clients = self.clients.read().await; |
| 863 | let matching: Vec<Arc<LspClient>> = clients |
| 864 | .iter() |
| 865 | .filter(|(id, _)| id.contains(language)) |
| 866 | .map(|(_, c)| c.clone()) |
| 867 | .collect(); |
| 868 | drop(clients); |
| 869 | |
| 870 | for client in &matching { |
| 871 | if let Err(e) = client.open_document(path, &content, language).await { |
| 872 | error!("Failed to touch file {:?} in LSP: {}", path, e); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | if wait_for_diagnostics && !matching.is_empty() { |
| 877 | // Give LSP servers a moment to produce diagnostics. |
| 878 | // The TS version uses client.waitForDiagnostics which listens |
| 879 | // for a publishDiagnostics notification. We approximate this |
| 880 | // with a short sleep, since the broadcast-based event system |
| 881 | // already stores diagnostics as they arrive. |
| 882 | tokio::time::sleep(std::time::Duration::from_millis(200)).await; |
| 883 | } |
| 884 | |
| 885 | Ok(()) |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | impl Default for LspClientRegistry { |
no test coverage detected