CrateOrigin::Local means local to the project workspace, not cargo workspace

This commit is contained in:
Lukas Wirth 2024-02-16 16:28:17 +01:00
parent 0ccb3b8731
commit ead369117a
17 changed files with 73 additions and 332 deletions

View File

@ -293,62 +293,6 @@ pub struct CrateData {
pub is_proc_macro: bool, pub is_proc_macro: bool,
} }
impl CrateData {
/// Check if [`other`] is almost equal to [`self`] ignoring `CrateOrigin` value.
pub fn eq_ignoring_origin_and_deps(&self, other: &CrateData, ignore_dev_deps: bool) -> bool {
// This method has some obscure bits. These are mostly there to be compliant with
// some patches. References to the patches are given.
if self.root_file_id != other.root_file_id {
return false;
}
if self.display_name != other.display_name {
return false;
}
if self.is_proc_macro != other.is_proc_macro {
return false;
}
if self.edition != other.edition {
return false;
}
if self.version != other.version {
return false;
}
let mut opts = self.cfg_options.difference(&other.cfg_options);
if let Some(it) = opts.next() {
// Don't care if rust_analyzer CfgAtom is the only cfg in the difference set of self's and other's cfgs.
// https://github.com/rust-lang/rust-analyzer/blob/0840038f02daec6ba3238f05d8caa037d28701a0/crates/project-model/src/workspace.rs#L894
if it.to_string() != "rust_analyzer" {
return false;
}
if opts.next().is_some() {
return false;
}
}
if self.env != other.env {
return false;
}
let slf_deps = self.dependencies.iter();
let other_deps = other.dependencies.iter();
if ignore_dev_deps {
return slf_deps
.clone()
.filter(|it| it.kind != DependencyKind::Dev)
.eq(other_deps.clone().filter(|it| it.kind != DependencyKind::Dev));
}
slf_deps.eq(other_deps)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Edition { pub enum Edition {
Edition2015, Edition2015,
@ -389,32 +333,22 @@ pub enum DependencyKind {
pub struct Dependency { pub struct Dependency {
pub crate_id: CrateId, pub crate_id: CrateId,
pub name: CrateName, pub name: CrateName,
kind: DependencyKind,
prelude: bool, prelude: bool,
} }
impl Dependency { impl Dependency {
pub fn new(name: CrateName, crate_id: CrateId, kind: DependencyKind) -> Self { pub fn new(name: CrateName, crate_id: CrateId) -> Self {
Self { name, crate_id, prelude: true, kind } Self { name, crate_id, prelude: true }
} }
pub fn with_prelude( pub fn with_prelude(name: CrateName, crate_id: CrateId, prelude: bool) -> Self {
name: CrateName, Self { name, crate_id, prelude }
crate_id: CrateId,
prelude: bool,
kind: DependencyKind,
) -> Self {
Self { name, crate_id, prelude, kind }
} }
/// Whether this dependency is to be added to the depending crate's extern prelude. /// Whether this dependency is to be added to the depending crate's extern prelude.
pub fn is_prelude(&self) -> bool { pub fn is_prelude(&self) -> bool {
self.prelude self.prelude
} }
pub fn kind(&self) -> DependencyKind {
self.kind
}
} }
impl CrateGraph { impl CrateGraph {
@ -684,11 +618,9 @@ impl CrateGraph {
match (cfg_if, std) { match (cfg_if, std) {
(Some(cfg_if), Some(std)) => { (Some(cfg_if), Some(std)) => {
self.arena[cfg_if].dependencies.clear(); self.arena[cfg_if].dependencies.clear();
self.arena[std].dependencies.push(Dependency::new( self.arena[std]
CrateName::new("cfg_if").unwrap(), .dependencies
cfg_if, .push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
DependencyKind::Normal,
));
true true
} }
_ => false, _ => false,
@ -836,7 +768,7 @@ impl fmt::Display for CyclicDependenciesError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{CrateOrigin, DependencyKind}; use crate::CrateOrigin;
use super::{CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId}; use super::{CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId};
@ -877,22 +809,13 @@ mod tests {
CrateOrigin::Local { repo: None, name: None }, CrateOrigin::Local { repo: None, name: None },
); );
assert!(graph assert!(graph
.add_dep( .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok()); .is_ok());
assert!(graph assert!(graph
.add_dep( .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,))
crate2,
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
)
.is_ok()); .is_ok());
assert!(graph assert!(graph
.add_dep( .add_dep(crate3, Dependency::new(CrateName::new("crate1").unwrap(), crate1,))
crate3,
Dependency::new(CrateName::new("crate1").unwrap(), crate1, DependencyKind::Normal)
)
.is_err()); .is_err());
} }
@ -922,16 +845,10 @@ mod tests {
CrateOrigin::Local { repo: None, name: None }, CrateOrigin::Local { repo: None, name: None },
); );
assert!(graph assert!(graph
.add_dep( .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok()); .is_ok());
assert!(graph assert!(graph
.add_dep( .add_dep(crate2, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
crate2,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_err()); .is_err());
} }
@ -972,16 +889,10 @@ mod tests {
CrateOrigin::Local { repo: None, name: None }, CrateOrigin::Local { repo: None, name: None },
); );
assert!(graph assert!(graph
.add_dep( .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok()); .is_ok());
assert!(graph assert!(graph
.add_dep( .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,))
crate2,
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
)
.is_ok()); .is_ok());
} }
@ -1013,20 +924,12 @@ mod tests {
assert!(graph assert!(graph
.add_dep( .add_dep(
crate1, crate1,
Dependency::new( Dependency::new(CrateName::normalize_dashes("crate-name-with-dashes"), crate2,)
CrateName::normalize_dashes("crate-name-with-dashes"),
crate2,
DependencyKind::Normal
)
) )
.is_ok()); .is_ok());
assert_eq!( assert_eq!(
graph[crate1].dependencies, graph[crate1].dependencies,
vec![Dependency::new( vec![Dependency::new(CrateName::new("crate_name_with_dashes").unwrap(), crate2,)]
CrateName::new("crate_name_with_dashes").unwrap(),
crate2,
DependencyKind::Normal
)]
); );
} }
} }

View File

@ -71,7 +71,6 @@ impl Definition {
&self, &self,
sema: &Semantics<'_, RootDatabase>, sema: &Semantics<'_, RootDatabase>,
new_name: &str, new_name: &str,
rename_external: bool,
) -> Result<SourceChange> { ) -> Result<SourceChange> {
// self.krate() returns None if // self.krate() returns None if
// self is a built-in attr, built-in type or tool module. // self is a built-in attr, built-in type or tool module.
@ -80,8 +79,8 @@ impl Definition {
if let Some(krate) = self.krate(sema.db) { if let Some(krate) = self.krate(sema.db) {
// Can we not rename non-local items? // Can we not rename non-local items?
// Then bail if non-local // Then bail if non-local
if !rename_external && !krate.origin(sema.db).is_local() { if !krate.origin(sema.db).is_local() {
bail!("Cannot rename a non-local definition as the config for it is disabled") bail!("Cannot rename a non-local definition")
} }
} }

View File

@ -43,7 +43,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Ass
let label = format!("Rename to {}", d.suggested_text); let label = format!("Rename to {}", d.suggested_text);
let mut res = unresolved_fix("change_case", &label, frange.range); let mut res = unresolved_fix("change_case", &label, frange.range);
if ctx.resolve.should_resolve(&res.id) { if ctx.resolve.should_resolve(&res.id) {
let source_change = def.rename(&ctx.sema, &d.suggested_text, true); let source_change = def.rename(&ctx.sema, &d.suggested_text);
res.source_change = Some(source_change.ok().unwrap_or_default()); res.source_change = Some(source_change.ok().unwrap_or_default());
} }

View File

@ -675,9 +675,8 @@ impl Analysis {
&self, &self,
position: FilePosition, position: FilePosition,
new_name: &str, new_name: &str,
rename_external: bool,
) -> Cancellable<Result<SourceChange, RenameError>> { ) -> Cancellable<Result<SourceChange, RenameError>> {
self.with_db(|db| rename::rename(db, position, new_name, rename_external)) self.with_db(|db| rename::rename(db, position, new_name))
} }
pub fn prepare_rename( pub fn prepare_rename(

View File

@ -84,7 +84,6 @@ pub(crate) fn rename(
db: &RootDatabase, db: &RootDatabase,
position: FilePosition, position: FilePosition,
new_name: &str, new_name: &str,
rename_external: bool,
) -> RenameResult<SourceChange> { ) -> RenameResult<SourceChange> {
let sema = Semantics::new(db); let sema = Semantics::new(db);
let source_file = sema.parse(position.file_id); let source_file = sema.parse(position.file_id);
@ -104,7 +103,7 @@ pub(crate) fn rename(
return rename_to_self(&sema, local); return rename_to_self(&sema, local);
} }
} }
def.rename(&sema, new_name, rename_external) def.rename(&sema, new_name)
}) })
.collect(); .collect();
@ -123,9 +122,9 @@ pub(crate) fn will_rename_file(
let module = sema.to_module_def(file_id)?; let module = sema.to_module_def(file_id)?;
let def = Definition::Module(module); let def = Definition::Module(module);
let mut change = if is_raw_identifier(new_name_stem) { let mut change = if is_raw_identifier(new_name_stem) {
def.rename(&sema, &SmolStr::from_iter(["r#", new_name_stem]), true).ok()? def.rename(&sema, &SmolStr::from_iter(["r#", new_name_stem])).ok()?
} else { } else {
def.rename(&sema, new_name_stem, true).ok()? def.rename(&sema, new_name_stem).ok()?
}; };
change.file_system_edits.clear(); change.file_system_edits.clear();
Some(change) Some(change)
@ -377,16 +376,11 @@ mod tests {
use super::{RangeInfo, RenameError}; use super::{RangeInfo, RenameError};
fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) { fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
check_with_rename_config(new_name, ra_fixture_before, ra_fixture_after, true); check_with_rename_config(new_name, ra_fixture_before, ra_fixture_after);
} }
#[track_caller] #[track_caller]
fn check_with_rename_config( fn check_with_rename_config(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
new_name: &str,
ra_fixture_before: &str,
ra_fixture_after: &str,
rename_external: bool,
) {
let ra_fixture_after = &trim_indent(ra_fixture_after); let ra_fixture_after = &trim_indent(ra_fixture_after);
let (analysis, position) = fixture::position(ra_fixture_before); let (analysis, position) = fixture::position(ra_fixture_before);
if !ra_fixture_after.starts_with("error: ") { if !ra_fixture_after.starts_with("error: ") {
@ -395,7 +389,7 @@ mod tests {
} }
} }
let rename_result = analysis let rename_result = analysis
.rename(position, new_name, rename_external) .rename(position, new_name)
.unwrap_or_else(|err| panic!("Rename to '{new_name}' was cancelled: {err}")); .unwrap_or_else(|err| panic!("Rename to '{new_name}' was cancelled: {err}"));
match rename_result { match rename_result {
Ok(source_change) => { Ok(source_change) => {
@ -426,10 +420,8 @@ mod tests {
fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) { fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture); let (analysis, position) = fixture::position(ra_fixture);
let source_change = analysis let source_change =
.rename(position, new_name, true) analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
.unwrap()
.expect("Expect returned a RenameError");
expect.assert_eq(&filter_expect(source_change)) expect.assert_eq(&filter_expect(source_change))
} }
@ -2636,19 +2628,7 @@ pub struct S;
//- /main.rs crate:main deps:lib new_source_root:local //- /main.rs crate:main deps:lib new_source_root:local
use lib::S$0; use lib::S$0;
"#, "#,
"error: Cannot rename a non-local definition as the config for it is disabled", "error: Cannot rename a non-local definition",
false,
);
check(
"Baz",
r#"
//- /lib.rs crate:lib new_source_root:library
pub struct S;
//- /main.rs crate:main deps:lib new_source_root:local
use lib::S$0;
"#,
"use lib::Baz;\n",
); );
} }
@ -2663,8 +2643,7 @@ use core::hash::Hash;
#[derive(H$0ash)] #[derive(H$0ash)]
struct A; struct A;
"#, "#,
"error: Cannot rename a non-local definition as the config for it is disabled", "error: Cannot rename a non-local definition",
false,
); );
} }

View File

@ -49,7 +49,7 @@
//! user explores them belongs to that extension (it's totally valid to change //! user explores them belongs to that extension (it's totally valid to change
//! rust-project.json over time via configuration request!) //! rust-project.json over time via configuration request!)
use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, DependencyKind, Edition}; use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
use la_arena::RawIdx; use la_arena::RawIdx;
use paths::{AbsPath, AbsPathBuf}; use paths::{AbsPath, AbsPathBuf};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -135,7 +135,6 @@ impl ProjectJson {
Dependency::new( Dependency::new(
dep_data.name, dep_data.name,
CrateId::from_raw(RawIdx::from(dep_data.krate as u32)), CrateId::from_raw(RawIdx::from(dep_data.krate as u32)),
DependencyKind::Normal,
) )
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),

View File

@ -6,8 +6,8 @@ use std::{collections::VecDeque, fmt, fs, iter, process::Command, str::FromStr,
use anyhow::{format_err, Context}; use anyhow::{format_err, Context};
use base_db::{ use base_db::{
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
Edition, Env, FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult, FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
}; };
use cfg::{CfgAtom, CfgDiff, CfgOptions}; use cfg::{CfgAtom, CfgDiff, CfgOptions};
use paths::{AbsPath, AbsPathBuf}; use paths::{AbsPath, AbsPathBuf};
@ -894,7 +894,7 @@ fn project_json_to_crate_graph(
for dep in &krate.deps { for dep in &krate.deps {
if let Some(&to) = crates.get(&dep.crate_id) { if let Some(&to) = crates.get(&dep.crate_id) {
add_dep(crate_graph, from, dep.name.clone(), to, dep.kind().to_owned()) add_dep(crate_graph, from, dep.name.clone(), to)
} }
} }
} }
@ -938,8 +938,6 @@ fn cargo_to_crate_graph(
// Add test cfg for local crates // Add test cfg for local crates
if cargo[pkg].is_local { if cargo[pkg].is_local {
cfg_options.insert_atom("test".into()); cfg_options.insert_atom("test".into());
}
if cargo[pkg].is_member {
cfg_options.insert_atom("rust_analyzer".into()); cfg_options.insert_atom("rust_analyzer".into());
} }
@ -973,16 +971,28 @@ fn cargo_to_crate_graph(
let Some(file_id) = load(root) else { continue }; let Some(file_id) = load(root) else { continue };
let build_data = build_scripts.get_output(pkg);
let pkg_data = &cargo[pkg];
let crate_id = add_target_crate_root( let crate_id = add_target_crate_root(
crate_graph, crate_graph,
proc_macros, proc_macros,
&cargo[pkg], pkg_data,
build_scripts.get_output(pkg), build_data,
cfg_options.clone(), cfg_options.clone(),
file_id, file_id,
name, name,
kind, kind,
false, if pkg_data.is_local {
CrateOrigin::Local {
repo: pkg_data.repository.clone(),
name: Some(pkg_data.name.clone()),
}
} else {
CrateOrigin::Library {
repo: pkg_data.repository.clone(),
name: pkg_data.name.clone(),
}
},
); );
if let TargetKind::Lib { .. } = kind { if let TargetKind::Lib { .. } = kind {
lib_tgt = Some((crate_id, name.clone())); lib_tgt = Some((crate_id, name.clone()));
@ -1016,7 +1026,7 @@ fn cargo_to_crate_graph(
// cargo metadata does not do any normalization, // cargo metadata does not do any normalization,
// so we do it ourselves currently // so we do it ourselves currently
let name = CrateName::normalize_dashes(&name); let name = CrateName::normalize_dashes(&name);
add_dep(crate_graph, from, name, to, DependencyKind::Normal); add_dep(crate_graph, from, name, to);
} }
} }
} }
@ -1036,17 +1046,7 @@ fn cargo_to_crate_graph(
continue; continue;
} }
add_dep( add_dep(crate_graph, from, name.clone(), to)
crate_graph,
from,
name.clone(),
to,
match dep.kind {
DepKind::Normal => DependencyKind::Normal,
DepKind::Dev => DependencyKind::Dev,
DepKind::Build => DependencyKind::Build,
},
)
} }
} }
} }
@ -1193,7 +1193,7 @@ fn handle_rustc_crates(
file_id, file_id,
&rustc_workspace[tgt].name, &rustc_workspace[tgt].name,
kind, kind,
true, CrateOrigin::Rustc { name: rustc_workspace[pkg].name.clone() },
); );
pkg_to_lib_crate.insert(pkg, crate_id); pkg_to_lib_crate.insert(pkg, crate_id);
// Add dependencies on core / std / alloc for this crate // Add dependencies on core / std / alloc for this crate
@ -1213,17 +1213,7 @@ fn handle_rustc_crates(
let name = CrateName::new(&dep.name).unwrap(); let name = CrateName::new(&dep.name).unwrap();
if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
for &from in rustc_pkg_crates.get(&pkg).into_iter().flatten() { for &from in rustc_pkg_crates.get(&pkg).into_iter().flatten() {
add_dep( add_dep(crate_graph, from, name.clone(), to);
crate_graph,
from,
name.clone(),
to,
match dep.kind {
DepKind::Normal => DependencyKind::Normal,
DepKind::Dev => DependencyKind::Dev,
DepKind::Build => DependencyKind::Build,
},
);
} }
} }
} }
@ -1245,7 +1235,7 @@ fn handle_rustc_crates(
// `rust_analyzer` thinks that it should use the one from the `rustc_source` // `rust_analyzer` thinks that it should use the one from the `rustc_source`
// instead of the one from `crates.io` // instead of the one from `crates.io`
if !crate_graph[*from].dependencies.iter().any(|d| d.name == name) { if !crate_graph[*from].dependencies.iter().any(|d| d.name == name) {
add_dep(crate_graph, *from, name.clone(), to, DependencyKind::Normal); add_dep(crate_graph, *from, name.clone(), to);
} }
} }
} }
@ -1262,7 +1252,7 @@ fn add_target_crate_root(
file_id: FileId, file_id: FileId,
cargo_name: &str, cargo_name: &str,
kind: TargetKind, kind: TargetKind,
rustc_crate: bool, origin: CrateOrigin,
) -> CrateId { ) -> CrateId {
let edition = pkg.edition; let edition = pkg.edition;
let potential_cfg_options = if pkg.features.is_empty() { let potential_cfg_options = if pkg.features.is_empty() {
@ -1310,13 +1300,7 @@ fn add_target_crate_root(
potential_cfg_options, potential_cfg_options,
env, env,
matches!(kind, TargetKind::Lib { is_proc_macro: true }), matches!(kind, TargetKind::Lib { is_proc_macro: true }),
if rustc_crate { origin,
CrateOrigin::Rustc { name: pkg.name.clone() }
} else if pkg.is_member {
CrateOrigin::Local { repo: pkg.repository.clone(), name: Some(pkg.name.clone()) }
} else {
CrateOrigin::Library { repo: pkg.repository.clone(), name: pkg.name.clone() }
},
); );
if let TargetKind::Lib { is_proc_macro: true } = kind { if let TargetKind::Lib { is_proc_macro: true } = kind {
let proc_macro = match build_data.as_ref().map(|it| it.proc_macro_dylib_path.as_ref()) { let proc_macro = match build_data.as_ref().map(|it| it.proc_macro_dylib_path.as_ref()) {
@ -1340,14 +1324,7 @@ impl SysrootPublicDeps {
/// Makes `from` depend on the public sysroot crates. /// Makes `from` depend on the public sysroot crates.
fn add_to_crate_graph(&self, crate_graph: &mut CrateGraph, from: CrateId) { fn add_to_crate_graph(&self, crate_graph: &mut CrateGraph, from: CrateId) {
for (name, krate, prelude) in &self.deps { for (name, krate, prelude) in &self.deps {
add_dep_with_prelude( add_dep_with_prelude(crate_graph, from, name.clone(), *krate, *prelude);
crate_graph,
from,
name.clone(),
*krate,
*prelude,
DependencyKind::Normal,
);
} }
} }
} }
@ -1455,7 +1432,7 @@ fn sysroot_to_crate_graph(
if let (Some(&from), Some(&to)) = if let (Some(&from), Some(&to)) =
(sysroot_crates.get(&from), sysroot_crates.get(&to)) (sysroot_crates.get(&from), sysroot_crates.get(&to))
{ {
add_dep(crate_graph, from, name, to, DependencyKind::Normal); add_dep(crate_graph, from, name, to);
} }
} }
} }
@ -1476,14 +1453,8 @@ fn sysroot_to_crate_graph(
} }
} }
fn add_dep( fn add_dep(graph: &mut CrateGraph, from: CrateId, name: CrateName, to: CrateId) {
graph: &mut CrateGraph, add_dep_inner(graph, from, Dependency::new(name, to))
from: CrateId,
name: CrateName,
to: CrateId,
kind: DependencyKind,
) {
add_dep_inner(graph, from, Dependency::new(name, to, kind))
} }
fn add_dep_with_prelude( fn add_dep_with_prelude(
@ -1492,20 +1463,12 @@ fn add_dep_with_prelude(
name: CrateName, name: CrateName,
to: CrateId, to: CrateId,
prelude: bool, prelude: bool,
kind: DependencyKind,
) { ) {
add_dep_inner(graph, from, Dependency::with_prelude(name, to, prelude, kind)) add_dep_inner(graph, from, Dependency::with_prelude(name, to, prelude))
} }
fn add_proc_macro_dep(crate_graph: &mut CrateGraph, from: CrateId, to: CrateId, prelude: bool) { fn add_proc_macro_dep(crate_graph: &mut CrateGraph, from: CrateId, to: CrateId, prelude: bool) {
add_dep_with_prelude( add_dep_with_prelude(crate_graph, from, CrateName::new("proc_macro").unwrap(), to, prelude);
crate_graph,
from,
CrateName::new("proc_macro").unwrap(),
to,
prelude,
DependencyKind::Normal,
);
} }
fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) { fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) {

View File

@ -48,7 +48,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -109,7 +108,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -117,7 +115,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -178,7 +175,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -186,7 +182,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -247,7 +242,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -255,7 +249,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],

View File

@ -48,7 +48,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -109,7 +108,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -117,7 +115,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -178,7 +175,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -186,7 +182,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -247,7 +242,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -255,7 +249,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],

View File

@ -47,7 +47,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -107,7 +106,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -115,7 +113,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -175,7 +172,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -183,7 +179,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -243,7 +238,6 @@
name: CrateName( name: CrateName(
"hello_world", "hello_world",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -251,7 +245,6 @@
name: CrateName( name: CrateName(
"libc", "libc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],

View File

@ -28,7 +28,6 @@
name: CrateName( name: CrateName(
"core", "core",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -153,7 +152,6 @@
name: CrateName( name: CrateName(
"std", "std",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -161,7 +159,6 @@
name: CrateName( name: CrateName(
"core", "core",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -228,7 +225,6 @@
name: CrateName( name: CrateName(
"alloc", "alloc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -236,7 +232,6 @@
name: CrateName( name: CrateName(
"panic_unwind", "panic_unwind",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -244,7 +239,6 @@
name: CrateName( name: CrateName(
"panic_abort", "panic_abort",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -252,7 +246,6 @@
name: CrateName( name: CrateName(
"core", "core",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -260,7 +253,6 @@
name: CrateName( name: CrateName(
"profiler_builtins", "profiler_builtins",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -268,7 +260,6 @@
name: CrateName( name: CrateName(
"unwind", "unwind",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -276,7 +267,6 @@
name: CrateName( name: CrateName(
"std_detect", "std_detect",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -284,7 +274,6 @@
name: CrateName( name: CrateName(
"test", "test",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
], ],
@ -409,7 +398,6 @@
name: CrateName( name: CrateName(
"core", "core",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -417,7 +405,6 @@
name: CrateName( name: CrateName(
"alloc", "alloc",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -425,7 +412,6 @@
name: CrateName( name: CrateName(
"std", "std",
), ),
kind: Normal,
prelude: true, prelude: true,
}, },
Dependency { Dependency {
@ -433,7 +419,6 @@
name: CrateName( name: CrateName(
"test", "test",
), ),
kind: Normal,
prelude: false, prelude: false,
}, },
Dependency { Dependency {
@ -441,7 +426,6 @@
name: CrateName( name: CrateName(
"proc_macro", "proc_macro",
), ),
kind: Normal,
prelude: false, prelude: false,
}, },
], ],

View File

@ -511,9 +511,6 @@ config_data! {
/// Exclude tests from find-all-references. /// Exclude tests from find-all-references.
references_excludeTests: bool = "false", references_excludeTests: bool = "false",
/// Allow renaming of items not belonging to the loaded workspaces.
rename_allowExternalItems: bool = "false",
/// Command to be executed instead of 'cargo' for runnables. /// Command to be executed instead of 'cargo' for runnables.
runnables_command: Option<String> = "null", runnables_command: Option<String> = "null",
@ -1774,10 +1771,6 @@ impl Config {
self.data.typing_autoClosingAngleBrackets_enable self.data.typing_autoClosingAngleBrackets_enable
} }
pub fn rename(&self) -> bool {
self.data.rename_allowExternalItems
}
// FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124 // FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124
// hence, distinguish it for now. // hence, distinguish it for now.
pub fn is_visual_studio_code(&self) -> bool { pub fn is_visual_studio_code(&self) -> bool {

View File

@ -1017,10 +1017,8 @@ pub(crate) fn handle_rename(
let _p = tracing::span!(tracing::Level::INFO, "handle_rename").entered(); let _p = tracing::span!(tracing::Level::INFO, "handle_rename").entered();
let position = from_proto::file_position(&snap, params.text_document_position)?; let position = from_proto::file_position(&snap, params.text_document_position)?;
let mut change = snap let mut change =
.analysis snap.analysis.rename(position, &params.new_name)?.map_err(to_proto::rename_error)?;
.rename(position, &params.new_name, snap.config.rename())?
.map_err(to_proto::rename_error)?;
// this is kind of a hack to prevent double edits from happening when moving files // this is kind of a hack to prevent double edits from happening when moving files
// When a module gets renamed by renaming the mod declaration this causes the file to move // When a module gets renamed by renaming the mod declaration this causes the file to move

View File

@ -19,7 +19,7 @@ use flycheck::{FlycheckConfig, FlycheckHandle};
use hir::{db::DefDatabase, Change, ProcMacros}; use hir::{db::DefDatabase, Change, ProcMacros};
use ide::CrateId; use ide::CrateId;
use ide_db::{ use ide_db::{
base_db::{salsa::Durability, CrateGraph, CrateOrigin, ProcMacroPaths, Version}, base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, Version},
FxHashMap, FxHashMap,
}; };
use itertools::Itertools; use itertools::Itertools;
@ -707,39 +707,11 @@ pub fn ws_to_crate_graph(
let mapping = crate_graph.extend( let mapping = crate_graph.extend(
other, other,
&mut crate_proc_macros, &mut crate_proc_macros,
|(cg_id, _cg_data), (_o_id, _o_data)| { |(cg_id, cg_data), (_o_id, o_data)| {
// if the newly created crate graph's layout is equal to the crate of the merged graph, then // if the newly created crate graph's layout is equal to the crate of the merged graph, then
// we can merge the crates. // we can merge the crates.
let id = cg_id.into_raw().into_u32() as usize; let id = cg_id.into_raw().into_u32() as usize;
if layouts[id] == layout && toolchains[id] == toolchain { layouts[id] == layout && toolchains[id] == toolchain && cg_data == o_data
let (res, update) = match (&_cg_data.origin, &_o_data.origin) {
(a, b)
if a == b && _cg_data.eq_ignoring_origin_and_deps(_o_data, false) =>
{
(true, false)
}
(a @ CrateOrigin::Local { .. }, CrateOrigin::Library { .. })
| (a @ CrateOrigin::Library { .. }, CrateOrigin::Local { .. })
if _cg_data.eq_ignoring_origin_and_deps(_o_data, true) =>
{
// If the origins differ, check if the two crates are equal without
// considering the dev dependencies, if they are, they most likely are in
// different loaded workspaces which may cause issues. We keep the local
// version and discard the library one as the local version may have
// dev-dependencies that we want to keep resolving. See #15656 for more
// information.
(true, !a.is_local())
}
(_, _) => (false, false),
};
if res && update {
_cg_data.origin = _o_data.origin.clone();
_cg_data.dependencies = _o_data.dependencies.clone();
}
res
} else {
false
}
}, },
); );
// Populate the side tables for the newly merged crates // Populate the side tables for the newly merged crates

View File

@ -2,9 +2,8 @@
use std::{iter, mem, ops::Not, str::FromStr, sync}; use std::{iter, mem, ops::Not, str::FromStr, sync};
use base_db::{ use base_db::{
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
Edition, Env, FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
VfsPath,
}; };
use cfg::CfgOptions; use cfg::CfgOptions;
use hir_expand::{ use hir_expand::{
@ -235,12 +234,7 @@ impl ChangeFixture {
crate_graph crate_graph
.add_dep( .add_dep(
from_id, from_id,
Dependency::with_prelude( Dependency::with_prelude(CrateName::new(&to).unwrap(), to_id, prelude),
CrateName::new(&to).unwrap(),
to_id,
prelude,
DependencyKind::Normal,
),
) )
.unwrap(); .unwrap();
} }
@ -272,14 +266,7 @@ impl ChangeFixture {
for krate in all_crates { for krate in all_crates {
crate_graph crate_graph
.add_dep( .add_dep(krate, Dependency::new(CrateName::new("core").unwrap(), core_crate))
krate,
Dependency::new(
CrateName::new("core").unwrap(),
core_crate,
DependencyKind::Normal,
),
)
.unwrap(); .unwrap();
} }
} }
@ -318,11 +305,7 @@ impl ChangeFixture {
crate_graph crate_graph
.add_dep( .add_dep(
krate, krate,
Dependency::new( Dependency::new(CrateName::new("proc_macros").unwrap(), proc_macros_crate),
CrateName::new("proc_macros").unwrap(),
proc_macros_crate,
DependencyKind::Normal,
),
) )
.unwrap(); .unwrap();
} }

View File

@ -803,11 +803,6 @@ Exclude imports from find-all-references.
-- --
Exclude tests from find-all-references. Exclude tests from find-all-references.
-- --
[[rust-analyzer.rename.allowExternalItems]]rust-analyzer.rename.allowExternalItems (default: `false`)::
+
--
Allow renaming of items not belonging to the loaded workspaces.
--
[[rust-analyzer.runnables.command]]rust-analyzer.runnables.command (default: `null`):: [[rust-analyzer.runnables.command]]rust-analyzer.runnables.command (default: `null`)::
+ +
-- --

View File

@ -1527,11 +1527,6 @@
"default": false, "default": false,
"type": "boolean" "type": "boolean"
}, },
"rust-analyzer.rename.allowExternalItems": {
"markdownDescription": "Allow renaming of items not belonging to the loaded workspaces.",
"default": false,
"type": "boolean"
},
"rust-analyzer.runnables.command": { "rust-analyzer.runnables.command": {
"markdownDescription": "Command to be executed instead of 'cargo' for runnables.", "markdownDescription": "Command to be executed instead of 'cargo' for runnables.",
"default": null, "default": null,