mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
CrateOrigin::Local means local to the project workspace, not cargo workspace
This commit is contained in:
parent
0ccb3b8731
commit
ead369117a
17 changed files with 73 additions and 332 deletions
|
@ -293,62 +293,6 @@ pub struct CrateData {
|
|||
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)]
|
||||
pub enum Edition {
|
||||
Edition2015,
|
||||
|
@ -389,32 +333,22 @@ pub enum DependencyKind {
|
|||
pub struct Dependency {
|
||||
pub crate_id: CrateId,
|
||||
pub name: CrateName,
|
||||
kind: DependencyKind,
|
||||
prelude: bool,
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
pub fn new(name: CrateName, crate_id: CrateId, kind: DependencyKind) -> Self {
|
||||
Self { name, crate_id, prelude: true, kind }
|
||||
pub fn new(name: CrateName, crate_id: CrateId) -> Self {
|
||||
Self { name, crate_id, prelude: true }
|
||||
}
|
||||
|
||||
pub fn with_prelude(
|
||||
name: CrateName,
|
||||
crate_id: CrateId,
|
||||
prelude: bool,
|
||||
kind: DependencyKind,
|
||||
) -> Self {
|
||||
Self { name, crate_id, prelude, kind }
|
||||
pub fn with_prelude(name: CrateName, crate_id: CrateId, prelude: bool) -> Self {
|
||||
Self { name, crate_id, prelude }
|
||||
}
|
||||
|
||||
/// Whether this dependency is to be added to the depending crate's extern prelude.
|
||||
pub fn is_prelude(&self) -> bool {
|
||||
self.prelude
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> DependencyKind {
|
||||
self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl CrateGraph {
|
||||
|
@ -684,11 +618,9 @@ impl CrateGraph {
|
|||
match (cfg_if, std) {
|
||||
(Some(cfg_if), Some(std)) => {
|
||||
self.arena[cfg_if].dependencies.clear();
|
||||
self.arena[std].dependencies.push(Dependency::new(
|
||||
CrateName::new("cfg_if").unwrap(),
|
||||
cfg_if,
|
||||
DependencyKind::Normal,
|
||||
));
|
||||
self.arena[std]
|
||||
.dependencies
|
||||
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
|
@ -836,7 +768,7 @@ impl fmt::Display for CyclicDependenciesError {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{CrateOrigin, DependencyKind};
|
||||
use crate::CrateOrigin;
|
||||
|
||||
use super::{CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId};
|
||||
|
||||
|
@ -877,22 +809,13 @@ mod tests {
|
|||
CrateOrigin::Local { repo: None, name: None },
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate1,
|
||||
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
|
||||
.is_ok());
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate2,
|
||||
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,))
|
||||
.is_ok());
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate3,
|
||||
Dependency::new(CrateName::new("crate1").unwrap(), crate1, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate3, Dependency::new(CrateName::new("crate1").unwrap(), crate1,))
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -922,16 +845,10 @@ mod tests {
|
|||
CrateOrigin::Local { repo: None, name: None },
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate1,
|
||||
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
|
||||
.is_ok());
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate2,
|
||||
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate2, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
|
||||
.is_err());
|
||||
}
|
||||
|
||||
|
@ -972,16 +889,10 @@ mod tests {
|
|||
CrateOrigin::Local { repo: None, name: None },
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate1,
|
||||
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,))
|
||||
.is_ok());
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
crate2,
|
||||
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
|
||||
)
|
||||
.add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,))
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
|
@ -1013,20 +924,12 @@ mod tests {
|
|||
assert!(graph
|
||||
.add_dep(
|
||||
crate1,
|
||||
Dependency::new(
|
||||
CrateName::normalize_dashes("crate-name-with-dashes"),
|
||||
crate2,
|
||||
DependencyKind::Normal
|
||||
)
|
||||
Dependency::new(CrateName::normalize_dashes("crate-name-with-dashes"), crate2,)
|
||||
)
|
||||
.is_ok());
|
||||
assert_eq!(
|
||||
graph[crate1].dependencies,
|
||||
vec![Dependency::new(
|
||||
CrateName::new("crate_name_with_dashes").unwrap(),
|
||||
crate2,
|
||||
DependencyKind::Normal
|
||||
)]
|
||||
vec![Dependency::new(CrateName::new("crate_name_with_dashes").unwrap(), crate2,)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ impl Definition {
|
|||
&self,
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
new_name: &str,
|
||||
rename_external: bool,
|
||||
) -> Result<SourceChange> {
|
||||
// self.krate() returns None if
|
||||
// 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) {
|
||||
// Can we not rename non-local items?
|
||||
// Then bail if non-local
|
||||
if !rename_external && !krate.origin(sema.db).is_local() {
|
||||
bail!("Cannot rename a non-local definition as the config for it is disabled")
|
||||
if !krate.origin(sema.db).is_local() {
|
||||
bail!("Cannot rename a non-local definition")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Ass
|
|||
let label = format!("Rename to {}", d.suggested_text);
|
||||
let mut res = unresolved_fix("change_case", &label, frange.range);
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -675,9 +675,8 @@ impl Analysis {
|
|||
&self,
|
||||
position: FilePosition,
|
||||
new_name: &str,
|
||||
rename_external: bool,
|
||||
) -> 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(
|
||||
|
|
|
@ -84,7 +84,6 @@ pub(crate) fn rename(
|
|||
db: &RootDatabase,
|
||||
position: FilePosition,
|
||||
new_name: &str,
|
||||
rename_external: bool,
|
||||
) -> RenameResult<SourceChange> {
|
||||
let sema = Semantics::new(db);
|
||||
let source_file = sema.parse(position.file_id);
|
||||
|
@ -104,7 +103,7 @@ pub(crate) fn rename(
|
|||
return rename_to_self(&sema, local);
|
||||
}
|
||||
}
|
||||
def.rename(&sema, new_name, rename_external)
|
||||
def.rename(&sema, new_name)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -123,9 +122,9 @@ pub(crate) fn will_rename_file(
|
|||
let module = sema.to_module_def(file_id)?;
|
||||
let def = Definition::Module(module);
|
||||
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 {
|
||||
def.rename(&sema, new_name_stem, true).ok()?
|
||||
def.rename(&sema, new_name_stem).ok()?
|
||||
};
|
||||
change.file_system_edits.clear();
|
||||
Some(change)
|
||||
|
@ -377,16 +376,11 @@ mod tests {
|
|||
use super::{RangeInfo, RenameError};
|
||||
|
||||
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]
|
||||
fn check_with_rename_config(
|
||||
new_name: &str,
|
||||
ra_fixture_before: &str,
|
||||
ra_fixture_after: &str,
|
||||
rename_external: bool,
|
||||
) {
|
||||
fn check_with_rename_config(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
let ra_fixture_after = &trim_indent(ra_fixture_after);
|
||||
let (analysis, position) = fixture::position(ra_fixture_before);
|
||||
if !ra_fixture_after.starts_with("error: ") {
|
||||
|
@ -395,7 +389,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
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}"));
|
||||
match rename_result {
|
||||
Ok(source_change) => {
|
||||
|
@ -426,10 +420,8 @@ mod tests {
|
|||
|
||||
fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
|
||||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let source_change = analysis
|
||||
.rename(position, new_name, true)
|
||||
.unwrap()
|
||||
.expect("Expect returned a RenameError");
|
||||
let source_change =
|
||||
analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
|
||||
expect.assert_eq(&filter_expect(source_change))
|
||||
}
|
||||
|
||||
|
@ -2636,19 +2628,7 @@ pub struct S;
|
|||
//- /main.rs crate:main deps:lib new_source_root:local
|
||||
use lib::S$0;
|
||||
"#,
|
||||
"error: Cannot rename a non-local definition as the config for it is disabled",
|
||||
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",
|
||||
"error: Cannot rename a non-local definition",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2663,8 +2643,7 @@ use core::hash::Hash;
|
|||
#[derive(H$0ash)]
|
||||
struct A;
|
||||
"#,
|
||||
"error: Cannot rename a non-local definition as the config for it is disabled",
|
||||
false,
|
||||
"error: Cannot rename a non-local definition",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
//! user explores them belongs to that extension (it's totally valid to change
|
||||
//! 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 paths::{AbsPath, AbsPathBuf};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -135,7 +135,6 @@ impl ProjectJson {
|
|||
Dependency::new(
|
||||
dep_data.name,
|
||||
CrateId::from_raw(RawIdx::from(dep_data.krate as u32)),
|
||||
DependencyKind::Normal,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
|
|
|
@ -6,8 +6,8 @@ use std::{collections::VecDeque, fmt, fs, iter, process::Command, str::FromStr,
|
|||
|
||||
use anyhow::{format_err, Context};
|
||||
use base_db::{
|
||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind,
|
||||
Edition, Env, FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
||||
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
||||
};
|
||||
use cfg::{CfgAtom, CfgDiff, CfgOptions};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
|
@ -894,7 +894,7 @@ fn project_json_to_crate_graph(
|
|||
|
||||
for dep in &krate.deps {
|
||||
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
|
||||
if cargo[pkg].is_local {
|
||||
cfg_options.insert_atom("test".into());
|
||||
}
|
||||
if cargo[pkg].is_member {
|
||||
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 build_data = build_scripts.get_output(pkg);
|
||||
let pkg_data = &cargo[pkg];
|
||||
let crate_id = add_target_crate_root(
|
||||
crate_graph,
|
||||
proc_macros,
|
||||
&cargo[pkg],
|
||||
build_scripts.get_output(pkg),
|
||||
pkg_data,
|
||||
build_data,
|
||||
cfg_options.clone(),
|
||||
file_id,
|
||||
name,
|
||||
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 {
|
||||
lib_tgt = Some((crate_id, name.clone()));
|
||||
|
@ -1016,7 +1026,7 @@ fn cargo_to_crate_graph(
|
|||
// cargo metadata does not do any normalization,
|
||||
// so we do it ourselves currently
|
||||
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;
|
||||
}
|
||||
|
||||
add_dep(
|
||||
crate_graph,
|
||||
from,
|
||||
name.clone(),
|
||||
to,
|
||||
match dep.kind {
|
||||
DepKind::Normal => DependencyKind::Normal,
|
||||
DepKind::Dev => DependencyKind::Dev,
|
||||
DepKind::Build => DependencyKind::Build,
|
||||
},
|
||||
)
|
||||
add_dep(crate_graph, from, name.clone(), to)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1193,7 +1193,7 @@ fn handle_rustc_crates(
|
|||
file_id,
|
||||
&rustc_workspace[tgt].name,
|
||||
kind,
|
||||
true,
|
||||
CrateOrigin::Rustc { name: rustc_workspace[pkg].name.clone() },
|
||||
);
|
||||
pkg_to_lib_crate.insert(pkg, crate_id);
|
||||
// Add dependencies on core / std / alloc for this crate
|
||||
|
@ -1213,17 +1213,7 @@ fn handle_rustc_crates(
|
|||
let name = CrateName::new(&dep.name).unwrap();
|
||||
if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
|
||||
for &from in rustc_pkg_crates.get(&pkg).into_iter().flatten() {
|
||||
add_dep(
|
||||
crate_graph,
|
||||
from,
|
||||
name.clone(),
|
||||
to,
|
||||
match dep.kind {
|
||||
DepKind::Normal => DependencyKind::Normal,
|
||||
DepKind::Dev => DependencyKind::Dev,
|
||||
DepKind::Build => DependencyKind::Build,
|
||||
},
|
||||
);
|
||||
add_dep(crate_graph, from, name.clone(), to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1245,7 +1235,7 @@ fn handle_rustc_crates(
|
|||
// `rust_analyzer` thinks that it should use the one from the `rustc_source`
|
||||
// instead of the one from `crates.io`
|
||||
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,
|
||||
cargo_name: &str,
|
||||
kind: TargetKind,
|
||||
rustc_crate: bool,
|
||||
origin: CrateOrigin,
|
||||
) -> CrateId {
|
||||
let edition = pkg.edition;
|
||||
let potential_cfg_options = if pkg.features.is_empty() {
|
||||
|
@ -1310,13 +1300,7 @@ fn add_target_crate_root(
|
|||
potential_cfg_options,
|
||||
env,
|
||||
matches!(kind, TargetKind::Lib { is_proc_macro: true }),
|
||||
if rustc_crate {
|
||||
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() }
|
||||
},
|
||||
origin,
|
||||
);
|
||||
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()) {
|
||||
|
@ -1340,14 +1324,7 @@ impl SysrootPublicDeps {
|
|||
/// Makes `from` depend on the public sysroot crates.
|
||||
fn add_to_crate_graph(&self, crate_graph: &mut CrateGraph, from: CrateId) {
|
||||
for (name, krate, prelude) in &self.deps {
|
||||
add_dep_with_prelude(
|
||||
crate_graph,
|
||||
from,
|
||||
name.clone(),
|
||||
*krate,
|
||||
*prelude,
|
||||
DependencyKind::Normal,
|
||||
);
|
||||
add_dep_with_prelude(crate_graph, from, name.clone(), *krate, *prelude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1455,7 +1432,7 @@ fn sysroot_to_crate_graph(
|
|||
if let (Some(&from), Some(&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(
|
||||
graph: &mut CrateGraph,
|
||||
from: CrateId,
|
||||
name: CrateName,
|
||||
to: CrateId,
|
||||
kind: DependencyKind,
|
||||
) {
|
||||
add_dep_inner(graph, from, Dependency::new(name, to, kind))
|
||||
fn add_dep(graph: &mut CrateGraph, from: CrateId, name: CrateName, to: CrateId) {
|
||||
add_dep_inner(graph, from, Dependency::new(name, to))
|
||||
}
|
||||
|
||||
fn add_dep_with_prelude(
|
||||
|
@ -1492,20 +1463,12 @@ fn add_dep_with_prelude(
|
|||
name: CrateName,
|
||||
to: CrateId,
|
||||
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) {
|
||||
add_dep_with_prelude(
|
||||
crate_graph,
|
||||
from,
|
||||
CrateName::new("proc_macro").unwrap(),
|
||||
to,
|
||||
prelude,
|
||||
DependencyKind::Normal,
|
||||
);
|
||||
add_dep_with_prelude(crate_graph, from, CrateName::new("proc_macro").unwrap(), to, prelude);
|
||||
}
|
||||
|
||||
fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) {
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -109,7 +108,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -117,7 +115,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -178,7 +175,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -186,7 +182,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -247,7 +242,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -255,7 +249,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -109,7 +108,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -117,7 +115,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -178,7 +175,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -186,7 +182,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -247,7 +242,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -255,7 +249,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -107,7 +106,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -115,7 +113,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -175,7 +172,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -183,7 +179,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -243,7 +238,6 @@
|
|||
name: CrateName(
|
||||
"hello_world",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -251,7 +245,6 @@
|
|||
name: CrateName(
|
||||
"libc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
name: CrateName(
|
||||
"core",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -153,7 +152,6 @@
|
|||
name: CrateName(
|
||||
"std",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -161,7 +159,6 @@
|
|||
name: CrateName(
|
||||
"core",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -228,7 +225,6 @@
|
|||
name: CrateName(
|
||||
"alloc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -236,7 +232,6 @@
|
|||
name: CrateName(
|
||||
"panic_unwind",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -244,7 +239,6 @@
|
|||
name: CrateName(
|
||||
"panic_abort",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -252,7 +246,6 @@
|
|||
name: CrateName(
|
||||
"core",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -260,7 +253,6 @@
|
|||
name: CrateName(
|
||||
"profiler_builtins",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -268,7 +260,6 @@
|
|||
name: CrateName(
|
||||
"unwind",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -276,7 +267,6 @@
|
|||
name: CrateName(
|
||||
"std_detect",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -284,7 +274,6 @@
|
|||
name: CrateName(
|
||||
"test",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
],
|
||||
|
@ -409,7 +398,6 @@
|
|||
name: CrateName(
|
||||
"core",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -417,7 +405,6 @@
|
|||
name: CrateName(
|
||||
"alloc",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -425,7 +412,6 @@
|
|||
name: CrateName(
|
||||
"std",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -433,7 +419,6 @@
|
|||
name: CrateName(
|
||||
"test",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: false,
|
||||
},
|
||||
Dependency {
|
||||
|
@ -441,7 +426,6 @@
|
|||
name: CrateName(
|
||||
"proc_macro",
|
||||
),
|
||||
kind: Normal,
|
||||
prelude: false,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -511,9 +511,6 @@ config_data! {
|
|||
/// Exclude tests from find-all-references.
|
||||
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.
|
||||
runnables_command: Option<String> = "null",
|
||||
|
@ -1774,10 +1771,6 @@ impl Config {
|
|||
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
|
||||
// hence, distinguish it for now.
|
||||
pub fn is_visual_studio_code(&self) -> bool {
|
||||
|
|
|
@ -1017,10 +1017,8 @@ pub(crate) fn handle_rename(
|
|||
let _p = tracing::span!(tracing::Level::INFO, "handle_rename").entered();
|
||||
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
||||
|
||||
let mut change = snap
|
||||
.analysis
|
||||
.rename(position, ¶ms.new_name, snap.config.rename())?
|
||||
.map_err(to_proto::rename_error)?;
|
||||
let mut change =
|
||||
snap.analysis.rename(position, ¶ms.new_name)?.map_err(to_proto::rename_error)?;
|
||||
|
||||
// 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
|
||||
|
|
|
@ -19,7 +19,7 @@ use flycheck::{FlycheckConfig, FlycheckHandle};
|
|||
use hir::{db::DefDatabase, Change, ProcMacros};
|
||||
use ide::CrateId;
|
||||
use ide_db::{
|
||||
base_db::{salsa::Durability, CrateGraph, CrateOrigin, ProcMacroPaths, Version},
|
||||
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, Version},
|
||||
FxHashMap,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
@ -707,39 +707,11 @@ pub fn ws_to_crate_graph(
|
|||
let mapping = crate_graph.extend(
|
||||
other,
|
||||
&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
|
||||
// we can merge the crates.
|
||||
let id = cg_id.into_raw().into_u32() as usize;
|
||||
if layouts[id] == layout && toolchains[id] == toolchain {
|
||||
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
|
||||
}
|
||||
layouts[id] == layout && toolchains[id] == toolchain && cg_data == o_data
|
||||
},
|
||||
);
|
||||
// Populate the side tables for the newly merged crates
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
use std::{iter, mem, ops::Not, str::FromStr, sync};
|
||||
|
||||
use base_db::{
|
||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind,
|
||||
Edition, Env, FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version,
|
||||
VfsPath,
|
||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
||||
FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
|
||||
};
|
||||
use cfg::CfgOptions;
|
||||
use hir_expand::{
|
||||
|
@ -235,12 +234,7 @@ impl ChangeFixture {
|
|||
crate_graph
|
||||
.add_dep(
|
||||
from_id,
|
||||
Dependency::with_prelude(
|
||||
CrateName::new(&to).unwrap(),
|
||||
to_id,
|
||||
prelude,
|
||||
DependencyKind::Normal,
|
||||
),
|
||||
Dependency::with_prelude(CrateName::new(&to).unwrap(), to_id, prelude),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -272,14 +266,7 @@ impl ChangeFixture {
|
|||
|
||||
for krate in all_crates {
|
||||
crate_graph
|
||||
.add_dep(
|
||||
krate,
|
||||
Dependency::new(
|
||||
CrateName::new("core").unwrap(),
|
||||
core_crate,
|
||||
DependencyKind::Normal,
|
||||
),
|
||||
)
|
||||
.add_dep(krate, Dependency::new(CrateName::new("core").unwrap(), core_crate))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -318,11 +305,7 @@ impl ChangeFixture {
|
|||
crate_graph
|
||||
.add_dep(
|
||||
krate,
|
||||
Dependency::new(
|
||||
CrateName::new("proc_macros").unwrap(),
|
||||
proc_macros_crate,
|
||||
DependencyKind::Normal,
|
||||
),
|
||||
Dependency::new(CrateName::new("proc_macros").unwrap(), proc_macros_crate),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -803,11 +803,6 @@ Exclude imports 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`)::
|
||||
+
|
||||
--
|
||||
|
|
|
@ -1527,11 +1527,6 @@
|
|||
"default": false,
|
||||
"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": {
|
||||
"markdownDescription": "Command to be executed instead of 'cargo' for runnables.",
|
||||
"default": null,
|
||||
|
|
Loading…
Reference in a new issue