Skip to content

Integration with rust-analyzer is broken for bindings #139

@peterhuene

Description

@peterhuene

Repro steps

  1. cargo component new repro
  2. cd repro
  3. Run VS Code with rust-analyzer enabled and open src/main.rs.

rust-analyzer should trigger a check command that will generate a target/bindings/repro/target.wasm file containing the current target world for the project; the target is empty for command projects by default, so the generated bindings mod will be empty.

  1. Create a wit directory.
  2. Add a test.wit file with the following contents:
package repro:test

world repro {
    import test: func()
}
  1. In VS Code, manually save src/main.rs to trigger a reparse.
  2. In the main function in src/main.rs, type bindings::.

Expected results

rust-analyzer should offer autocomplete suggestions for the imported function.

Actual results

Nothing happens.

Remarks

Right now, the cargo_component_bindings::generate! macro reads the target wasm file (which is very small and only contains type information) to generate bindings and emits a include_bytes! with the hopes that a dependency on the file will trigger a rebuild if it changes.

However, it appears that rust-analyzer doesn't respect changes to the file to reparse; it continues to use a cached evaluation of the proc-macro.

This may be related to rust-lang/rust-analyzer#13668, but I can't say for sure.

Workarounds

Restarting the rust-analyzer server after modifying the WIT files forces the re-evaluation of the macro with the latest bindings information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions