Skip to content

feat: Load sysroot library via cargo metadata #17795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
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
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/bind_unused_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O

acc.add(
AssistId("bind_unused_param", AssistKind::QuickFix),
&format!("Bind as `let _ = {ident_pat};`"),
format!("Bind as `let _ = {ident_pat};`"),
param.syntax().text_range(),
|builder| {
let line_index = ctx.db().line_index(ctx.file_id().into());
Expand Down
4 changes: 2 additions & 2 deletions crates/load-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ide_db::{
use itertools::Itertools;
use proc_macro_api::{MacroDylib, ProcMacroServer};
use project_model::{
CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
};
use span::Span;
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
Expand Down Expand Up @@ -247,7 +247,7 @@ impl ProjectFolders {
let mut file_set_roots: Vec<VfsPath> = vec![];
let mut entries = vec![];

if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
if let Some(manifest) = ws.manifest().map(|it| it.to_path_buf()) {
file_set_roots.push(VfsPath::from(manifest.to_owned()));
entries.push(manifest.to_owned());
}
Expand Down
4 changes: 4 additions & 0 deletions crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ impl AbsPathBuf {
pub fn push<P: AsRef<Utf8Path>>(&mut self, suffix: P) {
self.0.push(suffix)
}

pub fn join(&self, path: impl AsRef<Utf8Path>) -> Self {
Self(self.0.join(path))
}
}

impl fmt::Display for AbsPathBuf {
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl WorkspaceBuildScripts {
cmd.args(&config.extra_args);

cmd.arg("--manifest-path");
cmd.arg(manifest_path.as_ref());
cmd.arg(manifest_path);

if let Some(target_dir) = &config.target_dir {
cmd.arg("--target-dir").arg(target_dir);
Expand Down
6 changes: 4 additions & 2 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub struct CargoConfig {
pub target: Option<String>,
/// Sysroot loading behavior
pub sysroot: Option<RustLibSource>,
/// Whether to invoke `cargo metadata` on the sysroot crate.
pub sysroot_query_metadata: bool,
pub sysroot_src: Option<AbsPathBuf>,
/// rustc private crate source
pub rustc_source: Option<RustLibSource>,
Expand Down Expand Up @@ -259,6 +257,7 @@ impl CargoWorkspace {
current_dir: &AbsPath,
config: &CargoConfig,
sysroot: &Sysroot,
locked: bool,
progress: &dyn Fn(String),
) -> anyhow::Result<cargo_metadata::Metadata> {
let targets = find_list_of_build_targets(config, cargo_toml, sysroot);
Expand Down Expand Up @@ -312,6 +311,9 @@ impl CargoWorkspace {
// opt into it themselves.
other_options.push("-Zscript".to_owned());
}
if locked {
other_options.push("--locked".to_owned());
}
meta.other_options(other_options);

// FIXME: Fetching metadata is a slow process, as it might require
Expand Down
12 changes: 12 additions & 0 deletions crates/project-model/src/manifest_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ impl AsRef<AbsPath> for ManifestPath {
}
}

impl AsRef<std::path::Path> for ManifestPath {
fn as_ref(&self) -> &std::path::Path {
self.file.as_ref()
}
}

impl AsRef<std::ffi::OsStr> for ManifestPath {
fn as_ref(&self) -> &std::ffi::OsStr {
self.file.as_ref()
}
}

impl Borrow<AbsPath> for ManifestPath {
fn borrow(&self) -> &AbsPath {
self.file.borrow()
Expand Down
Loading