(
&mut self,
project_root: &Path,
documents: Vec<LspDocument>,
timeouts: LspRefreshTimeouts,
)
| 180 | } |
| 181 | |
| 182 | pub async fn collect_document_diagnostics( |
| 183 | &mut self, |
| 184 | project_root: &Path, |
| 185 | documents: Vec<LspDocument>, |
| 186 | timeouts: LspRefreshTimeouts, |
| 187 | ) -> Result<Vec<CodeDiagnostic>> { |
| 188 | let mut uri_to_document = BTreeMap::new(); |
| 189 | for document in &documents { |
| 190 | let uri = file_uri(&project_root.join(&document.relative_path)); |
| 191 | uri_to_document.insert(uri.clone(), document.clone()); |
| 192 | let next_version = self.document_versions.get(&uri).copied().unwrap_or(0) + 1; |
| 193 | if next_version == 1 { |
| 194 | write_message_with_timeout( |
| 195 | &mut self.stdin, |
| 196 | json!({ |
| 197 | "jsonrpc": "2.0", |
| 198 | "method": "textDocument/didOpen", |
| 199 | "params": { |
| 200 | "textDocument": { |
| 201 | "uri": uri, |
| 202 | "languageId": document.language_id, |
| 203 | "version": next_version, |
| 204 | "text": document.text, |
| 205 | } |
| 206 | } |
| 207 | }), |
| 208 | timeouts.message_io, |
| 209 | ) |
| 210 | .await?; |
| 211 | } |
| 212 | let change_version = next_version + 1; |
| 213 | write_message_with_timeout( |
| 214 | &mut self.stdin, |
| 215 | json!({ |
| 216 | "jsonrpc": "2.0", |
| 217 | "method": "textDocument/didChange", |
| 218 | "params": { |
| 219 | "textDocument": { |
| 220 | "uri": uri, |
| 221 | "version": change_version |
| 222 | }, |
| 223 | "contentChanges": [{ |
| 224 | "text": document.text, |
| 225 | }] |
| 226 | } |
| 227 | }), |
| 228 | timeouts.message_io, |
| 229 | ) |
| 230 | .await?; |
| 231 | self.document_versions.insert(uri, change_version); |
| 232 | } |
| 233 | |
| 234 | let mut diagnostics_by_uri: BTreeMap<String, Vec<CodeDiagnostic>> = BTreeMap::new(); |
| 235 | let quiet_deadline = tokio::time::Instant::now() + timeouts.diagnostics_quiet; |
| 236 | loop { |
| 237 | let now = tokio::time::Instant::now(); |
| 238 | if now >= quiet_deadline { |
| 239 | break; |
no test coverage detected