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 does not complete external crates #981

Closed
PeterDing opened this issue Oct 23, 2018 · 12 comments
Closed

racer does not complete external crates #981

PeterDing opened this issue Oct 23, 2018 · 12 comments

Comments

@PeterDing
Copy link

PeterDing commented Oct 23, 2018

I installed racer with nightly rust. racer completes only std libs.

Following is my test:

My environment info:

macOS 10.13.6
rustc 1.31.0-nightly (424a749a0 2018-10-21)
racer 2.1.9

RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

In my project directory, following is test result.

  • ls
Cargo.lock      Cargo.toml      src        target
  • cat Cargo.toml
[package]
name = "ttt"
version = "0.1.0"
authors = ["PeterDing <dfhayst@gmail.com>"]
edition = "2018"

[dependencies]
hyper = "0.12.12"
tokio = "0.1.11"
  • cat src/main.rs
use hyper;
fn main() {
    return ();
}
  • RUST_BACKTRACE=1 RUST_LOG=trace racer complete std (complete stdlib)
DEBUG 2018-10-23T08:39:53.083789000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
DEBUG 2018-10-23T08:39:53.083879000Z: racer::nameres: do_file_search with search string "std"
DEBUG 2018-10-23T08:39:53.083889000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
DEBUG 2018-10-23T08:39:53.083905000Z: racer::nameres: do_file_search std_path: Some("/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src")
DEBUG 2018-10-23T08:39:53.083935000Z: racer::nameres: do_file_search v: ["/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src", "."]
MATCH std,1,0,/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/lib.rs,Module,std

  • RUST_BACKTRACE=1 RUST_LOG=trace racer complete 1 9 src/main.rs (no complete external lib)
DEBUG 2018-10-23T08:36:10.555840000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
PREFIX 4,9,hyper
DEBUG 2018-10-23T08:36:10.556294000Z: racer::core: Path: contextstr is ||, searchstr is |hyper|
DEBUG 2018-10-23T08:36:10.556318000Z: racer::scopes: [find_stmt_start] now we are in scope BytePos(0) ~ BytePos(9)
DEBUG 2018-10-23T08:36:10.556329000Z: racer::core: Complete path with line: "use hyper"
DEBUG 2018-10-23T08:36:10.556354000Z: racer::core: path: P[hyper], prefix: None
DEBUG 2018-10-23T08:36:10.556366000Z: racer::nameres: resolve_path P[hyper] "src/main.rs" BytePos(9) StartsWith
DEBUG 2018-10-23T08:36:10.556379000Z: racer::nameres: search_local_scopes PathSegment { name: "hyper", generics: [], output: None } "src/main.rs" BytePos(9) StartsWith Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.556409000Z: racer::nameres: searching scope Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path start: BytePos(0) point: BytePos(9) 'hyper' "src/main.rs" StartsWith local: true, session: Session { .. }
DEBUG 2018-10-23T08:36:10.556433000Z: racer::nameres: [run_matchers_on_blob] src: fn main() {
    let url = "                ".parse::<hyper::Uri>().unwrap();
}, cxt: MatchCxt { filepath: "src/main.rs", search_str: "hyper", range: ByteRange(11..89), search_type: StartsWith, is_local: true }, namespace: Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
TRACE 2018-10-23T08:36:10.556471000Z: racer::typeinf: searching fn args for self: || false
TRACE 2018-10-23T08:36:10.556487000Z: racer::nameres: Searching 1 delayed imports for `hyper`
DEBUG 2018-10-23T08:36:10.556492000Z: racer::nameres: [run_matchers_on_blob] src: use hyper;, cxt: MatchCxt { filepath: "src/main.rs", search_str: "hyper", range: ByteRange(0..10), search_type: StartsWith, is_local: true }, namespace: Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.556733000Z: syntax::parse::lexer: scanning whitespace: Some(TokenAndSpan { tok: Whitespace, sp: Span { lo: BytePos(3), hi: BytePos(4), ctxt: #0 } })
DEBUG 2018-10-23T08:36:10.556787000Z: syntax::source_map: byte pos BytePos(0) is on the line at byte pos BytePos(0)
DEBUG 2018-10-23T08:36:10.556791000Z: syntax::source_map: char pos CharPos(0) is on the line at char pos CharPos(0)
DEBUG 2018-10-23T08:36:10.556793000Z: syntax::source_map: byte is on line: 1
DEBUG 2018-10-23T08:36:10.556807000Z: syntax::parse::attr: parse_outer_attributes: self.token=Ident(use#0, false)
DEBUG 2018-10-23T08:36:10.556940000Z: racer::matchers: [match_use] found item: UseVisitor { path_list: [PathAlias { kind: Ident("hyper"), path: P[hyper] }], contains_glob: false }, searchstr: hyper
DEBUG 2018-10-23T08:36:10.556957000Z: racer::nameres: resolve_path P[hyper] "src/main.rs" BytePos(0) ExactMatch
DEBUG 2018-10-23T08:36:10.556965000Z: racer::nameres: search_local_scopes PathSegment { name: "hyper", generics: [], output: None } "src/main.rs" BytePos(0) ExactMatch Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.556973000Z: racer::nameres: searching scope Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path start: BytePos(0) point: BytePos(0) 'hyper' "src/main.rs" ExactMatch local: true, session: Session { .. }
DEBUG 2018-10-23T08:36:10.556982000Z: racer::nameres: [run_matchers_on_blob] src: fn main() {
    let url = "                ".parse::<hyper::Uri>().unwrap();
}, cxt: MatchCxt { filepath: "src/main.rs", search_str: "hyper", range: ByteRange(11..89), search_type: ExactMatch, is_local: true }, namespace: Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
TRACE 2018-10-23T08:36:10.556995000Z: racer::typeinf: searching fn args for self: || false
TRACE 2018-10-23T08:36:10.557000000Z: racer::nameres: Searching 1 delayed imports for `hyper`
DEBUG 2018-10-23T08:36:10.557002000Z: racer::nameres: [run_matchers_on_blob] src: use hyper;, cxt: MatchCxt { filepath: "src/main.rs", search_str: "hyper", range: ByteRange(0..10), search_type: ExactMatch, is_local: true }, namespace: Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.557009000Z: racer::matchers: import use hyper; involved in a cycle; ignoring
TRACE 2018-10-23T08:36:10.557014000Z: racer::nameres: Closure definition match is looking for `hyper` in 90 characters
DEBUG 2018-10-23T08:36:10.557016000Z: racer::nameres: search_scope found matches ExactMatch []
DEBUG 2018-10-23T08:36:10.557019000Z: racer::nameres: search_crate_root |PathSegment { name: "hyper", generics: [], output: None }| "src/main.rs"
DEBUG 2018-10-23T08:36:10.557043000Z: racer::nameres: search_prelude file PathSegment { name: "hyper", generics: [], output: None } ExactMatch Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.557047000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
DEBUG 2018-10-23T08:36:10.557169000Z: racer::nameres: searching scope Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path start: BytePos(0) point: BytePos(0) 'hyper' "/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/prelude/v1.rs" ExactMatch local: true, session: Session { .. }
TRACE 2018-10-23T08:36:10.557197000Z: racer::nameres: Closure definition match is looking for `hyper` in 2576 characters
DEBUG 2018-10-23T08:36:10.557201000Z: racer::nameres: search_scope found matches ExactMatch []
TRACE 2018-10-23T08:36:10.557208000Z: racer::nameres: Closure definition match is looking for `hyper` in 90 characters
DEBUG 2018-10-23T08:36:10.557211000Z: racer::nameres: search_scope found matches StartsWith []
DEBUG 2018-10-23T08:36:10.557213000Z: racer::nameres: search_crate_root |PathSegment { name: "hyper", generics: [], output: None }| "src/main.rs"
DEBUG 2018-10-23T08:36:10.557230000Z: racer::nameres: search_prelude file PathSegment { name: "hyper", generics: [], output: None } StartsWith Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path
DEBUG 2018-10-23T08:36:10.557245000Z: racer::nameres: searching scope Crate | Mod | Space | Enum | Struct | Union | Trait | TypeDef | Type | PathParen | Const | Static | Func | Macro | PathChild | Path start: BytePos(0) point: BytePos(0) 'hyper' "/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/prelude/v1.rs" StartsWith local: true, session: Session { .. }
TRACE 2018-10-23T08:36:10.557267000Z: racer::nameres: Closure definition match is looking for `hyper` in 2576 characters
DEBUG 2018-10-23T08:36:10.557269000Z: racer::nameres: search_scope found matches StartsWith []
DEBUG 2018-10-23T08:36:10.557275000Z: racer::nameres: do_file_search with search string "hyper"
DEBUG 2018-10-23T08:36:10.557277000Z: racer::nameres: do_file_search std_path: Some("/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src")
DEBUG 2018-10-23T08:36:10.557284000Z: racer::nameres: do_file_search v: ["/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src", "src"]
END
  • RUST_BACKTRACE=1 RUST_LOG=trace racer complete hyper
DEBUG 2018-10-23T08:50:00.909610000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
DEBUG 2018-10-23T08:50:00.909706000Z: racer::nameres: do_file_search with search string "hyper"
DEBUG 2018-10-23T08:50:00.909716000Z: racer::util: Getting rust source path. Trying env var RUST_SRC_PATH.
DEBUG 2018-10-23T08:50:00.909731000Z: racer::nameres: do_file_search std_path: Some("/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src")
DEBUG 2018-10-23T08:50:00.909761000Z: racer::nameres: do_file_search v: ["/Users/peter/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src", "."]

I viewed #551 , finding nothing to solve the problem.

@kngwyu
Copy link
Collaborator

kngwyu commented Oct 23, 2018

Looks same as #916

@qzio
Copy link

qzio commented Oct 23, 2018

I'm having the same issue, same versions, but on linux (debian)
I've read #916 and tried adding extern crate hyper; but it didn't solve anything for me.

@kngwyu
Copy link
Collaborator

kngwyu commented Oct 24, 2018

@qzio
I think it's fixed by e0da9bd.
Could you please try current master?
Thanks.

@qzio
Copy link

qzio commented Oct 24, 2018

@kngwyu I've built racer from this repo, I still have the same issue, no completion or definition for hyper.

@kngwyu
Copy link
Collaborator

kngwyu commented Oct 24, 2018

@qzio
Could you please paste the output of cargo --version?

@qzio
Copy link

qzio commented Oct 24, 2018

@kngwyu

$ cargo --version
cargo 1.31.0-nightly (2d0863f65 2018-10-20)

@qzio
Copy link

qzio commented Oct 24, 2018

@kngwyu some more output:

saito:src/private/foo(master✗)$ ~/src/other/racer/target/release/racer --version && cargo --version && rustc --version && echo -e "\n## file: Cargo.toml\n$(cat Cargo.toml)\n\n## file: src/main.rs\n\n$(cat src/main.rs)"
racer 2.1.9
cargo 1.31.0-nightly (2d0863f65 2018-10-20)
rustc 1.31.0-nightly (a66dc8a14 2018-10-22)

## file: Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["user adminson <user@example.com>"]
edition = "2018"

[dependencies]

hyper = "0.12"

## file: src/main.rs

extern crate hyper;
use hyper;
fn main() {
    println!("Hello, world!");
}
saito:src/private/foo(master✗)$ ~/src/other/racer/target/release/racer complete 2 8 src/main.rs                                                                                                            
PREFIX 24,28,hype
END
saito:src/private/foo(master✗)$ ~/src/other/racer/target/release/racer complete 4 10 src/main.rs
PREFIX 47,53,printl
MATCH println!,157,13,/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs,Macro,macro_rules! println {
END
saito:src/private/foo(master✗)$ 

@PeterDing
Copy link
Author

Completion works at neovim using vim-racer and rust.vim after I add extern crate hyper; to main.ts

screen shot 2018-10-24 at 8 29 09 pm

@kngwyu
Copy link
Collaborator

kngwyu commented Oct 24, 2018

@PeterDing
Thanks!
Now I found racer fails to resolve external crates given a relative path.

@qzio
Now I think it's fixed by d538540.
Could you please try it out?
Sorry for taking your time again.

@qzio
Copy link

qzio commented Oct 24, 2018

$ ~/src/other/racer/target/release/racer complete 2 8 src/main.rs                                                                                                                                        
PREFIX 24,28,hype
MATCH hyper,1,0,/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.12/src/lib.rs,Module,/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.12/src/lib.rs                                         
END

success! Thank you for taking the time to fix this <3

@qzio
Copy link

qzio commented Oct 25, 2018

As far as I'm concerned, the commit d538540 closes this issue.

@kathampy
Copy link

kathampy commented Sep 24, 2019

Is racer complete <external crate> supposed to work in the terminal in the presence of cargo.lock, because it doesn't for me? I don't get auto-complete for trait methods implemented on a struct.

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

4 participants