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

Use Rust Analyzer API to generate robust completions #71

Open
Veetaha opened this issue Aug 28, 2024 · 1 comment
Open

Use Rust Analyzer API to generate robust completions #71

Veetaha opened this issue Aug 28, 2024 · 1 comment
Labels
feature request A new feature is requested

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Aug 28, 2024

Context

I wrote some experimental code to generate completions for the builder macro here. It was showcased in the 2.0 update blog post.

However, the current impl is rather limited. It does some custom manual parsing trying to be resilient to incomplete/errored syntax. The goal for this effort is that the macro must be able to parse any incomplete syntax and always generate the use statements with completions for all attributes passed to the macro. This must include attributes on struct fields and on function arguments (current dirty impl ignores those).

Summary

The idea is to use rust-analyzer's APIs (RA publishes its crates to crates.io) to parse the tokens handed to the macro instead of using the custom impl I wrote, which is very limited. The RA crates need to be added as dependencies under cfg(rust_analyzer) condition only. For example:

[target.'cfg(rust_analyzer)'.dependencies]
ra_ap_syntax = "=0.0.232"

The cfg(rust_analyzer) is an internal CFG used by RA when it analyzes Rust's code. We can work with RA maintainers to guarantee this CFG is stable, or discuss alternatives (maybe use a more generic name for the CFG).

This effort requires a lot of research and the nuances are undiscovered yet. I'm not yet sure how hard this will be to use RA to provide good completions for users, and also keep it in sync with the real macro implementation.

@Veetaha Veetaha added the feature request A new feature is requested label Aug 28, 2024
@Veetaha Veetaha changed the title Try using Rust Analyzer API to generate robust completions Use Rust Analyzer API to generate robust completions Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new feature is requested
Projects
None yet
Development

No branches or pull requests

2 participants
@Veetaha and others