rust-analyzer now works with XPCOM, windows-rs, and other generated Rust code

41 views
Skip to first unread message

Nicholas Rishel

unread,
Jan 14, 2025, 5:09:19 PM1/14/25
to dev-pl...@mozilla.org, firef...@mozilla.org
TL;DR run mach ide vscode to get code completion, go-to definition, etc. for XPCOM, windows-rs, and other build generated Rust code.

What Changed
rust-analyzer previously did not recognize code outside of the source and cargo build directories as there was no mechanism for populating its VFS after construction, and include!()s and other source analysis didn't occur until after the VFS was populated. In our case this prevented rust-analyzer from recognizing XPCOM and Glean generated code which are located outside of crate build directories, and windows-rs which is downloaded separately from source.

With this PR rust-analyzer was extended with the config rust-analyzer.vfs.extraIncludes which allows explicitly extending the list of directories added to the VFS. With this revision support for the config was added for both the build and windows-rs directories with mach ide vscode.

Known Issues
Go-to definition for XPCOM interface names will navigate to the include!()ing file instead of the definition itself. All other content for the interface - i.e. constants, methods, and attributes - resolves correctly to the generated source. This is likely a result of our include!()s in include!()s layout.

Additionally navigating to very large generated files - notably those generated by Glean - can result in rust-analyzer running exponentially slower. Bug tracked here.

Happy Oxidizing!
Nicholas
Reply all
Reply to author
Forward
0 new messages