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

Tracking issue for procedural macro support #6908

Open
10 of 12 tasks
Undin opened this issue Mar 1, 2021 · 35 comments
Open
10 of 12 tasks

Tracking issue for procedural macro support #6908

Undin opened this issue Mar 1, 2021 · 35 comments
Labels
feature meta Top level/tracking issue that group collections of related issues subsystem::proc-macros Issues related to procedural macros

Comments

@Undin
Copy link
Member

Undin commented Mar 1, 2021

Procedural macro support feature depends on the following (experimental) features:

  • org.rust.cargo.evaluate.build.scripts - enables building and collecting build artifacts including proc-macro libraries during importing of project structure. Enabled by default
  • org.rust.macros.proc.function-like - enables expansion of function-like procedural macros. Enabled by default
  • org.rust.macros.proc.derive - enables expansion of derive procedural macros. Enabled by default
  • org.rust.macros.proc.attr - enables expansion of attribute procedural macros

To enable an experimental feature, type Experimental feature in the dialog of Help | Find Action action, enable the corresponding items and reload the project model via Refresh Cargo Projects action in Cargo tool window

image

@Undin Undin added meta Top level/tracking issue that group collections of related issues feature subsystem::proc-macros Issues related to procedural macros labels Mar 1, 2021
@Undin Undin changed the title Procedural macro support Tracking issue for procedural macro support Mar 1, 2021
@Undin Undin pinned this issue Apr 14, 2021
bors bot added a commit that referenced this issue Apr 16, 2021
6992: MACRO: expand custom derive, resolve impls from custom derive r=vlad20012 a=vlad20012

Issue #6908 

At this point, we can expand custom derive proc macros (except `serde`) and take into account `impl`s generated by them. Other items except impls are ignored. Works only when using the new name resolution engine (#6217). `serde::Serialize` and `serde::Deserialize` are ignored for now because we have fine-working hardcoded impls for them and turning it into honest macro expansion can impact performance (because of LOTS of serde macros everywhere).

changelog: Provide initial support for [custom derive](https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros) procedural macros. Now the plugin can expand such procedural macro calls and take into account expanded `impl` items in type inference and name resolution (other types of items are ignored). Note, it’s only an initial implementation, so it may work in an unexpected way in some cases. The feature is disabled by default for now. To turn it on, you should enable `Use experimental name resolution engine` option in `Preferences | Languages & Frameworks | Rust` settings and enable `org.rust.cargo.evaluate.build.scripts` and `org.rust.macros.proc` experimental features. Don’t forget to reload a project structure after enabling the corresponding features via `Refresh Cargo Projects` action on Cargo tool window. See [tracking issue](#6908) for more details and the current status of procedural macros support

Co-authored-by: vlad20012 <beskvlad@gmail.com>
bors bot added a commit that referenced this issue Apr 16, 2021
6992: MACRO: expand custom derive, resolve impls from custom derive r=undin a=vlad20012

Issue #6908 

At this point, we can expand custom derive proc macros (except `serde`) and take into account `impl`s generated by them. Other items except impls are ignored. Works only when using the new name resolution engine (#6217). `serde::Serialize` and `serde::Deserialize` are ignored for now because we have fine-working hardcoded impls for them and turning it into honest macro expansion can impact performance (because of LOTS of serde macros everywhere).

changelog: Provide initial support for [custom derive](https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros) procedural macros. Now the plugin can expand such procedural macro calls and take into account expanded `impl` items in type inference and name resolution (other types of items are ignored). Note, it’s only an initial implementation, so it may work in an unexpected way in some cases. The feature is disabled by default for now. To turn it on, you should enable `Use experimental name resolution engine` option in `Preferences | Languages & Frameworks | Rust` settings and enable `org.rust.cargo.evaluate.build.scripts` and `org.rust.macros.proc` experimental features. Don’t forget to reload a project structure after enabling the corresponding features via `Refresh Cargo Projects` action on Cargo tool window. See [tracking issue](#6908) for more details and the current status of procedural macros support

Co-authored-by: vlad20012 <beskvlad@gmail.com>
bors bot added a commit that referenced this issue Apr 16, 2021
6992: MACRO: expand custom derive, resolve impls from custom derive r=undin a=vlad20012

Issue #6908 

At this point, we can expand custom derive proc macros (except `serde`) and take into account `impl`s generated by them. Other items except impls are ignored. Works only when using the new name resolution engine (#6217). `serde::Serialize` and `serde::Deserialize` are ignored for now because we have fine-working hardcoded impls for them and turning it into honest macro expansion can impact performance (because of LOTS of serde macros everywhere).

changelog: Provide initial support for [custom derive](https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros) procedural macros. Now the plugin can expand such procedural macro calls and take into account expanded `impl` items in type inference and name resolution (other types of items are ignored). Note, it’s only an initial implementation, so it may work in an unexpected way in some cases. The feature is disabled by default for now. To turn it on, you should enable `Use experimental name resolution engine` option in `Preferences | Languages & Frameworks | Rust` settings and enable `org.rust.cargo.evaluate.build.scripts` and `org.rust.macros.proc` experimental features. Don’t forget to reload a project structure after enabling the corresponding features via `Refresh Cargo Projects` action on Cargo tool window. See [tracking issue](#6908) for more details and the current status of procedural macros support

Co-authored-by: vlad20012 <beskvlad@gmail.com>
@webern
Copy link

webern commented Jun 3, 2021

Does this mean that a subset of derive macro code is currently considered (e.g. for code completion and missing-symbol highlighting?

take into account all items generated by custom derive macros

For example, the Snafu derive macro produces structs which intellij-rust seems to be unaware of.

Would a minimal use case example of this and tracking issue be of any benefit?

@Undin
Copy link
Member Author

Undin commented Jun 4, 2021

@webern

Does this mean that a subset of derive macro code is currently considered (e.g. for code completion and missing-symbol highlighting?

Yep. Currently, the plugin takes into account only impl blocks generated by derive proc macro

Would a minimal use case example of this and tracking issue be of any benefit?

I don't think that we need additional tracking issue only for that case because the current issue already contains a similar item: "take into account all items generated by custom derive macros". But an additional use-case can be useful indeed to check it during the corresponding implementation

@webern
Copy link

webern commented Jun 14, 2021

additional use-case can be useful indeed to check it during the corresponding implementation

Here is the use-case:

Cargo.toml:

[package]
name = "snafu-jetbrains"
version = "0.1.0"
edition = "2018"

[dependencies]
snafu = "0.6"

main.rs

use snafu::Snafu;

/// The error type for this library.
#[derive(Debug, Snafu)]
enum Error {
    #[snafu(display("This is always an error:: {}", message))]
    AlwaysError { message: String },
}

fn hello_world() -> Result<(), Error> {
    AlwaysError {
        message: "this is a struct created by snafu",
    }
    .fail()
}

fn main() {
    hello_world().unwrap()
}

Problem:

image

Desired behavior: code completion should be available for the struct AlwaysError:

image

Desired behavior: context actions should provide the ability to fill in missing struct fields for the AlwaysError struct.

image

Thank you! 🚀

@Undin
Copy link
Member Author

Undin commented Jun 18, 2021

@webern Thank you for your example. I've filed a separate issue #7365 with it

bors bot added a commit that referenced this issue Jun 25, 2021
7307: CI&MACRO: expand proc macros on Apple Silicon machines r=Undin a=Undin

Part of #6908

changelog: Support [procedural macro](https://doc.rust-lang.org/reference/procedural-macros.html) expansion on Apple Silicon machines. Note:
- you should use `aarch64-apple-darwin` toolchain to make procedural macro expansion work
- the proc macro expansion is still disabled by default. To turn it on, enable `org.rust.cargo.evaluate.build.scripts` and `org.rust.macros.proc` [experimental features](https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-faq.html#experimental-features)

Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
@webern
Copy link

webern commented Jul 27, 2021

How are we coming along on take into account all items generated by custom derive macros and #7365? This is suuuuuch a huge feature for me. Is at the top of the intellij-rust priority list?

Right now I have to open Sublime Text using Rust Analyzer to discover generated structs and functions! Help, I'm lost without my IDE!

@vlad20012
Copy link
Member

@webern #7725

@ranile
Copy link

ranile commented Aug 24, 2021

What's blocking #6732? I don't see that issue mentioned here. I'm experiencing the same problem and would love if that is fixed.

@vlad20012
Copy link
Member

@hamza1311, I suppose it's #7725, but you can use the latest yew version from GitHub (not from crates.io) that works well right now.

@ranile
Copy link

ranile commented Aug 24, 2021

@vlad20012, I see. It seems that specific case is fixed but there are other cases where the bug still exists. For example, the following code still gives the same message:
lib.rs:

use yew::prelude::*;

fn _test() -> Html {
    use_effect(|| {
        || {}
    });

    html! {

    }
}

Cargo.toml:

[package]
name = "yew-html-macro-bug-repro"
version = "0.1.0"
edition = "2018"

[dependencies]
yew = { git = "https://github.com/yewstack/yew/" }

Screenshot:
image

It is also worth mentioning that the warning disappears if I do this:
image

@lfrancke
Copy link

I tried enabling this, refreshed a cargo project and it just worked.
Unfortunately, it only worked once. All changes since the initial refresh don't show up.
I tried refreshing, I disabled and reenabled the functionality but nothing worked.

My code compiles fine even though IntelliJ now shows it as "red".

Before I open a new ticket I thought I'd ask if I am maybe missing something: Do I need to do anything to manually update proc macro details and/or can I delete a cache somewhere? A cargo clean followed by a refresh works. Is this intended?

@johansmitsnl
Copy link

Had a issue with Sycamore (originally reported it for Yew) but these experimental features solved it for me. Also added screenshots and a repo to reproduce it: #6732 (comment)

@CristianKerr
Copy link

Hi I wanted to activate org.rust.macros.proc as an experimental feature, but I do not see it in there, what can I do to make it available? Thanks

@Undin
Copy link
Member Author

Undin commented Oct 21, 2022

@CristianKerr follow this instruction

@CristianKerr
Copy link

@CristianKerr follow this instruction
Its not there
Screenshot from 2022-10-21 12-17-30

@Undin
Copy link
Member Author

Undin commented Oct 21, 2022

@CristianKerr I suppose you use too old plugin version

@CristianKerr
Copy link

@CristianKerr I suppose you use too old plugin version

You are right, I have 0.3.140.3644-202, but I do not know why it doesn't show latest version for me (it looks like its up to date). Thanks!

@Undin
Copy link
Member Author

Undin commented Oct 21, 2022

I do not know why it doesn't show latest version for me

Probably, you use old IDE version as well

@CristianKerr
Copy link

@Undin you are right, got stuck on older version, thanks for the help!

@Mersid
Copy link

Mersid commented Dec 14, 2022

I am not fully sure if this issue is related to procedural macros, but I'll post it here anyway. So, some functions from libraries do not show up in code completion:
image

As one can see, on line 20 it shows that it is a perfectly valid function, but attempting to invoke the code completion dropdown will show that it cannot find a function by that name. I have all of the experimental features turned on, but it doesn't appear to help:
image

Now, using the Re-Expand All Rust Macros command does fix it:
image

But it causes additional problems, because now CLion marks a lot of code as invalid and says things like "cannot move":
image

Or "use of moved" value:
image

The code does still work, and these errors did not show up before re-expanding macros. Additionally, re-expanding macros breaks the IDE's ability to detect and detect some macro-related code. Notice how BinaryTreeKey is in white; it appears that CLion no longer knows that BinaryTreeKey is a struct:
image


Closing and re-opening the project does fix these issues:

image
image

But it also means that code completion can't find some functions again:
image

Does anyone know how to fix this, or is this something that cannot be remedied?

Thanks!

@Mersid
Copy link

Mersid commented Dec 19, 2022

I think I found another issue. Macros that take structs don't show up properly if documentation in it ends with a backslash. For example, observe these two instances. They work fine normally
image
But when adding backslashes to the comment (and it only works with triple slash comments that end with a backslash),
image
The coloring gets stripped out, showing that the IDE is no longer able to properly recognize the code. I am not quite sure why this is happening, but it does mean that these types do not show up in code completion. An example is from the wgpu crate: the functions in wgpu::Features::* do not work because two of the bit flags end with a backslash in its comment.

@Mersid
Copy link

Mersid commented Dec 20, 2022

Environment

  • IntelliJ Rust plugin version: 0.4.185.5086-223
  • Rust toolchain version: nightly-x86_64-pc-windows-msvc, rustc 1.68.0-nightly (37d7de337 2022-12-12)
  • IDE name and version: CLion 2022.3
  • Operating system: Windows 10

Problem description

Derive macros do not appear to recognize procedural macros in code completion

Steps to reproduce

  1. Install something like bytemuck
  2. Derive (for example) bytemuck::Zeroable
  3. Observe that it should be valid, but if you enter bytemuck::Zeroabl (missing the last character) and hit Ctrl + Space to bring up the code completion, it will say that there are no suggestions.

For this test, ensure Cargo.toml has these two dependencies:

glam = {version = "0.22.0", features = ["bytemuck"]}
bytemuck = {version = "1.12.3", features = ["derive"]}

Create a struct:

#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroabl)]
pub struct Vertex {
    position: glam::Vec3,
    color: glam::Vec3
}

Observe that:
image

No suggestions. But if we were to manually enter it correctly?
image
It recognizes it.

@djdisodo
Copy link

djdisodo commented Jan 5, 2023

Span::call_site.source_file.path has empty path

bors bot added a commit that referenced this issue Jun 23, 2023
10607: Enable attribute procedural macro expansion by default r=vlad20012 a=vlad20012

It looks like most of the issues with attribute macros are fixed now, so we can enable their expansion by default.

Part of #6908

Fixes #5104
Fixes #5239
Fixes #5748
Fixes #5896
Fixes #6006
Fixes #6091
Fixes #6093
Fixes #6482
Fixes #6938
Fixes #7610
Fixes #7863
Fixes #8350
Fixes #8407
Fixes #8640
Fixes #9128
Fixes #9384
Fixes #9534
Fixes #9918
Fixes #9973

changelog: Enable [attribute](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) procedural macro expansion by default.


Co-authored-by: vlad20012 <beskvlad@gmail.com>
@Maksim20023 Maksim20023 unpinned this issue Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature meta Top level/tracking issue that group collections of related issues subsystem::proc-macros Issues related to procedural macros
Projects
None yet
Development

No branches or pull requests