[ty] Add progress reporting to workspace diagnostics (#19616)

This commit is contained in:
Micha Reiser 2025-07-30 12:27:34 +02:00 committed by GitHub
parent 2a5ace6e55
commit 6237ecb4db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 450 additions and 79 deletions

View file

@ -658,7 +658,11 @@ impl TestServer {
let params = WorkspaceDiagnosticParams {
identifier: Some("ty".to_string()),
previous_result_ids: previous_result_ids.unwrap_or_default(),
work_done_progress_params: WorkDoneProgressParams::default(),
work_done_progress_params: WorkDoneProgressParams {
work_done_token: Some(lsp_types::NumberOrString::String(
"test-progress-token".to_string(),
)),
},
partial_result_params: PartialResultParams::default(),
};

View file

@ -5,7 +5,7 @@ use lsp_types::{
use ruff_db::system::SystemPath;
use ty_server::{ClientOptions, DiagnosticMode};
use crate::TestServerBuilder;
use crate::{TestServer, TestServerBuilder};
#[test]
fn on_did_open() -> Result<()> {
@ -234,8 +234,12 @@ def foo() -> str:
// First request with no previous result IDs
let first_response = server.workspace_diagnostic_request(None)?;
insta::assert_debug_snapshot!("workspace_diagnostic_initial_state", first_response);
// Consume all progress notifications sent during workspace diagnostics
consume_all_progress_notifications(&mut server)?;
// Extract result IDs from the first response
let previous_result_ids = match first_response {
WorkspaceDiagnosticReportResult::Report(report) => {
@ -317,6 +321,10 @@ def foo() -> str:
// - File D: Full report (diagnostic content changed)
// - File E: Full report (the range changes)
let second_response = server.workspace_diagnostic_request(Some(previous_result_ids))?;
// Consume all progress notifications sent during the second workspace diagnostics
consume_all_progress_notifications(&mut server)?;
insta::assert_debug_snapshot!("workspace_diagnostic_after_changes", second_response);
Ok(())
@ -328,3 +336,31 @@ fn filter_result_id() -> insta::internals::SettingsBindDropGuard {
settings.add_filter(r#""[a-f0-9]{16}""#, r#""[RESULT_ID]""#);
settings.bind_to_scope()
}
fn consume_all_progress_notifications(server: &mut TestServer) -> Result<()> {
// Always consume Begin
let begin_params = server.await_notification::<lsp_types::notification::Progress>()?;
// The params are already the ProgressParams type
let lsp_types::ProgressParamsValue::WorkDone(lsp_types::WorkDoneProgress::Begin(_)) =
begin_params.value
else {
return Err(anyhow::anyhow!("Expected Begin progress notification"));
};
// Consume Report notifications - there may be multiple based on number of files
// Keep consuming until we hit the End notification
loop {
let params = server.await_notification::<lsp_types::notification::Progress>()?;
if let lsp_types::ProgressParamsValue::WorkDone(lsp_types::WorkDoneProgress::End(_)) =
params.value
{
// Found the End notification, we're done
break;
}
// Otherwise it's a Report notification, continue
}
Ok(())
}

View file

@ -64,7 +64,8 @@ expression: initialization_result
"diagnosticProvider": {
"identifier": "ty",
"interFileDependencies": true,
"workspaceDiagnostics": false
"workspaceDiagnostics": false,
"workDoneProgress": false
}
},
"serverInfo": {

View file

@ -64,7 +64,8 @@ expression: initialization_result
"diagnosticProvider": {
"identifier": "ty",
"interFileDependencies": true,
"workspaceDiagnostics": false
"workspaceDiagnostics": false,
"workDoneProgress": false
}
},
"serverInfo": {