Skip to content

Commit 37a01de

Browse files
bors[bot]matklad
andauthored
Merge #3793
3793: Add integrated test for concat include env r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 47c9ee2 + a4f9d96 commit 37a01de

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use lsp_types::{
99
};
1010
use rust_analyzer::req::{
1111
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
12-
Formatting, OnEnter, Runnables, RunnablesParams,
12+
Formatting, GotoDefinition, OnEnter, Runnables, RunnablesParams,
1313
};
1414
use serde_json::json;
1515
use tempfile::TempDir;
@@ -581,3 +581,47 @@ version = \"0.0.0\"
581581
}),
582582
);
583583
}
584+
585+
#[test]
586+
fn resolve_include_concat_env() {
587+
if skip_slow_tests() {
588+
return;
589+
}
590+
591+
let server = Project::with_fixture(
592+
r###"
593+
//- Cargo.toml
594+
[package]
595+
name = "foo"
596+
version = "0.0.0"
597+
598+
//- build.rs
599+
use std::{env, fs, path::Path};
600+
601+
fn main() {
602+
let out_dir = env::var_os("OUT_DIR").unwrap();
603+
let dest_path = Path::new(&out_dir).join("hello.rs");
604+
fs::write(
605+
&dest_path,
606+
r#"pub fn message() -> &'static str { "Hello, World!" }"#,
607+
)
608+
.unwrap();
609+
println!("cargo:rerun-if-changed=build.rs");
610+
}
611+
//- src/main.rs
612+
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
613+
614+
fn main() { message(); }
615+
"###,
616+
)
617+
.with_config(|config| {
618+
config.cargo_features.load_out_dirs_from_check = true;
619+
})
620+
.server();
621+
server.wait_until_workspace_is_loaded();
622+
let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new(
623+
server.doc_id("src/main.rs"),
624+
Position::new(2, 15),
625+
));
626+
assert!(format!("{}", res).contains("hello.rs"));
627+
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ pub struct Project<'a> {
2727
with_sysroot: bool,
2828
tmp_dir: Option<TempDir>,
2929
roots: Vec<PathBuf>,
30+
config: Option<Box<dyn Fn(&mut ServerConfig)>>,
3031
}
3132

3233
impl<'a> Project<'a> {
3334
pub fn with_fixture(fixture: &str) -> Project {
34-
Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false }
35+
Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None }
3536
}
3637

3738
pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> {
@@ -49,6 +50,11 @@ impl<'a> Project<'a> {
4950
self
5051
}
5152

53+
pub fn with_config(mut self, config: impl Fn(&mut ServerConfig) + 'static) -> Project<'a> {
54+
self.config = Some(Box::new(config));
55+
self
56+
}
57+
5258
pub fn server(self) -> Server {
5359
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
5460
static INIT: Once = Once::new();
@@ -72,7 +78,14 @@ impl<'a> Project<'a> {
7278

7379
let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
7480

75-
Server::new(tmp_dir, self.with_sysroot, roots, paths)
81+
let mut config =
82+
ServerConfig { with_sysroot: self.with_sysroot, ..ServerConfig::default() };
83+
84+
if let Some(f) = &self.config {
85+
f(&mut config)
86+
}
87+
88+
Server::new(tmp_dir, config, roots, paths)
7689
}
7790
}
7891

@@ -92,7 +105,7 @@ pub struct Server {
92105
impl Server {
93106
fn new(
94107
dir: TempDir,
95-
with_sysroot: bool,
108+
config: ServerConfig,
96109
roots: Vec<PathBuf>,
97110
files: Vec<(PathBuf, String)>,
98111
) -> Server {
@@ -118,7 +131,7 @@ impl Server {
118131
window: None,
119132
experimental: None,
120133
},
121-
ServerConfig { with_sysroot, ..ServerConfig::default() },
134+
config,
122135
connection,
123136
)
124137
.unwrap()

0 commit comments

Comments
 (0)