mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-18 02:38:38 +00:00
Merge #3793
3793: Add integrated test for concat include env r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
37a01de42c
2 changed files with 62 additions and 5 deletions
|
@ -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;
|
||||
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -118,7 +131,7 @@ impl Server {
|
|||
window: None,
|
||||
experimental: None,
|
||||
},
|
||||
ServerConfig { with_sysroot, ..ServerConfig::default() },
|
||||
config,
|
||||
connection,
|
||||
)
|
||||
.unwrap()
|
||||
|
|
Loading…
Reference in a new issue