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

Method diagnostic

src/server.rs:1196–1256  ·  view source on GitHub ↗
(
        &self,
        params: DocumentDiagnosticParams,
    )

Source from the content-addressed store, hash-verified

1194 }
1195
1196 async fn diagnostic(
1197 &self,
1198 params: DocumentDiagnosticParams,
1199 ) -> Result<DocumentDiagnosticReportResult> {
1200 let uri_str = params.text_document.uri.to_string();
1201
1202 // Check resultId — if the client sends back the same resultId we
1203 // last returned AND the full cache is still present (not
1204 // invalidated by schedule_diagnostics), the diagnostics have not
1205 // changed and we can return Unchanged immediately.
1206 let cache_present = self.diag_last_full.lock().contains_key(&uri_str);
1207 if cache_present && let Some(prev_id) = &params.previous_result_id {
1208 let ids = self.diag_result_ids.lock();
1209 if let Some(&current_id) = ids.get(&uri_str)
1210 && prev_id == &current_id.to_string()
1211 {
1212 return Ok(DocumentDiagnosticReportResult::Report(
1213 DocumentDiagnosticReport::Unchanged(RelatedUnchangedDocumentDiagnosticReport {
1214 related_documents: None,
1215 unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport {
1216 result_id: current_id.to_string(),
1217 },
1218 }),
1219 ));
1220 }
1221 }
1222
1223 // In pull mode the pull request *triggers* native diagnostic
1224 // computation (no debounce — the IDE decided "now is the time").
1225 // If the full cache is missing for this URI, run the native
1226 // pipeline immediately and block until it finishes. External
1227 // tool results (PHPStan, PHPCS, Mago) are delivered
1228 // incrementally via publishDiagnostics as each finishes; we do
1229 // not block on them here to keep the pull response fast.
1230 let needs_compute = {
1231 let cache = self.diag_last_full.lock();
1232 !cache.contains_key(&uri_str)
1233 };
1234
1235 if needs_compute {
1236 self.trigger_diagnostics_for_pull(&uri_str).await;
1237 }
1238
1239 let (diagnostics, result_id) = {
1240 let cache = self.diag_last_full.lock();
1241 let ids = self.diag_result_ids.lock();
1242 let diags = cache.get(&uri_str).cloned().unwrap_or_default();
1243 let rid = ids.get(&uri_str).copied().unwrap_or(0).to_string();
1244 (diags, rid)
1245 };
1246
1247 Ok(DocumentDiagnosticReportResult::Report(
1248 DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
1249 related_documents: None,
1250 full_document_diagnostic_report: FullDocumentDiagnosticReport {
1251 result_id: Some(result_id),
1252 items: diagnostics,
1253 },

Callers

nothing calls this directly

Calls 2

getMethod · 0.45

Tested by

no test coverage detected