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

Span hygene and editor UX #2702

Merged
merged 3 commits into from May 25, 2022
Merged

Conversation

WorldSEnder
Copy link
Member

@WorldSEnder WorldSEnder commented May 24, 2022

Description

Fixes #2381

Additionally, renaming should now work correctly for usages of component types, properties and in expressions for keys and refs.

To expand on the latter: A quoted TokenStream can have two Spans attached to it: resolved_at and located_at:

  • errors in an expression are reported at located_at
  • quoted expressions (occurances) have a "usage" attached to the span in resolved_at. This not only impacts name resolution, but also renaming and other editor actions analyzing usage.

So by decoupling the two and using Span::call_site() more often instead of using the same span for both resolved_at and located_at, editors should be less confused which item should be targeted by a rename or usage lookup. Try it out in your editor. I don't have a good approach to automating these UX tests… Sample manual test code:

#[derive(
    ::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq,
)]
pub struct ContainerProperties {
    pub int: ::std::primitive::i32,
    #[prop_or_default]
    pub children: ::yew::Children,
    #[prop_or_default]
    pub header: ::yew::Html,
}

#[::yew::function_component]
fn Container(_: &ContainerProperties) -> ::yew::Html {
    ::std::unimplemented!()
}

fn compile_pass() {
    // Hover any identifier in here and try to rename it!
    // E.g `the_ref` inside the `<div ref=` or the `Container` in any opening/closing tag
    let the_ref = ::yew::NodeRef::default();
    let an_expression = 34;
    let int = 42;
    ::yew::html! {
        <>
        <div ref={the_ref} hidden={true} />
        <Container {int} key={an_expression} />
        <Container int=1></Container>
        </>
    };
}

Checklist

  • I have reviewed my own code
  • I have added tests. Indeed... how to test editor UX

github-actions[bot]
github-actions bot previously approved these changes May 24, 2022
@github-actions
Copy link

github-actions bot commented May 24, 2022

Visit the preview URL for this PR (updated for commit fe8011a):

https://yew-rs-api--pr2702-editor-spans-elxgb9lf.web.app

(expires Tue, 31 May 2022 16:39:54 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented May 24, 2022

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
boids 172.848 172.848 0 0.000%
contexts 109.696 109.696 0 0.000%
counter 86.652 86.652 0 0.000%
counter_functional 87.304 87.304 0 0.000%
dyn_create_destroy_apps 89.771 89.771 0 0.000%
file_upload 102.620 102.620 0 0.000%
function_memory_game 167.285 167.285 0 0.000%
function_router 350.031 350.031 0 0.000%
function_todomvc 161.962 161.962 0 0.000%
futures 226.660 226.660 0 0.000%
game_of_life 107.538 107.538 0 0.000%
inner_html 83.688 83.688 0 0.000%
js_callback 112.918 112.918 0 0.000%
keyed_list 195.100 195.100 0 0.000%
mount_point 86.281 86.281 0 0.000%
nested_list 115.912 115.912 0 0.000%
node_refs 90.521 90.521 0 0.000%
password_strength 1539.690 1539.690 0 0.000%
portals 97.267 97.267 0 0.000%
router 319.142 319.142 0 0.000%
simple_ssr 153.538 153.538 0 0.000%
ssr_router 394.824 394.824 0 0.000%
suspense 110.563 110.563 0 0.000%
timer 89.391 89.391 0 0.000%
todomvc 143.054 143.054 0 0.000%
two_apps 87.285 87.285 0 0.000%
web_worker_fib 153.531 153.531 0 0.000%
webgl 87.374 87.374 0 0.000%

✅ None of the examples has changed their size significantly.

@WorldSEnder
Copy link
Member Author

WorldSEnder commented May 24, 2022

Note, renaming inside prop expressions seem to be blocked by rust-lang/rust-analyzer#11272 in vscode. I don't know if other editors can handle it, would like to know.

@hamza1311 hamza1311 added this to the v0.20 milestone May 24, 2022
@hamza1311 hamza1311 added ergonomics A-yew-macro Area: The yew-macro crate labels May 24, 2022
Copy link
Member

@hamza1311 hamza1311 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I haven't tested the changes but I don't see them breaking anything.

Also, can you create an issue in the Rust Analyzer repository asking how to test the changes in this PR? Rust Analyzer should also cover intellij-rust since they both have the same proc-macro expansion engine under-the-hood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew-macro Area: The yew-macro crate ergonomics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect span assignment of identifier in the generic argument of a closing tag
2 participants