Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion crates/rust-analyzer/tests/heavy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use lsp_types::{
};
use rust_analyzer::req::{
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
Formatting, OnEnter, Runnables, RunnablesParams,
Formatting, GotoDefinition, OnEnter, Runnables, RunnablesParams,
};
use serde_json::json;
use tempfile::TempDir;
Expand Down Expand Up @@ -581,3 +581,47 @@ version = \"0.0.0\"
}),
);
}

#[test]
fn resolve_include_concat_env() {
if skip_slow_tests() {
return;
}

let server = Project::with_fixture(
r###"
//- Cargo.toml
[package]
name = "foo"
version = "0.0.0"

//- build.rs
use std::{env, fs, path::Path};

fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("hello.rs");
fs::write(
&dest_path,
r#"pub fn message() -> &'static str { "Hello, World!" }"#,
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
}
//- src/main.rs
include!(concat!(env!("OUT_DIR"), "/hello.rs"));

fn main() { message(); }
"###,
)
.with_config(|config| {
config.cargo_features.load_out_dirs_from_check = true;
})
.server();
server.wait_until_workspace_is_loaded();
let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(2, 15),
));
assert!(format!("{}", res).contains("hello.rs"));
}
21 changes: 17 additions & 4 deletions crates/rust-analyzer/tests/heavy_tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ pub struct Project<'a> {
with_sysroot: bool,
tmp_dir: Option<TempDir>,
roots: Vec<PathBuf>,
config: Option<Box<dyn Fn(&mut ServerConfig)>>,
}

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

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

pub fn with_config(mut self, config: impl Fn(&mut ServerConfig) + 'static) -> Project<'a> {
self.config = Some(Box::new(config));
self
}

pub fn server(self) -> Server {
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
static INIT: Once = Once::new();
Expand All @@ -72,7 +78,14 @@ impl<'a> Project<'a> {

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

Server::new(tmp_dir, self.with_sysroot, roots, paths)
let mut config =
ServerConfig { with_sysroot: self.with_sysroot, ..ServerConfig::default() };

if let Some(f) = &self.config {
f(&mut config)
}

Server::new(tmp_dir, config, roots, paths)
}
}

Expand All @@ -92,7 +105,7 @@ pub struct Server {
impl Server {
fn new(
dir: TempDir,
with_sysroot: bool,
config: ServerConfig,
roots: Vec<PathBuf>,
files: Vec<(PathBuf, String)>,
) -> Server {
Expand All @@ -118,7 +131,7 @@ impl Server {
window: None,
experimental: None,
},
ServerConfig { with_sysroot, ..ServerConfig::default() },
config,
connection,
)
.unwrap()
Expand Down