racer
racer copied to clipboard
docs: how to get completion for non-mozilla/rust crates?
Or am I missing something [ex|im]plicit in the README instructions?
I would like completion for types/modules outside of the rust distribution src tree. Is there a way to easily achieve this and what does it entail? eg gfx-rs or any of its dependencies or some other crate I depend on through cargo (i don't expect instant code completion for binary artifact dependencies, i assume access to src is neccesary)
If so, it would be useful to add to the README docs (eg if it involves downloading the src of the project you want completion for and adding it to the rust-src-distro-path env var.. what's the delimiter? etc.. these things are non-intuitive to me).
Hi @olsonjeffery. Racer should be able to perform completion/find-definition for other cargo crates by inspecting your Cargo.toml and Cargo.lock, so it sounds like there might be a more specific problem here. Do you have a test-case I can try? Thanks!
@phildawes
UPDATE: this is a release build on commit abef71c37c312a8
of racer (the HEAD of master as of the time of this post).
here's some screens of different things im seeing.. this is all in a main.rs for gfx-rs/gfx_examples
So it looks like some completions into crates are working, others are causing errors and others still just aren't returning anything.. in all of the examples, you can see the usings for the files (that are valid), so there should be completions, unless I'm mistaken. In any case, the problem(s) appear to be stuff outside of what I originally thought was the behavior I was observing...
Hi @olsenjeffery. I took a look at gfx-examples/src/terrain/main.rs. If the genmesh crate is resolving then it sounds like racer is setup ok.
I suspect the other problems might be either specific bugs in racer or more likely areas where racer doesn't have the skills yet to resolve the completion (macros, non-trivial generics). I am working on interfacing racer with rustc to get better at type resolution, but this is a way off at the moment.
N.B. on my linux laptop in emacs I'm having problems resolving even genmesh. I think this is a CRLF problem for me. What's your os?
Sorry!
No worries. Apologies for leaving out system info.. I'm on OSX Mavericks. Racer was built on rust stable. Thanks for the investigation. I will be patient. On Sun, Jun 7, 2015 at 1:52 AM Phil Dawes [email protected] wrote:
Hi @olsenjeffery. I took a look at gfx-examples/src/terrain/main.rs. If the genmesh crate is resolving then it sounds like racer is setup ok.
I suspect the other problems might be either specific bugs in racer or more likely areas where racer doesn't have the skills yet to resolve the completion (macros, non-trivial generics). I am working on interfacing racer with rustc to get better at type resolution, but this is a way off at the moment.
N.B. on my linux laptop in emacs I'm having problems resolving even genmesh. I think this is a CRLF problem for me. What's your os?
Sorry!
— Reply to this email directly or view it on GitHub https://github.com/phildawes/racer/issues/264#issuecomment-109705743.
@olsonjeffery To get debug info, run racer manually like this RUST_LOG=debug racer complete ROW COL FILENAME
where you put in the exact line number and column number manually. ~~The column number is what vim edit specifies when you have the cursor over the last character in normal mode.~~ (lol, it's not vim..)
+1
Still not working, tried with termbox crate, completion was available just for standard rust source distribution. Do I need some special setup to get this working?
Which editor config and which version of it are you using?
I'm trying to use racer from command-line at the moment, here is completion for standard module:
racer complete 18 17 src/app.rs PREFIX 17,17, MATCH BufReader,47,11,/home/n/projects/rust/src/libstd/io/buffered.rs,Struct,pub struct BufReader<R> ... tons of other completions ...
And there is completion for external crate module:
racer complete 19 17 src/app.rs PREFIX 17,17, END
I'm trying to complete following code:
std::io::
RustBox::
Also I'm using Atom editor (latest version, built from source) and atom-racer plugin, still working only for std modules.
it's the same for me. seems like racer uses wrong/system crate (name-sys instead of name) I have 'extern crate curl;' and try to get completion for 'curl::h'
RUST_LOG=debug racer complete 5 11 .../lib.rs
PREFIX 10,11,h
DEBUG:racer::core: CompletePath: contextstr is |curl|, searchstr is |h|
DEBUG:racer::nameres: resolve_path P[curl::h] Some(".../lib.rs") 80 StartsWith
DEBUG:racer::nameres: resolve_path P[curl] Some(".../lib.rs") 80 ExactMatch
DEBUG:racer::nameres: resolve_name curl Some("../lib.rs") 80 ExactMatch TypeNamespace
DEBUG:racer::nameres: search_local_scopes PathSegment { name: "curl", types: [] } Some(".../lib.rs") 80 ExactMatch TypeNamespace
DEBUG:racer::nameres: searching scope TypeNamespace start: 0 point: 80 'curl' Some(".../lib.rs") ExactMatch local: true, session: Session(".../lib.rs", ".../lib.rs")
DEBUG:racer::matchers: found an extern crate: |extern crate curl;|
DEBUG:syntex_syntax::parse::lexer: scanning whitespace: Some(TokenAndSpan { tok: Whitespace, sp: Span { lo: BytePos(6), hi: BytePos(7), expn_id: ExpnId(4294967295) } })
DEBUG:syntex_syntax::parse::attr: parse_outer_attributes: self.token=Ident(extern#0, Plain)
DEBUG:syntex_syntax::parse::lexer: scanning whitespace: Some(TokenAndSpan { tok: Whitespace, sp: Span { lo: BytePos(12), hi: BytePos(13), expn_id: ExpnId(4294967295) } })
DEBUG:racer::matchers: extern crate curl
DEBUG:racer::nameres: get_crate_file curl
DEBUG:racer::cargo: get_crate_file tomlfile is ".../Cargo.toml"
DEBUG:racer::cargo: get_cargo_rootdir. ".../Cargo.toml"
DEBUG:racer::cargo: get_cargo_rootdir: looking for overrides file. "~/.multirust/overrides"
DEBUG:racer::cargo: get_versioned_cratefile: cargo rootdir is "~/.cargo"
DEBUG:racer::cargo: crate path "~/.cargo/registry/src/github.com-0a35038f75765ae4/curl-sys-0.1.26/src"
DEBUG:racer::cargo: crate path with lib.rs "~/.cargo/registry/src/github.com-0a35038f75765ae4/curl-sys-0.1.26/src/lib.rs"
DEBUG:racer::nameres: nameres::get_crate_file - found the crate file! "~/.cargo/registry/src/github.com-0a35038f75765ae4/curl-sys-0.1.26/lib.rs"
DEBUG:racer::nameres: searching a module 'curl' for h (whole path: P[curl::h])
DEBUG:racer::nameres: searching scope BothNamespaces start: 0 point: 0 'h' Some("~/.cargo/registry/src/github.com-0a35038f75765ae4/curl-sys-0.1.26/lib.rs") StartsWith local: false, session: Session(".../lib.rs", ".../lib.rs")
DEBUG:racer::nameres: search_scope found matches StartsWith []
DEBUG:racer::nameres: resolve_path returning []
END
I use sdl2
crate and see some inconsistency in autocompletion behavior. Editor is emacs, package versions are:
company-racer 20150628.1933
racer 20160120.1229
Racer version is 4a92cb05495bc727d839c6036ae934dd499de5ac
from git, built with cargo 0.7.0-nightly (1af03be 2015-12-08)
and rustc 1.6.0 (c30b771ad 2016-01-19)
.
My project has a dependency - sdl2
package in Cargo.toml
file:
[dependencies]
sdl2 = "0.12"
Now, when I add extern crate sdl2;
to my source code and enter use s
then try to autocomplete, I see only standard Rust packages. However, when I try to autocomplete sdl2::
, I see the appropriate symbols there. Is this a related issue?
check your environment value $CARGO_HOME
, set to $HOME/.cargo
, that works for me.