MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / clear_diagnostics_for_file

Method clear_diagnostics_for_file

src/diagnostics/mod.rs:1704–1744  ·  view source on GitHub ↗

Clear diagnostics for a file (e.g. on `did_close`).

(&self, uri_str: &str)

Source from the content-addressed store, hash-verified

1702
1703 /// Clear diagnostics for a file (e.g. on `did_close`).
1704 pub(crate) async fn clear_diagnostics_for_file(&self, uri_str: &str) {
1705 // Remove all per-source caches so we don't leak memory.
1706 self.diag_last_fast.lock().remove(uri_str);
1707 self.diag_last_slow.lock().remove(uri_str);
1708 // Remove cached PHPStan, PHPCS, and Mago diagnostics too.
1709 self.phpstan_last_diags.lock().remove(uri_str);
1710 self.phpcs_last_diags.lock().remove(uri_str);
1711 self.mago_lint_last_diags.lock().remove(uri_str);
1712 self.mago_analyze_last_diags.lock().remove(uri_str);
1713 // Remove pull-diagnostic caches.
1714 self.diag_result_ids.lock().remove(uri_str);
1715 self.diag_last_full.lock().remove(uri_str);
1716
1717 let client = match &self.client {
1718 Some(c) => c,
1719 None => return,
1720 };
1721
1722 let uri = match uri_str.parse::<Url>() {
1723 Ok(u) => u,
1724 Err(_) => return,
1725 };
1726
1727 // Always push empty diagnostics to clear any Phase 1 snapshot.
1728 client.publish_diagnostics(uri, Vec::new(), None).await;
1729
1730 if self.supports_pull_diagnostics.load(Ordering::Acquire) {
1731 // Tell the editor to re-pull diagnostics. We spawn this
1732 // as a detached task instead of awaiting it because
1733 // workspace_diagnostic_refresh is a server-to-client
1734 // *request* that blocks until the client responds. When
1735 // the editor closes many files in a burst, each didClose
1736 // handler would await a response while the client is busy
1737 // sending more messages, deadlocking the tower-lsp
1738 // service loop.
1739 let client = client.clone();
1740 tokio::spawn(async move {
1741 let _ = client.workspace_diagnostic_refresh().await;
1742 });
1743 }
1744 }
1745}
1746
1747// ── Deduplication ───────────────────────────────────────────────────────────

Callers 1

did_closeMethod · 0.80

Calls 3

removeMethod · 0.80
cloneMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected