rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.16k stars 1.58k forks source link

Don't show test lenses in libraries outside of the workspace #13664

Closed lnicola closed 1 year ago

lnicola commented 1 year ago
    So I just ran into this issue with types implemented in the standard library.

Here are my repro steps:

  1. Inside src/main.rs include the following:
    
    use std::sync::Mutex;

fn main() { let m = Mutex::new(0); }


2. Place your cursor (`|`) in `Mutex::ne|w` and trigger "Go to definition" (A.K.A. F12).
3. VS Code will display the code lens option to "Run Doctest" in the library's definition:
<img width="773" alt="image" src="https://user-images.githubusercontent.com/62502207/203462899-801fbe1b-a939-47e2-84aa-2113366b0855.png">
4. After clicking on that action, the output is:
<img width="1206" alt="image" src="https://user-images.githubusercontent.com/62502207/203463069-80bfe2dc-f3d0-4fc8-b0ee-4889738ae0af.png">

Now, here are some thoughts. Note that I'm a Rust beginner (I encountered this while going though the Rust book hehe) so please take it with a grain of salt <3.
1. I don't think that code lens inside code that I didn't write myself should be enabled at all, since those feel like "implementor/dev-only" tools, and I don't immediately see why the clients of the APIs would need them. So I wouldn't be upset if this feature is removed (it's not working anyway...).
2. From the picture included in point 4 above, it seems like `cargo test` is running inside my current workspace, and not where the code lens is being displayed.

_Originally posted by @MariaSolOs in https://github.com/rust-lang/rust-analyzer/issues/8248#issuecomment-1324506301_
MariaSolOs commented 1 year ago

Could I take this @lnicola? :)

MariaSolOs commented 1 year ago

Also, do we want to just disable test-related lenses or all code lenses for external libraries?

Veykril commented 1 year ago

Only tests I would say, other code lenses do make sense in external libraries still

lnicola commented 1 year ago

Hmm. In an ideal world, we could have rlibs for the libraries, so things like "find all references" wouldn't work. I wouldn't mind if we didn't look at the function bodies in external crates.

Veykril commented 1 year ago

Right, find all references isn't too useful there (I keep forgetting that's a thing as i have that turned off), but I think the implementations lenses would still make sense?

MariaSolOs commented 1 year ago

Alright, I have a fix in #13686 :)

lnicola commented 1 year ago

Fixed in #13686