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

Does not work for attribute proc macros #6029

Closed
dakyskye opened this issue Sep 18, 2020 · 33 comments · Fixed by #9128
Closed

Does not work for attribute proc macros #6029

dakyskye opened this issue Sep 18, 2020 · 33 comments · Fixed by #9128
Labels
A-macro macro expansion A-nameres name, path and module resolution S-actionable Someone could pick this issue up and work on it right now

Comments

@dakyskye
Copy link

rust-analyzer does not work for this file:

use serenity::{
    client::*,
    framework::standard::{macros::command, Args, CommandResult},
    model::channel::Message,
};

#[command]
fn clear(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
    Ok(())
}

No intellisense, no completion, nothing works. I assume it's because of command macro?

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Yes, attribute proc macros are not supported.

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

I can't edit the issue title, can you rename it to something like the above?

CC #5412, #2984.

@flodiebold
Copy link
Member

Most features should still work as if the attribute wasn't there though.

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

@dakyskye can you confirm that completions are not working?

image

@dakyskye
Copy link
Author

@lnicola yes image

@dakyskye dakyskye changed the title Not working for a certain file Does not work for attribute proc macros Sep 18, 2020
@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Is that Vim? How did you configure rust-analyzer?

@dakyskye
Copy link
Author

@lnicola it is NeoVim, yes, with coc.nvim extension. That's the only rust-analyser config I have "rust-analyzer.serverPath": "rust-analyzer"

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Can you run it (from the same terminal) with rust-analyzer --version? If you installed from source, it should be under ~/.cargo/bin, and I'd expect that to be in PATH, but it doesn't hurt to check.

@dakyskye
Copy link
Author

Weird enough! My output for it is rust-analyzer ???????. I installed it from the Arch packages.

@dakyskye
Copy link
Author

dakyskye commented Sep 18, 2020

pacman -Q --info rust-analyzer outputs Version: 20200914-1

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Can you try https://github.com/fannheyward/coc-rust-analyzer/ instead? I think the official extension doesn't work too well with coc.nvim.

@dakyskye
Copy link
Author

I use coc-rust-analyzer, but with custom rust-analyzer path.

@dakyskye
Copy link
Author

I have also tried it in VSCode though, the same negative result.

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Does it work for you (in Code) with a new project?

@dakyskye
Copy link
Author

Nope
image

@lnicola
Copy link
Member

lnicola commented Sep 18, 2020

Sorry, I meant a new project as cargo new produces.

@dakyskye
Copy link
Author

Yes, I did that.

@matklad
Copy link
Member

matklad commented Oct 15, 2020

Can't reproduce, maybe this is fixed in master?

image

@matklad matklad added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Oct 15, 2020
@dakyskye
Copy link
Author

dakyskye commented Oct 16, 2020

It's weird. I have just tried it in VSCode, Vim and Emacs, works nowhere.
VSC result:
image

@dakyskye
Copy link
Author

dakyskye commented Oct 16, 2020

Ah, you said "master". I have latest release installed, let me build RA myself and try again.

EDIT: built rust-analyzer, but the result is same.

@matklad
Copy link
Member

matklad commented Oct 16, 2020

@dakyskye if you run Rust Analyzer: Status command, does it list anything as file deps?

image

@dakyskye
Copy link
Author

I accidentally deleted vscode package, and just reinstalled it. Now rust-analyzer works well for me in VSC. Let me try it in Emacs now
image

@dakyskye
Copy link
Author

dakyskye commented Oct 17, 2020

It started working in VSCode, but still not working in Vim and Emacs.

@jmg-duarte
Copy link

jmg-duarte commented Mar 18, 2021

I think this is the best place to put this issue.
I have a macro that adds a field to a struct.
For example:

#[add]
struct S;

Gets expanded to:

struct S { pub field: T }

While this compiles without a problem, rust-analyzer reports: no such field.
So, my issue is not about autocomplete, it's just about making the analyzer view the expansion result.

@bjorn3
Copy link
Member

bjorn3 commented Mar 18, 2021

Missing autocompletion is just a symptom of the fact that attribute proc macros are currently unimplemented.

@DanielJoyce
Copy link

DanielJoyce commented Apr 13, 2021

Yeah, would this explain why mockall_double #[double] macro doesn't work? Cargo check works, but rust analyzer gets confused and looks for Mock type not actual type outside test code.

@sanfusu
Copy link

sanfusu commented Apr 17, 2021

Are there any plans to support this feature?

@abreis
Copy link

abreis commented Apr 17, 2021

Yes, it's on the roadmap for the next six weeks: #8486

@flodiebold flodiebold added S-actionable Someone could pick this issue up and work on it right now and removed S-unactionable Issue requires feedback, design decisions or is blocked on other work labels May 21, 2021
bors bot added a commit that referenced this issue Jun 3, 2021
9128: feat: expand procedural attribute macros r=jonas-schievink a=jonas-schievink

This adds experimental support for attribute macros. They can be enabled by setting `rust-analyzer.experimental.procAttrMacros` to `true`.

Known issues:
* Tokens aren't remapped, presumably because we edit the input syntax tree (this causes IDE features to not work inside items with attribute macros on them)
* Macro errors aren't reported correctly

Closes #8971
Fixes #8964 / la10736/rstest#120
Fixes #2984
Fixes #5412
Fixes #6029
Fixes #6687

#6740 is still not fixed – we now expand `#[proc_macro_hack]`, but fail to expand the resulting `proc_macro_call!()` macro.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
@bors bors bot closed this as completed in 1415367 Jun 3, 2021
@bors bors bot closed this as completed in #9128 Jun 3, 2021
@dakyskye
Copy link
Author

dakyskye commented Jun 3, 2021

Oh, finally 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-nameres name, path and module resolution 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.