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

[Feature]: Refactor How motsu Modifies Test Functions to Improve IDE's Ability to Resolve References #24

Open
1 task done
0xNeshi opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working enhancement New feature or request question Further information is requested

Comments

@0xNeshi
Copy link
Collaborator

0xNeshi commented Jan 13, 2025

What is the feature you would like to see?

In VS Code with rust-analyzer extension, code reference behavior is inconsistent within functions annotated with #[motsu::test]. This makes it difficult to navigate from our tests to the actual contract functions being tests (e.g. to verify the function logic).

NOTE: examples of "code reference behavior": "Go to Definition", "Go to References", "Peek > Peek Call Hierarchy" etc.).

For example, see in the attached video showing how "go to" commands behave in error_when_minting_token_id_twice:

  • when going to the definition of: motsu::test, Erc721Consecutive, msg, and matches! macro - all works fine.
  • when trying to go to the definition of: _mint, random_token_id, contract - no definitions/references are found.

Since a large number of developers use VS Code, it might be prudent to make their experience with using motsu as smooth as possible.

Possible explanation (needs to be verified!)

The macro is creating a new context where the contract parameter is introduced, but this happens at compilation time. Before macro expansion, the IDE only sees the raw TokenStream and can't properly resolve the references within it.
VS Code (through rust-analyzer) tries to resolve symbols before macro expansion, which is why it can't find the definition. The actual binding of contract and its methods only exists after the macro is expanded.

Screencast.from.13-01-25.10.46.47.webm

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines
@0xNeshi 0xNeshi added bug Something isn't working enhancement New feature or request labels Jan 13, 2025
@0xNeshi 0xNeshi added the question Further information is requested label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant