BUG: candid_method macro messes up intellisense and stops it from working

Applying the #[candid::candid_method] macro for autogeneration of Candid in a Rust project breaks intellisense on that function. Here’s a minimal reproduction:

Steps to reproduce:

  • Clone repo and install dependencies
  • Open the project in a VS Code instance with the rust-analyzer extension installed
  • Try prompting intellisense in the increment_1 and increment_2 functions
  • Intellisense doesn’t work in the first one with both macros but works in the second one

Here are some screenshots:

Intellisense shows generic word results here

Intellisense shows relevant results received from the Rust language server

Additional environment details:

  • Running on Windows 11 with WSL 2
  • VS Code stable
  • rust-analyzer - official extension for Rust autocomplete

I’ve posted the bug to the Github repo but adding here for visibility. In case you’d like me to remove either, do let me know

@chenyan

1 Like

I’m not using VSCode, so hard for me to triage the problem. But it seems like a rust-analyzer problem, since rustc can compile the code just fine?

Thank you for confirming. I will open an issue with the rust-analyzer repo.

Hi @chenyan

I opened an issue with the rust-analyzer team here and they acknowledged the issue and had thoughts on both how the extension could possibly handle this scenario better but also on how a part of the candid method macro should ideally be written differently.

They finally conclude that this is a bug in the proc macro here

They also point to the offending code here

Would appreciate your thoughts on the Github issue to get us to a resolution.

Thank you :slight_smile:

Thanks for the update. It all makes sense. I don’t see an immediate solution on either end. As a workaround, can you comment out candid_method while using auto-completion and only enable them for deployment?

1 Like

Yes, that’s what I’m doing right now.

From what I understand, this issue will persist for now until the macro code is rewritten to not use this:

using a global counter to generate identifiers

Would you consider adding an issue in your issue tracker for the candid macros so that this behaviour is rectified when you’re refactoring/updating candid macro code in the future?

The offending code is here: candid/func.rs at master · dfinity/candid · GitHub, which is blocked by the Rust issue I linked in the comment. I will watch that issue when they have a solution.

1 Like