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

Support Goto Definition into include! #3767

Closed
Tracked by #86
cynecx opened this issue Mar 29, 2020 · 12 comments · Fixed by #14561
Closed
Tracked by #86

Support Goto Definition into include! #3767

cynecx opened this issue Mar 29, 2020 · 12 comments · Fixed by #14561
Assignees
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now

Comments

@cynecx
Copy link
Contributor

cynecx commented Mar 29, 2020

settings.json (vscode):

{
    "rust-analyzer.cargoFeatures.loadOutDirsFromCheck": true,
}

rust-analyzer: 1c2d4135db867efe335a0654d86429bea7bb9caf (current master)

How to reproduce:

  1. Add lapin = { version = "0.34" } to your deps.
  2. Use this code snippet:
use lapin::{
    message::Delivery,
    options::{BasicAckOptions, BasicConsumeOptions, BasicRejectOptions},
    types::FieldTable,
    Connection, ConnectionProperties,
};

BasicAckOptions, BasicConsumeOptions and BasicRejectOptions come from proc-macro. "Go to definition" doesn't work on them. It works but redirects you a wrong source-site.

@edwin0cheng edwin0cheng added the A-macro macro expansion label Mar 29, 2020
@edwin0cheng
Copy link
Member

edwin0cheng commented Mar 29, 2020

Goto definition do not work in include! macro yet. Do completion show them correctly ?

@cynecx
Copy link
Contributor Author

cynecx commented Mar 29, 2020

Oh, I see. Yes, completions do work. Is there an already opened issue for that? (So I might close this one.)

@edwin0cheng
Copy link
Member

@cynecx This is the first issue for that :)

@cynecx
Copy link
Contributor Author

cynecx commented Apr 5, 2020

@edwin0cheng I am currently on master. And it seems that it's broken (In terms of it doesn't even find/resolve items). I am not quite sure when it broke though. I haven't realized since today when I came across this again.

Nevermind, it seems that the option changed from rust-analyzer.cargoFeatures.loadOutDirsFromCheck to rust-analyzer.cargo.loadOutDirsFromCheck.

@fahrradflucht
Copy link

Maybe we update the title? I was about to open an issue for include! macros not being followed for goto definition.

@mvtec-bergdolll
Copy link

What is missing for this to be supported?

@matklad
Copy link
Member

matklad commented Jun 17, 2022

@mvtec-bergdolll I think it's not so much "anything missing", but rather "we need to redesign one of our core abstractions to support this at all". See #9403.

@g0hl1n
Copy link

g0hl1n commented Jul 11, 2022

This would make life a lot easier when working with tonic in vscode.
Any ETA for a fix or any workarounds anybody is aware of?

@sebpuetz
Copy link

[...] any workarounds anybody is aware of?

It's a bit hacky and brittle but you can set the output path for the generated Rust files

    tonic_build::configure()
        .out_dir("src/") // put the generated files under src/, could be a nested directory like src/proto, too.
        .compile(&["./protobuf.proto"], &["./"])

and include the generated file like a regular module:

// lib.rs
mod protobuf;

If your CI runs cargo fmt / rustfmt, you'll probably want ot run rustfmt on the generated files since tonic_build / prost don't format the code.

@bjorn3
Copy link
Member

bjorn3 commented Aug 10, 2022

If you put that in build.rs you need to be aware that cargo prevents publishing crates if it detects that building them changes their source code.

@sebpuetz
Copy link

sebpuetz commented Aug 10, 2022

Publishing should work by adding a feature gate to the code gen (and running rustfmt), e.g. lapin has a code gen feature: https://github.com/amqp-rs/lapin/blob/main/build.rs#L1-L7

with code gen turned off by default:
https://github.com/amqp-rs/lapin/blob/main/Cargo.toml#L18

(I have no experience with publishing the workaround through cargo, so this is speculation on my end)

@jonas-schievink
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants