Android 中對 Rust 的 IDE 支持依賴於rust-analyzer 。 rust-analyzer
是一種語言服務器協議,IDE 使用它來理解代碼結構並提供代碼完成或跳轉定義等功能。在開始之前,請搜索rust-analyzer 快速入門文檔,了解如何配置 IDE 或編輯器以使用rust-analyzer
協議。
Android 提供了使rust-analyzer
能夠了解 Android Rust 模塊是如何構建的配置。這在宋生成的文件rust-project.json
中有描述。對於某些 IDE,例如 Visual Studio Code,此文件由aidegen
生成,使用-lr
選項參數(選擇 Rust 作為語言)。如果您使用不同的 IDE,請使用以下代碼手動生成rust-project.json
文件:
// Generates rust-project.json in out/soong/
SOONG_GEN_RUST_PROJECT=1 m nothing
// Creates a symbolic link
ln -s $ANDROID_BUILD_TOP/out/soong/rust-project.json $ANDROID_BUILD_TOP
prebuilts/rust/linux-x86/stable/rust-analyzer在樹中提供了一個預構建的穩定版本的rust-analyzer
-analyzer。