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

Actix-web's attribute macros are not IDE friendly #2394

Closed
Veykril opened this issue Oct 6, 2021 · 1 comment · Fixed by actix/actix-net#391 or #2410
Closed

Actix-web's attribute macros are not IDE friendly #2394

Veykril opened this issue Oct 6, 2021 · 1 comment · Fixed by actix/actix-net#391 or #2410
Labels
A-codegen project: actix-web-codegen C-improvement Category: an improvement to existing functionality good-first-issue easy to pick up for newcomers

Comments

@Veykril
Copy link

Veykril commented Oct 6, 2021

In short this is a problem with how syn and attributes using syn implement failure, as these crates tend to just discard the entire attributed item on a parsing failure, replacing it with a compile_error! invocation. This has the side effect that when typing inside an item, a user may momentarily create invalid syntax causing the item to be fully discarded resulting in loss of IDE features as the item now effectively does not exist in the file until this syntax error has been fixed.

Possible Solution

A simple solution to this problem is to change the attributes such that when they error, they re-emit the original item with the compile_error! invocation, that way IDEs will still see the item even if the attribute fails causing IDE features to continue to function.

Sidenote: This will fix the general problem, but if the attribute introduces new usable items inside the item they will of course not always be visible in completions with just this fix. An ideal fix would be to make the attribute do parsing with recovery in such cases if required.

Steps to Reproduce

This problem can be observed(in rust-analyzer) by doing the following.
Using the Readme's example snippet(where $0 represents the current cursor position):

use actix_web::{get, web, App, HttpServer, Responder};

#[get("/{id}/{name}/index.html")]
async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder {
    format!("Hello {}! id:{}", name, id)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    $0
    HttpServer::new(|| App::new().service(index))
        .bind("127.0.0.1:8080")?
        .run()
        .await
}
  1. Type 0.m and notice that we do not get any completions
  2. Comment out the #[actix_web::main] attribute
  3. Type 0.m again, this time with completions
  • Rust Version (I.e, output of rustc -V): rustc 1.55.0 (c8dfcfe04 2021-09-06)
  • Actix Web Version: 3.3.2

See a relevant RA issue rust-lang/rust-analyzer#10468

@robjtede robjtede added C-improvement Category: an improvement to existing functionality A-codegen project: actix-web-codegen good-first-issue easy to pick up for newcomers labels Oct 6, 2021
@robjtede robjtede reopened this Oct 14, 2021
@robjtede
Copy link
Member

fixed runtime macros in actix/actix-net#391, reopening until the route macros also are fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen project: actix-web-codegen C-improvement Category: an improvement to existing functionality good-first-issue easy to pick up for newcomers
Projects
None yet
2 participants