rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Macros cannot be expanded in certain situations.

Open coderfreii opened this issue 1 year ago • 3 comments

rust-analyzer version: v0.3.2062

rustc version: rustc 1.80.0 (051478957 2024-07-21)

editor or extension: VSCode

relevant settings: default

repository link (if public, optional): (https://github.com/jkb0o/belly/blob/main/crates/belly_widgets/src/input/slider.rs)

code snippet to reproduce:

#[widget]
#[extends(RangeWidget)]
#[styles(
    slider .slider-grabber {
      margin: 0px;
      min-width: 16px;
      min-height: 16px;
      width: 16px;
      height: 16px;
    }
)]
fn slider(ctx: &mut WidgetContext) {
    let grabber = SliderGrabber {
        slider: ctx.entity(),
    };
    let params = ctx.params();
    ctx.render(eml! {
        <range c:slider params=params>
            <slot separator>
                <button with=grabber mode="instant" c:slider-grabber>
                </button>
            </slot>
        </range>
    })
}

When I use the command 'Expand macro recursively at caret' on a macro widget, nothing happens. After that, I commented out the content in the macro styles, and it worked.

For example:

#[widget]
#[extends(RangeWidget)]
#[styles(
    // slider .slider-grabber {
    //   margin: 0px;
    //   min-width: 16px;
    //   min-height: 16px;
    //   width: 16px;
    //   height: 16px;
    // }
)]
fn slider(ctx: &mut WidgetContext) {

coderfreii avatar Aug 09 '24 05:08 coderfreii

And the cargo expand command produces the correct output.

            fn split_components(
                &self,
                components: Self::Components,
            ) -> (Self::BuildComponents, Self::OtherComponents) {
                let () = components;
                ((), ())
            }
            fn default_styles(&self) -> &str {
                "slider .slider-grabber {\n  margin: 0px;\n  min-width: 16px;\n  min-height: 16px;\n  width: 16px;\n  height: 16px;\n}\n\n"
            }

coderfreii avatar Aug 09 '24 06:08 coderfreii

I imagine we might be tokenizing things wrongly (the 16px looks suspicious to me as that is a special kind of literal)

Veykril avatar Aug 27 '24 09:08 Veykril

here's another one that won't re-expand after any line change; you must manually "restart" rust-analyzer every time to get rid of red squiggly highlighting:

macro_rules! make_types {
    ( $l:ident, ($($n:ident $c:literal $d:expr),*)) => {
        $( pub const $n: &str = $c; )*

        lazy_static! {
            pub static ref $l: Vec<(&'static str, DataType)> = vec![
                $( ($n, $d), )*
            ];
        }
    };
}

it also strangely highlights this use as "unresolved import" until I restart after every code change: use lazy_static::lazy_static;

evbo avatar Aug 27 '24 23:08 evbo