Skip to content

Commit 9bbac8a

Browse files
committed
add a slow test
1 parent 869b6a4 commit 9bbac8a

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

crates/rust-analyzer/tests/slow-tests/main.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use lsp_types::{
2929
PartialResultParams, Position, Range, RenameFilesParams, TextDocumentItem,
3030
TextDocumentPositionParams, WorkDoneProgressParams,
3131
};
32-
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams};
32+
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject};
3333
use serde_json::json;
3434
use test_utils::skip_slow_tests;
3535

@@ -588,6 +588,66 @@ fn main() {{}}
588588
);
589589
}
590590

591+
#[test]
592+
fn test_opening_a_file_outside_of_indexed_workspace() {
593+
if skip_slow_tests() {
594+
return;
595+
}
596+
597+
let tmp_dir = TestDir::new();
598+
let path = tmp_dir.path();
599+
600+
let project = json!({
601+
"roots": [path],
602+
"crates": [ {
603+
"root_module": path.join("src/crate_one/lib.rs"),
604+
"deps": [],
605+
"edition": "2015",
606+
"cfg": [ "cfg_atom_1", "feature=\"cfg_1\""],
607+
} ]
608+
});
609+
610+
let code = format!(
611+
r#"
612+
//- /rust-project.json
613+
{project}
614+
615+
//- /src/crate_one/lib.rs
616+
mod bar;
617+
618+
fn main() {{}}
619+
"#,
620+
);
621+
622+
let server = Project::with_fixture(&code)
623+
.tmp_dir(tmp_dir)
624+
.with_config(serde_json::json!({
625+
"notifications": {
626+
"unindexedProject": true
627+
},
628+
}))
629+
.server()
630+
.wait_until_workspace_is_loaded();
631+
632+
let uri = server.doc_id(&format!("src/crate_two/lib.rs")).uri;
633+
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
634+
text_document: TextDocumentItem {
635+
uri: uri.clone(),
636+
language_id: "rust".to_string(),
637+
version: 0,
638+
text: "/// Docs\nfn foo() {}".to_string(),
639+
},
640+
});
641+
let expected = json!({
642+
"textDocuments": [
643+
{
644+
"uri": uri
645+
}
646+
]
647+
});
648+
server.expect_notification::<UnindexedProject>(expected);
649+
}
650+
591651
#[test]
592652
fn diagnostics_dont_block_typing() {
593653
if skip_slow_tests() {

crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,37 @@ impl Server {
198198
self.send_notification(r)
199199
}
200200

201+
pub(crate) fn expect_notification<N>(&self, expected: Value)
202+
where
203+
N: lsp_types::notification::Notification,
204+
N::Params: Serialize,
205+
{
206+
let msg = recv_timeout(&self.client.receiver).unwrap_or_else(|_| panic!("timed out"));
207+
208+
let Some(Message::Notification(actual)) = msg else {
209+
panic!("did not get a notification");
210+
};
211+
212+
if actual.method == N::METHOD {
213+
let actual = actual
214+
.clone()
215+
.extract::<Value>(N::METHOD)
216+
.expect("was not able to extract notification");
217+
218+
if let Some((expected_part, actual_part)) = find_mismatch(&expected, &actual) {
219+
panic!(
220+
"JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n",
221+
to_string_pretty(&expected).unwrap(),
222+
to_string_pretty(&actual).unwrap(),
223+
to_string_pretty(expected_part).unwrap(),
224+
to_string_pretty(actual_part).unwrap(),
225+
);
226+
}
227+
} else {
228+
panic!("mismatched method: {}", actual.method);
229+
}
230+
}
231+
201232
#[track_caller]
202233
pub(crate) fn request<R>(&self, params: R::Params, expected_resp: Value)
203234
where

0 commit comments

Comments
 (0)