No autocompletion with rust-analyzer and wasm-bindgen

When I open the DOM web-sys example with VS Code (using the latest rust-analyzer), I don't get any autocompletion after typing document..

Is this to be expected because of the #[wasm_bindgen] attribute macro?
I tried enabling rust-analyzer.experimental.procAttrMacros but that didn't help.

1 Like

I have not managed to get auto completion working with web-sys/IntelliJ yet either.

This is a bug in rust-analyzer: Inside macros, methods don't show up in completion after a dot · Issue #8158 · rust-lang/rust-analyzer · GitHub.

Turning attribute macros off would work around it, but results in the web-sys API not being generated, so it doesn't help here.

Support for attribute macros is generally still experimental, but should improve over the next releases.

I don't think it's this specific bug, since that bug is about function-like instead of attribute-like macros and also the behavior with wasm-bindgen is worse: I don't get autocompletion for getElementId even after typing document.get.

This isn't about attribute macros in general, autocompletion works fine in #[tokio::main] attributed functions for example, so there must be something that the wasm-bindgen macro is doing in specific that breaks rust-analyzer.

I don't know if this is something rust-analyzer can improve since I think that there are some macros that rust-analyzer won't ever support since they are way too complicated. If that's the case maybe wasm-bindgen could be adapted with such limitations in mind.

That bug applies to macros in general, and is particularly hard to fix for procedural macros (to the point that it either requires some hacks that let macro authors opt in to a workaround, or support from syn that is equivalent to a rewrite and large breaking change).

You are also seeing Completion does not work in attribute macros · Issue #9866 · rust-lang/rust-analyzer · GitHub, which makes completion within attribute macros just generally not work.

Some quick testing shows that we seem to support both snippets in that comment just fine.

Sorry, I should have been more specific. Hover doesn't work in the following inner! macro. (Note that the macro has been simplified, the real macro actually used the $d argument).

macro_rules! outer {
    ($block:block) => {
        {
            macro_rules! with_dollar_sign {
                ($a:tt => $b:tt) => {
                    macro_rules! __with_dollar_sign { $a => $b }
                    __with_dollar_sign!($);
                }
            }

            with_dollar_sign! {
                ($d:tt) => {
                    macro_rules! inner {
                        ($blk:block) => {
                            $blk
                        };
                    }
                }
            }
            $block
        }
    };
}

fn main() {
    outer!({
        let s = String::new();
        s.len();
        inner!({
            s.len();
        });
    });
}

Thanks, filed Incorrect macro expansion with doubly nested macros · Issue #10125 · rust-lang/rust-analyzer · GitHub for that issue.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.