Update some tests to reflect code action debouncing
This commit is contained in:
parent
5142049515
commit
791f6cf9e7
3 changed files with 50 additions and 48 deletions
|
@ -5321,7 +5321,7 @@ async fn test_collaborating_with_code_actions(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut fake_language_server = fake_language_servers.next().await.unwrap();
|
let mut fake_language_server = fake_language_servers.next().await.unwrap();
|
||||||
fake_language_server
|
let mut requests = fake_language_server
|
||||||
.handle_request::<lsp::request::CodeActionRequest, _, _>(|params, _| async move {
|
.handle_request::<lsp::request::CodeActionRequest, _, _>(|params, _| async move {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
params.text_document.uri,
|
params.text_document.uri,
|
||||||
|
@ -5330,9 +5330,9 @@ async fn test_collaborating_with_code_actions(
|
||||||
assert_eq!(params.range.start, lsp::Position::new(0, 0));
|
assert_eq!(params.range.start, lsp::Position::new(0, 0));
|
||||||
assert_eq!(params.range.end, lsp::Position::new(0, 0));
|
assert_eq!(params.range.end, lsp::Position::new(0, 0));
|
||||||
Ok(None)
|
Ok(None)
|
||||||
})
|
});
|
||||||
.next()
|
deterministic.advance_clock(editor::CODE_ACTIONS_DEBOUNCE_TIMEOUT * 2);
|
||||||
.await;
|
requests.next().await;
|
||||||
|
|
||||||
// Move cursor to a location that contains code actions.
|
// Move cursor to a location that contains code actions.
|
||||||
editor_b.update(cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
|
@ -5342,7 +5342,7 @@ async fn test_collaborating_with_code_actions(
|
||||||
cx.focus(&editor_b);
|
cx.focus(&editor_b);
|
||||||
});
|
});
|
||||||
|
|
||||||
fake_language_server
|
let mut requests = fake_language_server
|
||||||
.handle_request::<lsp::request::CodeActionRequest, _, _>(|params, _| async move {
|
.handle_request::<lsp::request::CodeActionRequest, _, _>(|params, _| async move {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
params.text_document.uri,
|
params.text_document.uri,
|
||||||
|
@ -5394,9 +5394,9 @@ async fn test_collaborating_with_code_actions(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)]))
|
)]))
|
||||||
})
|
});
|
||||||
.next()
|
deterministic.advance_clock(editor::CODE_ACTIONS_DEBOUNCE_TIMEOUT * 2);
|
||||||
.await;
|
requests.next().await;
|
||||||
|
|
||||||
// Toggle code actions and wait for them to display.
|
// Toggle code actions and wait for them to display.
|
||||||
editor_b.update(cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
|
@ -7864,6 +7864,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
client_a.language_registry().add(Arc::clone(&language));
|
client_a.language_registry().add(Arc::clone(&language));
|
||||||
client_b.language_registry().add(language);
|
client_b.language_registry().add(language);
|
||||||
|
|
||||||
|
// Client A opens a project.
|
||||||
client_a
|
client_a
|
||||||
.fs()
|
.fs()
|
||||||
.insert_tree(
|
.insert_tree(
|
||||||
|
@ -7884,6 +7885,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Client B joins the project
|
||||||
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
||||||
active_call_b
|
active_call_b
|
||||||
.update(cx_b, |call, cx| call.set_location(Some(&project_b), cx))
|
.update(cx_b, |call, cx| call.set_location(Some(&project_b), cx))
|
||||||
|
@ -7893,6 +7895,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
let workspace_a = client_a.build_workspace(&project_a, cx_a).root(cx_a);
|
let workspace_a = client_a.build_workspace(&project_a, cx_a).root(cx_a);
|
||||||
cx_a.foreground().start_waiting();
|
cx_a.foreground().start_waiting();
|
||||||
|
|
||||||
|
// The host opens a rust file.
|
||||||
let _buffer_a = project_a
|
let _buffer_a = project_a
|
||||||
.update(cx_a, |project, cx| {
|
.update(cx_a, |project, cx| {
|
||||||
project.open_local_buffer("/a/main.rs", cx)
|
project.open_local_buffer("/a/main.rs", cx)
|
||||||
|
@ -7900,7 +7903,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let fake_language_server = fake_language_servers.next().await.unwrap();
|
let fake_language_server = fake_language_servers.next().await.unwrap();
|
||||||
let next_call_id = Arc::new(AtomicU32::new(0));
|
|
||||||
let editor_a = workspace_a
|
let editor_a = workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "main.rs"), None, true, cx)
|
workspace.open_path((worktree_id, "main.rs"), None, true, cx)
|
||||||
|
@ -7909,6 +7911,9 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Set up the language server to return an additional inlay hint on each request.
|
||||||
|
let next_call_id = Arc::new(AtomicU32::new(0));
|
||||||
fake_language_server
|
fake_language_server
|
||||||
.handle_request::<lsp::request::InlayHintRequest, _, _>(move |params, _| {
|
.handle_request::<lsp::request::InlayHintRequest, _, _>(move |params, _| {
|
||||||
let task_next_call_id = Arc::clone(&next_call_id);
|
let task_next_call_id = Arc::clone(&next_call_id);
|
||||||
|
@ -7917,33 +7922,28 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
params.text_document.uri,
|
params.text_document.uri,
|
||||||
lsp::Url::from_file_path("/a/main.rs").unwrap(),
|
lsp::Url::from_file_path("/a/main.rs").unwrap(),
|
||||||
);
|
);
|
||||||
let mut current_call_id = Arc::clone(&task_next_call_id).fetch_add(1, SeqCst);
|
let call_count = task_next_call_id.fetch_add(1, SeqCst);
|
||||||
let mut new_hints = Vec::with_capacity(current_call_id as usize);
|
Ok(Some(
|
||||||
loop {
|
(0..=call_count)
|
||||||
new_hints.push(lsp::InlayHint {
|
.map(|ix| lsp::InlayHint {
|
||||||
position: lsp::Position::new(0, current_call_id),
|
position: lsp::Position::new(0, ix),
|
||||||
label: lsp::InlayHintLabel::String(current_call_id.to_string()),
|
label: lsp::InlayHintLabel::String(ix.to_string()),
|
||||||
kind: None,
|
kind: None,
|
||||||
text_edits: None,
|
text_edits: None,
|
||||||
tooltip: None,
|
tooltip: None,
|
||||||
padding_left: None,
|
padding_left: None,
|
||||||
padding_right: None,
|
padding_right: None,
|
||||||
data: None,
|
data: None,
|
||||||
});
|
})
|
||||||
if current_call_id == 0 {
|
.collect(),
|
||||||
break;
|
))
|
||||||
}
|
|
||||||
current_call_id -= 1;
|
|
||||||
}
|
|
||||||
Ok(Some(new_hints))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
cx_a.foreground().finish_waiting();
|
deterministic.run_until_parked();
|
||||||
cx_a.foreground().run_until_parked();
|
|
||||||
|
|
||||||
let mut edits_made = 1;
|
let mut edits_made = 1;
|
||||||
editor_a.update(cx_a, |editor, _| {
|
editor_a.update(cx_a, |editor, _| {
|
||||||
|
@ -7969,7 +7969,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
cx_b.foreground().run_until_parked();
|
deterministic.run_until_parked();
|
||||||
editor_b.update(cx_b, |editor, _| {
|
editor_b.update(cx_b, |editor, _| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec!["0".to_string(), "1".to_string()],
|
vec!["0".to_string(), "1".to_string()],
|
||||||
|
@ -7990,18 +7990,9 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
cx.focus(&editor_b);
|
cx.focus(&editor_b);
|
||||||
edits_made += 1;
|
edits_made += 1;
|
||||||
});
|
});
|
||||||
cx_a.foreground().run_until_parked();
|
|
||||||
cx_b.foreground().run_until_parked();
|
deterministic.run_until_parked();
|
||||||
editor_a.update(cx_a, |editor, _| {
|
editor_a.update(cx_a, |editor, _| {
|
||||||
assert_eq!(
|
|
||||||
vec!["0".to_string(), "1".to_string(), "2".to_string()],
|
|
||||||
extract_hint_labels(editor),
|
|
||||||
"Host should get hints from the 1st edit and 1st LSP query"
|
|
||||||
);
|
|
||||||
let inlay_cache = editor.inlay_hint_cache();
|
|
||||||
assert_eq!(inlay_cache.version(), edits_made);
|
|
||||||
});
|
|
||||||
editor_b.update(cx_b, |editor, _| {
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![
|
vec![
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
|
@ -8015,6 +8006,15 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
let inlay_cache = editor.inlay_hint_cache();
|
let inlay_cache = editor.inlay_hint_cache();
|
||||||
assert_eq!(inlay_cache.version(), edits_made);
|
assert_eq!(inlay_cache.version(), edits_made);
|
||||||
});
|
});
|
||||||
|
editor_b.update(cx_b, |editor, _| {
|
||||||
|
assert_eq!(
|
||||||
|
vec!["0".to_string(), "1".to_string(), "2".to_string(),],
|
||||||
|
extract_hint_labels(editor),
|
||||||
|
"Guest should get hints the 1st edit and 2nd LSP query"
|
||||||
|
);
|
||||||
|
let inlay_cache = editor.inlay_hint_cache();
|
||||||
|
assert_eq!(inlay_cache.version(), edits_made);
|
||||||
|
});
|
||||||
|
|
||||||
editor_a.update(cx_a, |editor, cx| {
|
editor_a.update(cx_a, |editor, cx| {
|
||||||
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
||||||
|
@ -8022,8 +8022,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
cx.focus(&editor_a);
|
cx.focus(&editor_a);
|
||||||
edits_made += 1;
|
edits_made += 1;
|
||||||
});
|
});
|
||||||
cx_a.foreground().run_until_parked();
|
|
||||||
cx_b.foreground().run_until_parked();
|
deterministic.run_until_parked();
|
||||||
editor_a.update(cx_a, |editor, _| {
|
editor_a.update(cx_a, |editor, _| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![
|
vec![
|
||||||
|
@ -8062,8 +8062,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.await
|
.await
|
||||||
.expect("inlay refresh request failed");
|
.expect("inlay refresh request failed");
|
||||||
edits_made += 1;
|
edits_made += 1;
|
||||||
cx_a.foreground().run_until_parked();
|
|
||||||
cx_b.foreground().run_until_parked();
|
deterministic.run_until_parked();
|
||||||
editor_a.update(cx_a, |editor, _| {
|
editor_a.update(cx_a, |editor, _| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -111,8 +111,8 @@ const MAX_LINE_LEN: usize = 1024;
|
||||||
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
|
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
|
||||||
const MAX_SELECTION_HISTORY_LEN: usize = 1024;
|
const MAX_SELECTION_HISTORY_LEN: usize = 1024;
|
||||||
const COPILOT_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
const COPILOT_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
||||||
const CODE_ACTIONS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250);
|
pub const CODE_ACTIONS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250);
|
||||||
const DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
pub const DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
||||||
|
|
||||||
pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
|
pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
|
||||||
|
|
||||||
|
|
|
@ -1706,6 +1706,8 @@ mod tests {
|
||||||
.remove_file(Path::new("/root/a/file2"), Default::default())
|
.remove_file(Path::new("/root/a/file2"), Default::default())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
cx.foreground().run_until_parked();
|
||||||
|
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |w, cx| w.go_back(w.active_pane().downgrade(), cx))
|
.update(cx, |w, cx| w.go_back(w.active_pane().downgrade(), cx))
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue