Closed Bug 1890431 Opened 2 years ago Closed 1 year ago

rust-analyzer fails to resolve xpcom::interfaces::*

Categories

(Developer Infrastructure :: Developer Environment Integration, defect, P5)

defect

Tracking

(firefox136 fixed)

RESOLVED FIXED
136 Branch
Tracking Status
firefox136 --- fixed

People

(Reporter: saschanaz, Assigned: nrishel)

References

Details

(Whiteboard: [fidedi])

Attachments

(1 file)

Probably some include! macro related issue? Perhaps a rust-analyzer bug, but filing here until we figure it out as it affects Firefox dev experience.

For example, hovering mouse cursor on interface names on authrs_bridge/src/lib.rs shows nothing, and the interface names are rendered as plaintext color (white on my config) instead of struct name color (green on my config). (Edit: This affects searchfox too; clicking on interfaces only gives "Search for the substring ..." instead of "Go to definition". Thanks Andrew!)

Similar thing affects windows-rs crate where any modules include!-ed from build/rust/windows/src/lib.rs do not autocomplete.

(Tested on Windows 11)

It seems rust-analyzer fails to expand include! macro if the destination is outside of the crate directory. Tried playing with "Inline macro" feature in VSCode rust-analyzer within xpcom/rust/nserror/src/lib.rs, and it works for "lol.rs", "../lol.rs" but then stops working for "../../lol.rs"; it silently gives empty string. (lol.rs is a file I added to test this, with only a string literal "what" in it.)

Tried nightly toolchain and the behavior is still same.

The severity field is not set for this bug.
:ahochheiden, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(ahochheiden)

It seems like this is entirely a rust-analyzer issue, and there's nothing we can really do about this from a build system perspective.

I suppose keeping it open until it's resolved upstream is fine though, just for visibility.

Severity: -- → S4
Flags: needinfo?(ahochheiden)
Priority: -- → P5

Found a workaround for the time being.

  1. Replace mozilla-unified\build\rust\windows\src\lib.rs with .mozbuild\windows-rs\src\lib.rs
  2. In CMD (not mozilla build's MSYS or powershell) run mklink /d C:\[some path]\mozilla-unified\build\rust\windows\src\Windows C:\[some other path]\.mozbuild\windows-rs\src\Windows
  3. Restart rust-analyzer server if VS Code was running (or restart VS Code).

For commit convenience you can add ^build/rust/windows/src/Windows/.* to .hgignore and save these changes as a commit that can be removed from a patch's history as needed.

(That's windows-rs specific as it has very special situation, and not really applies for generated types like xpcom interfaces.)

Assignee: nobody → nrishel
Status: NEW → ASSIGNED
Whiteboard: [fidedi]
Pushed by nrishel@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2bb333fce0c2 Add configs for rust-analyzer includes that are not automatically detected - i.e. all code outside of the source root and crate-specific `OUT_DIR`s. r=glandium
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 136 Branch
Component: General → Developer Environment Integration
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: