racer-rust / emacs-racer

Racer support for Emacs
399 stars 48 forks source link

Use region contents in racer-describe if active #88

Closed dcluna closed 7 years ago

dcluna commented 7 years ago

(thing-at-point 'symbol) (here) doesn't always retrieve what we want - for instance, when describing a namespaced fn - so we may want to check it against the active region to work around this.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.08%) to 65.205% when pulling 9634a1a319b439ee769714ef43e9f6531e82e3f2 on dcluna:racer-describe-use-region into 6e0d1b3ebd54497c0cc995a92f09328ff101cd33 on racer-rust:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.08%) to 65.205% when pulling 9634a1a319b439ee769714ef43e9f6531e82e3f2 on dcluna:racer-describe-use-region into 6e0d1b3ebd54497c0cc995a92f09328ff101cd33 on racer-rust:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.08%) to 65.205% when pulling 9634a1a319b439ee769714ef43e9f6531e82e3f2 on dcluna:racer-describe-use-region into 6e0d1b3ebd54497c0cc995a92f09328ff101cd33 on racer-rust:master.

Wilfred commented 7 years ago

Hi @dcluna , thanks for the PR! :)

Could you give a code example where this is useful? I don't see how this affects racer-describe, since as you say it's using thing-at-point. We may also want to file a bug on upstream racer to make it smarter.

dcluna commented 7 years ago

Hi @Wilfred, thanks for reviewing!

I was looking at a piece of code like the following:

::std::env::var("MY_ENV_VAR")

and just putting point at var and running racer-describe didn't open the documentation for var as I expected. racer-debug returned the following:

$ $HOME/.cargo/bin/racer complete-with-snippet 753 31 my-file.rs /tmp/racer3881nsF

This command terminated with exit code 0.

stdout:

PREFIX 24647,24650,var
END

No output on stderr.

The temporary file will have been deleted. You should be
able to reproduce the same output from racer with the
following command:

$ CARGO_HOME=$HOME/.cargo RUST_SRC_PATH=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src $HOME/.cargo/bin/racer complete-with-snippet 753 31 my-file.rs

The upstream racer command has a complete option that allows you to pass a fully-namespaced string for autocompletion, and that's what I'm using in this PR. It solved my problem, but as you say, maybe I should focus on fixing the upstream complete-with-snippet. I must admit I am not familiar with it - particularly, the numbers after PREFIX seem like internal pointers to crates to me, but I could use some guidance with it.

Anyway, have I made myself clear? Do you think this is mergeable (after adding some tests, ofc), or do you think this is a racer bug in the complete-with-snippet?

Wilfred commented 7 years ago

Thanks for the example. Based on it, I've written the following program, but I can't reproduce the issue:

fn main() {
    let v = ::std::env::var("MY_ENV_VAR");
}

I'm able to jump to definition and run racer-describe on var. What version of racer are you using?

dcluna commented 7 years ago

racer 2.0.9. There are some rustc errors in the crate I'm writing this code, so maybe that has something to do with it? What surprises me is that racer-call with complete does work. If this is expected behavior, I can change this PR to use the complete option if complete-with-snippet fails for whatever reason. WDYT?

Wilfred commented 7 years ago

Interesting that complete works. Could you share the file you're working on?

dcluna commented 7 years ago

https://github.com/rust-lang-nursery/rustup.rs/blob/9e1f621b80f9c0f80c295028be165c327b756a43/tests/cli-rustup.rs#L752

Wilfred commented 7 years ago

I can't see any references to ::std::env::var in that file, and ::std::env::current_dir seems to work as expected. How can I reproduce the issue?

dcluna commented 7 years ago

I added the following line (after line 752):

assert!(::std::env::var("RUST_SRC_PATH") == Ok(_));

It seems like this is mostly related to my own environment than any bug in racer or this plugin, so I'll close this and re-open if I manage to reproduce it reliably. Thanks for your patience on this!