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

generated_* files seem to throw ides for a loop #440

Open
rsheeter opened this issue May 30, 2023 · 9 comments
Open

generated_* files seem to throw ides for a loop #440

rsheeter opened this issue May 30, 2023 · 9 comments
Assignees

Comments

@rsheeter
Copy link
Collaborator

VSCode + rust-analyzer does far worse at things like jump to definition on the generated_X files. For example, in generated_layout.rs you can't go to definition on the struct for the enum formats here:

#[derive(Clone, Debug)]
pub enum ChainedSequenceContext {
    Format1(ChainedSequenceContextFormat1),
    Format2(ChainedSequenceContextFormat2),
    Format3(ChainedSequenceContextFormat3),
}

I suspect the use via include! might be related. Could we generate them but have them act more like handwritten files, notably not use include! to pull them in?

This slowed me down considerably when confused about how some of the layout types and macros worked.

@dfrg
Copy link
Member

dfrg commented May 31, 2023

This might be as simple as replacing the include with

#[path = “path/to/generated_whatever.rs]
mod generated;
pub use generated::*;

We’d need to add an additional import for codegen_prelude::* if we make use of those types because we currently get it by default with the include.

@cmyr
Copy link
Member

cmyr commented May 31, 2023

This was a known problem in rust-analyzer, but checking now it looks like it was fixed last month? Are you running the latest rust-analayzer? see rust-lang/rust-analyzer#3767.

I did previously use chad's solution, but I believe that this introduced other problems, perhaps around visibility? iirc everything works best when the generated code and the hand-written code is defined in the same module, instead of having the generated code be a submodule.

edit: hmm, okay reading more carefully I do also see your problem, with goto not working from within a generated file. Will look and see if there's an open issue for this in rust-analyzer..

@cmyr
Copy link
Member

cmyr commented May 31, 2023

okay I opened rust-lang/rust-analyzer#14937 to inquire about support in rust-analyzer. Barring that, though, I'm not aware of a good solution to this problem. I personally just end up searching the file for the relevant symbol 😒

@rsheeter
Copy link
Collaborator Author

It's possible to hand-write code for which the tools work. I'm not clear what makes that intractable for machine-written code?

@dfrg
Copy link
Member

dfrg commented May 31, 2023

So while playing with this yesterday, I also realized that my rust-analyzer goto-def was just working with the includes now. I'm completely ambivalent on making this change now that the pain point is gone.

@rsheeter
Copy link
Collaborator Author

rsheeter commented May 31, 2023 via email

@rsheeter
Copy link
Collaborator Author

Per IM it seems you can jump into the generated file but not navigate within it. Navigate within is what I want fixed.

@rsheeter
Copy link
Collaborator Author

Per further IM, if we generate code under src and make it a "normal" module (no include!) this should work. Downsides to this include:

  1. Codegen will need a way to know the path for extern types that Just Work currently because the file that includes them worries about it
  2. non-pub generated code would be less accessible, though ... I think pub(crate) might substantially resolve (?)

Preferred solution is RA fixes it. If that seems unlikely to happen soon we can fix it ourselves.

@cmyr
Copy link
Member

cmyr commented Jun 1, 2023

a note: it doesn't even need to be under source, we can use the notation chad mentions about to specify an arbitrary path to a module. This means we wouldn't need to move the files, which means we could keep all the generated files in their own directory (which makes the project easier to navigate, and makes it easier to know what to ignore in code review)

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

3 participants