mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Change existing OUT_DIR override config to make use of new infrastructure
This commit is contained in:
parent
33c6c7abc6
commit
f5a2fcf8f5
8 changed files with 26 additions and 57 deletions
|
@ -39,6 +39,9 @@ pub struct CargoFeatures {
|
||||||
|
|
||||||
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
|
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
|
||||||
pub load_out_dirs_from_check: bool,
|
pub load_out_dirs_from_check: bool,
|
||||||
|
|
||||||
|
/// Fine grained controls for additional `OUT_DIR` env variables
|
||||||
|
pub out_dir_overrides: FxHashMap<PackageId, PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CargoFeatures {
|
impl Default for CargoFeatures {
|
||||||
|
@ -48,6 +51,7 @@ impl Default for CargoFeatures {
|
||||||
all_features: true,
|
all_features: true,
|
||||||
features: Vec::new(),
|
features: Vec::new(),
|
||||||
load_out_dirs_from_check: false,
|
load_out_dirs_from_check: false,
|
||||||
|
out_dir_overrides: FxHashMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,6 +195,10 @@ impl CargoWorkspace {
|
||||||
if cargo_features.load_out_dirs_from_check {
|
if cargo_features.load_out_dirs_from_check {
|
||||||
out_dir_by_id = load_out_dirs(cargo_toml, cargo_features);
|
out_dir_by_id = load_out_dirs(cargo_toml, cargo_features);
|
||||||
}
|
}
|
||||||
|
// We explicitly extend afterwards to allow overriding the value returned by cargo
|
||||||
|
out_dir_by_id.extend(
|
||||||
|
cargo_features.out_dir_overrides.iter().map(|(id, path)| (id.clone(), path.clone())),
|
||||||
|
);
|
||||||
|
|
||||||
let mut pkg_by_id = FxHashMap::default();
|
let mut pkg_by_id = FxHashMap::default();
|
||||||
let mut packages = Arena::default();
|
let mut packages = Arena::default();
|
||||||
|
|
|
@ -177,7 +177,6 @@ impl ProjectWorkspace {
|
||||||
pub fn to_crate_graph(
|
pub fn to_crate_graph(
|
||||||
&self,
|
&self,
|
||||||
default_cfg_options: &CfgOptions,
|
default_cfg_options: &CfgOptions,
|
||||||
additional_out_dirs: &FxHashMap<String, PathBuf>,
|
|
||||||
extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
|
extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
|
||||||
load: &mut dyn FnMut(&Path) -> Option<FileId>,
|
load: &mut dyn FnMut(&Path) -> Option<FileId>,
|
||||||
) -> CrateGraph {
|
) -> CrateGraph {
|
||||||
|
@ -251,15 +250,8 @@ impl ProjectWorkspace {
|
||||||
opts
|
opts
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut env = Env::default();
|
let env = Env::default();
|
||||||
let mut extern_source = ExternSource::default();
|
let extern_source = ExternSource::default();
|
||||||
if let Some(path) = additional_out_dirs.get(krate.name(&sysroot)) {
|
|
||||||
env.set("OUT_DIR", path.to_string_lossy().to_string());
|
|
||||||
if let Some(extern_source_id) = extern_source_roots.get(path) {
|
|
||||||
extern_source.set_extern_path(&path, *extern_source_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
Edition::Edition2018,
|
Edition::Edition2018,
|
||||||
|
@ -310,19 +302,11 @@ impl ProjectWorkspace {
|
||||||
};
|
};
|
||||||
let mut env = Env::default();
|
let mut env = Env::default();
|
||||||
let mut extern_source = ExternSource::default();
|
let mut extern_source = ExternSource::default();
|
||||||
if let Some(out_dir) = dbg!(pkg.out_dir(cargo)) {
|
if let Some(out_dir) = pkg.out_dir(cargo) {
|
||||||
|
// FIXME: We probably mangle non UTF-8 paths here, figure out a better solution
|
||||||
env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
|
env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
|
||||||
if let Some(extern_source_id) =
|
if let Some(&extern_source_id) = extern_source_roots.get(out_dir) {
|
||||||
dbg!(dbg!(&extern_source_roots).get(out_dir))
|
extern_source.set_extern_path(&out_dir, extern_source_id);
|
||||||
{
|
|
||||||
extern_source.set_extern_path(&out_dir, *extern_source_id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(path) = additional_out_dirs.get(pkg.name(&cargo)) {
|
|
||||||
env.set("OUT_DIR", path.to_string_lossy().to_string());
|
|
||||||
if let Some(extern_source_id) = extern_source_roots.get(path) {
|
|
||||||
extern_source.set_extern_path(&path, *extern_source_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
|
|
|
@ -53,19 +53,14 @@ pub(crate) fn load_cargo(
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: outdirs?
|
// FIXME: outdirs?
|
||||||
let outdirs = FxHashMap::default();
|
|
||||||
let extern_source_roots = FxHashMap::default();
|
let extern_source_roots = FxHashMap::default();
|
||||||
|
|
||||||
let crate_graph = ws.to_crate_graph(
|
let crate_graph =
|
||||||
&default_cfg_options,
|
ws.to_crate_graph(&default_cfg_options, &extern_source_roots, &mut |path: &Path| {
|
||||||
&outdirs,
|
|
||||||
&extern_source_roots,
|
|
||||||
&mut |path: &Path| {
|
|
||||||
let vfs_file = vfs.load(path);
|
let vfs_file = vfs.load(path);
|
||||||
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
|
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
|
||||||
vfs_file.map(vfs_file_to_id)
|
vfs_file.map(vfs_file_to_id)
|
||||||
},
|
});
|
||||||
);
|
|
||||||
log::debug!("crate graph: {:?}", crate_graph);
|
log::debug!("crate graph: {:?}", crate_graph);
|
||||||
|
|
||||||
let source_roots = roots
|
let source_roots = roots
|
||||||
|
|
|
@ -48,9 +48,6 @@ pub struct ServerConfig {
|
||||||
/// Fine grained feature flags to disable specific features.
|
/// Fine grained feature flags to disable specific features.
|
||||||
pub feature_flags: FxHashMap<String, bool>,
|
pub feature_flags: FxHashMap<String, bool>,
|
||||||
|
|
||||||
/// Fine grained controls for additional `OUT_DIR` env variables
|
|
||||||
pub additional_out_dirs: FxHashMap<String, String>,
|
|
||||||
|
|
||||||
pub rustfmt_args: Vec<String>,
|
pub rustfmt_args: Vec<String>,
|
||||||
|
|
||||||
/// Cargo feature configurations.
|
/// Cargo feature configurations.
|
||||||
|
@ -76,7 +73,6 @@ impl Default for ServerConfig {
|
||||||
cargo_watch_all_targets: true,
|
cargo_watch_all_targets: true,
|
||||||
with_sysroot: true,
|
with_sysroot: true,
|
||||||
feature_flags: FxHashMap::default(),
|
feature_flags: FxHashMap::default(),
|
||||||
additional_out_dirs: FxHashMap::default(),
|
|
||||||
cargo_features: Default::default(),
|
cargo_features: Default::default(),
|
||||||
rustfmt_args: Vec::new(),
|
rustfmt_args: Vec::new(),
|
||||||
vscode_lldb: false,
|
vscode_lldb: false,
|
||||||
|
|
|
@ -204,7 +204,6 @@ pub fn main_loop(
|
||||||
Watch(!config.use_client_watching),
|
Watch(!config.use_client_watching),
|
||||||
options,
|
options,
|
||||||
feature_flags,
|
feature_flags,
|
||||||
config.additional_out_dirs,
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@ impl WorldState {
|
||||||
watch: Watch,
|
watch: Watch,
|
||||||
options: Options,
|
options: Options,
|
||||||
feature_flags: FeatureFlags,
|
feature_flags: FeatureFlags,
|
||||||
additional_out_dirs: FxHashMap<String, String>,
|
|
||||||
) -> WorldState {
|
) -> WorldState {
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
|
|
||||||
|
@ -105,8 +104,7 @@ impl WorldState {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut extern_dirs: FxHashSet<_> =
|
let mut extern_dirs = FxHashSet::default();
|
||||||
additional_out_dirs.iter().map(|(_, path)| (PathBuf::from(path))).collect();
|
|
||||||
for ws in workspaces.iter() {
|
for ws in workspaces.iter() {
|
||||||
extern_dirs.extend(ws.out_dirs());
|
extern_dirs.extend(ws.out_dirs());
|
||||||
}
|
}
|
||||||
|
@ -152,21 +150,9 @@ impl WorldState {
|
||||||
vfs_file.map(|f| FileId(f.0))
|
vfs_file.map(|f| FileId(f.0))
|
||||||
};
|
};
|
||||||
|
|
||||||
let additional_out_dirs: FxHashMap<String, PathBuf> = additional_out_dirs
|
|
||||||
.into_iter()
|
|
||||||
.map(|(name, path)| (name, PathBuf::from(&path)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
workspaces
|
workspaces
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ws| {
|
.map(|ws| ws.to_crate_graph(&default_cfg_options, &extern_source_roots, &mut load))
|
||||||
ws.to_crate_graph(
|
|
||||||
&default_cfg_options,
|
|
||||||
&additional_out_dirs,
|
|
||||||
&extern_source_roots,
|
|
||||||
&mut load,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.for_each(|graph| {
|
.for_each(|graph| {
|
||||||
crate_graph.extend(graph);
|
crate_graph.extend(graph);
|
||||||
});
|
});
|
||||||
|
|
|
@ -237,11 +237,6 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "Whether to ask for permission before downloading any files from the Internet"
|
"description": "Whether to ask for permission before downloading any files from the Internet"
|
||||||
},
|
},
|
||||||
"rust-analyzer.additionalOutDirs": {
|
|
||||||
"type": "object",
|
|
||||||
"default": {},
|
|
||||||
"markdownDescription": "Fine grained controls for OUT_DIR `env!(\"OUT_DIR\")` variable. e.g. `{\"foo\":\"/path/to/foo\"}`, "
|
|
||||||
},
|
|
||||||
"rust-analyzer.serverPath": {
|
"rust-analyzer.serverPath": {
|
||||||
"type": [
|
"type": [
|
||||||
"null",
|
"null",
|
||||||
|
@ -367,6 +362,11 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
|
"markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
|
||||||
|
},
|
||||||
|
"rust-analyzer.cargoFeatures.outDirOverrides": {
|
||||||
|
"type": "object",
|
||||||
|
"default": {},
|
||||||
|
"markdownDescription": "Fine grained controls for OUT_DIR `env!(\"OUT_DIR\")` variable. e.g. `{\"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\":\"/path/to/foo\"}`, "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,6 +23,7 @@ export interface CargoFeatures {
|
||||||
allFeatures: boolean;
|
allFeatures: boolean;
|
||||||
features: string[];
|
features: string[];
|
||||||
loadOutDirsFromCheck: boolean;
|
loadOutDirsFromCheck: boolean;
|
||||||
|
outDirOverrides: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum UpdatesChannel {
|
export const enum UpdatesChannel {
|
||||||
|
@ -203,7 +204,6 @@ export class Config {
|
||||||
get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
|
get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
|
||||||
get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
|
get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
|
||||||
get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
|
get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
|
||||||
get additionalOutDirs() { return this.cfg.get("additionalOutDirs") as Record<string, string>; }
|
|
||||||
get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; }
|
get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; }
|
||||||
get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; }
|
get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; }
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ export class Config {
|
||||||
allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
|
allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
|
||||||
features: this.cfg.get("cargoFeatures.features") as string[],
|
features: this.cfg.get("cargoFeatures.features") as string[],
|
||||||
loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean,
|
loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean,
|
||||||
|
outDirOverrides: this.cfg.get("cargoFeatures.outDirOverrides") as Record<string, string>,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue