Skip to content

#[instrument] attribute is not IDE friendly #1633

@Veykril

Description

@Veykril

Feature Request

Crates

tracing-attributes

Motivation

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.

This is becoming a bigger problem now as Rust-Analyzer enabled attribute expansion by default starting this week which causes users to run into this problem.

Proposal

A simple solution to this problem is to change the attribute such that when it errors, it re-emits 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 which could benefit from IDE features like completions for example, they will of course not always be visible to these features with just this fix. An ideal fix would be to make the attribute do parsing with recovery in such cases if required or emit the expected output on a best effort basis even with invalid or unexpected input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/attributesRelated to the `tracing-attributes` cratekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions