Skip to content
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

Racer searches for crate sources recursively in all package dependencies #831

Closed
RReverser opened this issue Feb 24, 2018 · 8 comments
Closed

Comments

@RReverser
Copy link

It seems that Racer tries to find crate source somewhat too hard, traversing not only dependencies from current Cargo.toml or Cargo.lock (which are the only accessible to current Rust code), but also dependencies of these dependencies and so on recursively. Additionally, it looks in global overrides, again, returning any match, no matter whether it's actually defined and so accessible in current crate's Cargo.toml or not.

@kngwyu
Copy link
Collaborator

kngwyu commented Feb 25, 2018

Thanks for reporting, but, I think racer doesn't.
Could you tell me why you think so?

@RReverser
Copy link
Author

Well I found this while trying to implement #830 and trying to figure out why I'm getting overly extensive list of crates.

Turns out, when looking for crate by name, cargo::get_crate_file will look at global overrides (

racer/src/racer/cargo.rs

Lines 696 to 698 in cff609a

if let Some(src) = get_crate_file_from_overrides(kratename, from_path) {
return Some(src);
}
) and then Cargo.lock without checking Cargo.toml whether this crate is a direct dependency at all (as both global overrides and Cargo.lock contain many more packages then current Rust code can actually access by name).

Then, even if it didn't find in either of those and when it does look at Cargo.toml, it recursively opens another Cargo.toml of each dependency and starts looking there -

racer/src/racer/cargo.rs

Lines 380 to 388 in cff609a

if let Some(tomlfile) = find_cargo_tomlfile(package_source.clone()) {
let package_name = get_package_name(tomlfile.as_path());
debug!("find_src_via_tomlfile package_name: {}", package_name);
if package_name == kratename {
return find_src_via_tomlfile(kratename, &tomlfile)
}
}

@kngwyu
Copy link
Collaborator

kngwyu commented Feb 25, 2018

Thanks, I understand.
I'm sorry I had misunderstanding that you're pointing out completion problem.

Racer searches Cargo.lock file to complete items in re-exported crates(see #812).
It's surely waste of time, but I'm not sure this should be fixed, because making data structure such as crate_skip_list also takes time.

For second problem(recursive search for Cargo.toml), hmm, this code seems to be for the cases where local path chains, like
Cargo.toml in work directory contains

[dependencies.crate-a]
path = "../../crate-a"

and Cargo.toml in ../../crate-a contains

[dependencies.crate-b]
path = "../../crate-b"

If crate-b isn't visible it's surely waste of time, too. However, I'm not sure this should be fixed, too.

Edited(2018/04/25):
My comment was incorrect.
Recursive search is completely useless here because actually we find outer crates step-by-step

@kristate
Copy link

This seems related to #757 -- lots of recursion problems in racer.

@kngwyu
Copy link
Collaborator

kngwyu commented Mar 14, 2018

Hmm...
OK.
I'll try to rewrite racer's file cache to check reexporting and circuit, though not now(I have 4 PRs not yet merged:fearful:).

@kristate
Copy link

@kngwyu

I'll try to rewrite racer's file cache to check reexporting and circuit, though not now(I have 4 PRs not yet merged😨).

Thank-you!

@kngwyu
Copy link
Collaborator

kngwyu commented Mar 29, 2018

Fixed in my branch.

@kngwyu
Copy link
Collaborator

kngwyu commented Jun 6, 2018

Closed via #855

@kngwyu kngwyu closed this as completed Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants