internal: Fetch toolchain and datalayout for DetachedFiles

This commit is contained in:
Lukas Wirth 2024-02-20 10:40:39 +01:00
parent 2223b4fa71
commit d93096ecc0
29 changed files with 164 additions and 80 deletions

View file

@ -4,7 +4,7 @@ use std::mem;
use cfg::{CfgAtom, CfgExpr};
use ide::{Cancellable, CrateId, FileId, RunnableKind, TestId};
use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
use project_model::{CargoFeatures, ManifestPath, TargetKind};
use rustc_hash::FxHashSet;
use vfs::AbsPathBuf;
@ -208,7 +208,6 @@ fn required_features(cfg_expr: &CfgExpr, features: &mut Vec<String>) {
mod tests {
use super::*;
use cfg::CfgExpr;
use mbe::{syntax_node_to_token_tree, DummyTestSpanMap, DUMMY};
use syntax::{
ast::{self, AstNode},

View file

@ -13,7 +13,7 @@ use ide_db::{
LineIndexDatabase,
};
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
use lsp_types::{self, lsif};
use lsp_types::lsif;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use rustc_hash::FxHashMap;
use vfs::{AbsPathBuf, Vfs};

View file

@ -5,7 +5,8 @@ use std::{cell::RefCell, fs::read_to_string, panic::AssertUnwindSafe, path::Path
use hir::{Change, Crate};
use ide::{AnalysisHost, DiagnosticCode, DiagnosticsConfig};
use profile::StopWatch;
use project_model::{CargoConfig, ProjectWorkspace, RustLibSource, Sysroot};
use project_model::target_data_layout::RustcDataLayoutConfig;
use project_model::{target_data_layout, CargoConfig, ProjectWorkspace, RustLibSource, Sysroot};
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
use rustc_hash::FxHashMap;
@ -60,15 +61,22 @@ impl Tester {
std::fs::write(&tmp_file, "")?;
let cargo_config =
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
let sysroot =
Ok(Sysroot::discover(tmp_file.parent().unwrap(), &cargo_config.extra_env, false)
.unwrap());
let data_layout = target_data_layout::get(
RustcDataLayoutConfig::Rustc(sysroot.as_ref().ok()),
None,
&cargo_config.extra_env,
);
let workspace = ProjectWorkspace::DetachedFiles {
files: vec![tmp_file.clone()],
sysroot: Ok(Sysroot::discover(
tmp_file.parent().unwrap(),
&cargo_config.extra_env,
false,
)
.unwrap()),
sysroot,
rustc_cfg: vec![],
toolchain: None,
target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())),
};
let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: false,

View file

@ -324,7 +324,7 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
#[cfg(test)]
mod test {
use super::*;
use ide::{AnalysisHost, FilePosition, StaticIndex, TextSize};
use ide::{AnalysisHost, FilePosition, TextSize};
use scip::symbol::format_symbol;
use test_fixture::ChangeFixture;