rust-lang / rust-analyzer

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

Does not work for attribute proc macros #6029

Closed dakyskye closed 2 years ago

dakyskye commented 3 years ago

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 commented 3 years ago

Yes, attribute proc macros are not supported.

lnicola commented 3 years ago

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

CC #5412, #2984.

flodiebold commented 3 years ago

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

lnicola commented 3 years ago

@dakyskye can you confirm that completions are not working?

image

dakyskye commented 3 years ago

@lnicola yes image

lnicola commented 3 years ago

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

dakyskye commented 3 years ago

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

lnicola commented 3 years ago

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 commented 3 years ago

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

dakyskye commented 3 years ago

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

lnicola commented 3 years ago

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 commented 3 years ago

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

dakyskye commented 3 years ago

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

lnicola commented 3 years ago

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

dakyskye commented 3 years ago

Nope image

lnicola commented 3 years ago

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

dakyskye commented 3 years ago

Yes, I did that.

matklad commented 3 years ago

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

image

dakyskye commented 3 years ago

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

dakyskye commented 3 years ago

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 commented 3 years ago

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

image

dakyskye commented 3 years ago

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 commented 3 years ago

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

seanybaggins commented 3 years ago

@matklad I am having a similar issue.

Rust analyzer status

workspaces:
54 packages loaded

analysis:
4067 (46mb) files
0 (0b) index symbols
1211 trees, 128 retained
18692 trees, 128 retained (macros)
472mb total

requests:
  783 textDocument/semanticTokens/full/delta2ms
  784 completionItem/resolve              1ms
  785 textDocument/foldingRange           0ms
  786 textDocument/codeLens               0ms
  787 textDocument/codeAction             1ms
  788 textDocument/documentSymbol         0ms
  791 textDocument/codeAction             1ms
* 779 textDocument/documentSymbol         0ms
  781 rust-analyzer/inlayHints            6ms
  782 textDocument/completion             7ms

image

I should see a bunch of pbx options (where x is some integer) within the drop down.

You can find the code with a Dockerfile to reproduce the environment here

anirudhb commented 3 years ago

Any plans to work on this? Is there anything blocking this?

AlaaZorkane commented 3 years ago

Similar issue with wasm_bindgen :/ (no typings and no type completion)

image image

jonas-schievink commented 3 years ago

Any plans to work on this? Is there anything blocking this?

In short, what needs to be done to get this working is:

jmg-duarte commented 3 years ago

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 commented 3 years ago

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

DanielJoyce commented 3 years ago

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 commented 3 years ago

Are there any plans to support this feature?

abreis commented 3 years ago

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

dakyskye commented 2 years ago

Oh, finally 🎉 🎉