intellij-rust / intellij-rust

Rust plugin for the IntelliJ Platform
https://intellij-rust.github.io
MIT License
4.54k stars 379 forks source link

Yew html macro error Expect Html found () #6732

Open johansmitsnl opened 3 years ago

johansmitsnl commented 3 years ago

Environment

Problem description

When wrapping the html in the match it gives this markup error but it works fine. Also the compiler thinks it is ok.

Schermafdruk van 2021-01-27 09-33-57

Steps to reproduce

Wrap a view in a match case like this:

fn view(&self) -> Html {
        let account: models::Account = models::Account::default(),

        match self.props.kind {
            ViewKind::Name => {
                html! {
                    <>
                         <>{ &account.name }</>
                    </>
                }
            }
            ViewKind::Avatar => {
                html! {
                    <>
                        <img src=&account.avatar_url class="avatar img-fluid avatar-xs mr-3" alt=&account.name />
                    </>
                }
            }
        }
    }
Waridley commented 2 years ago

With maud's html! macro, the error goes away if you change the braces to square or parens. Is the same true for yew?

ctron commented 2 years ago

For me using html![] or html!() seems to work, but fails in a different way. It then detects the code as unreachable.

jetaggart commented 2 years ago

This is still happening on nightly. Switching to [] fixes the issue for me, but why does it fail with html!{}?

ctron commented 2 years ago

We switched to Yew 0.19 a while back. That actually "solved" the issue.

jetaggart commented 2 years ago

FWIW, I'm on nightly yew and nightly rust plugin and this is still broken.

ranile commented 2 years ago

nightly yew

Yew does not have a nightly release. You may want to clarify what you're referring to

jetaggart commented 2 years ago

@hamza1311 the master branch: yew = { git = "https://github.com/yewstack/yew/" }

dima74 commented 2 years ago

@johansmitsnl @Waridley @ctron @bit-void do you still experience this problem? If yes, could you please provide minimal example? I can't reproduce it with 0.4.176.4762-221-nightly and yew = { git = "https://github.com/yewstack/yew/" }:

ctron commented 2 years ago

No, I haven't seen this in a while. IIRC there was a significant improvement when migrating from Yew 0.17 to 0.19 (not sure about 0.18). I guess this improved something, which made it work better with the Rust plugin. It is ok to close from my point of view.

johansmitsnl commented 2 years ago

@dima74 I have not used yew projects lately so I can't give feedback on it. But @ctron does not experiencing it you can close it if you like.

YthanZhang commented 2 years ago

Hi, I just encountered this issue, the project is very minimal, only containing Cargo.toml and src/main.rs

main.rs

use yew::prelude::*;

fn main() {
   yew::start_app::<App>();
}

#[function_component(App)]
pub fn app() -> Html {
    html! {
        <div>
            <h2 class={"heading"}>{"Hello, World!"}</h2>
        </div>
    }
}

Cargo.toml

[package]
name = "yew-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yew = "0.19.3"

Environment

Interestingly if I replace the html! {} with html! () or html! [] the error disappears.

I tried setting toolchain to nightly, but that didn't work.

dima74 commented 2 years ago

@YthanZhang could you please try to enable org.rust.cargo.evaluate.build.scripts and org.rust.macros.proc experimental features

YthanZhang commented 2 years ago

@dima74 Enabling org.rust.cargo.evaluate.build.scripts fixed the issue. Enabling org.rust.macros.proc didn't seem to affect this issue.

johansmitsnl commented 2 years ago

6908 With this project I can reproduce it easily: https://github.com/johan-smits/sycamore

org.rust.cargo.evaluate.build.scripts fixes the issue the component warning to be lowercase. In the #[component] they have added this ignore message. Schermafdruk van 2022-09-15 19-12-36

org.rust.macros.proc fixes the issue that i says the wrong return type the initial error from this issue: Schermafdruk van 2022-09-15 19-05-45

With both options enabled it is now happy :+1:

Hope this helps.

bradvoth commented 2 years ago

Both experimental features enabled and I still see this issue. However changing to [] from {} resolves. The totality of the app is as follows:

use yew::prelude::*;

struct App {}

impl Component for App {
    type Message = ();
    type Properties = ();

    fn create(_ctx: &Context<Self>) -> Self {
        todo!()
    }

    fn view(&self, _ctx: &Context<Self>) -> Html {
        html! {}
    }
}

fn main() {
    yew::start_app::<App>();
}
dima74 commented 2 years ago

Both experimental features enabled and I still see this issue. However changing to [] from {} resolves

@bradvoth This is very strange. Is the error with {} consistently reproducible? Please try to invalidate caches. Also could you please attach your idea.log and specify what version of yew are you using