Skip to contentSkip to conversation

rust: rust-analyzer: add proc_macro for macros crate

PATCH In review Fiona Behrens 2 participants 2 messages Dec 5, 2024 – Jan 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: rust-analyzer: add proc_macro for macros crate

Add the proc_macro crate from the rust sysroot to the rust-project.json file used by rust-analyzer. This allows rust-analyzer to autocomplete items from the proc_macro crate inside the macros crate.

This also adds std and alloc only to be used by proc_macro and macros. This does not add the dependencies of those crates as this is sufficent for rust-analyzer to have a basic autocompletion support without having to worry about all the dependencies std usually needs. alloc is added, as e.g. std::vec just reexports from alloc, so that macros can use autocompletion for Vec and similar.

---
 scripts/generate_rust_analyzer.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
scripts/generate_rust_analyzer.py +25 -1
index 09e1d166d8d2..747b5ed6c857 100755
@@ -64,10 +64,34 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
         [],
     )
 
+    # alloc only for std/proc_macros/macros
+    append_crate(
+        "alloc",
+        sysroot_src / "alloc" / "src" / "lib.rs",
+        ["core"],
+        is_workspace_member=False,
+    )
+
+    # std only for proc_macros/macros
+    append_crate(
+        "std",
+        sysroot_src / "std" / "src" / "lib.rs",
+        ["core", "alloc"],
+        is_workspace_member=False,
+    )
+
+    # proc_macro for macros crate
+    append_crate(
+        "proc_macro",
+        sysroot_src / "proc_macro" / "src" / "lib.rs",
+        ["std", "core"],
+        is_workspace_member=False,
+    )
+
     append_crate(
         "macros",
         srctree / "rust" / "macros" / "lib.rs",
-        [],
+        ["std", "proc_macro"],
         is_proc_macro=True,
     )
     crates[-1]["proc_macro_dylib_path"] = f"{objtree}/rust/libmacros.so"
Signature · 1 line
2.47.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Fiona Behrens

Add the proc_macro crate from the rust sysroot to the rust-project.json file used by rust-analyzer. This allows rust-analyzer to autocomplete items from the proc_macro crate inside the macros crate.

Quoted 6 lines

This also adds std and alloc only to be used by proc_macro and macros. This does not add the dependencies of those crates as this is sufficent for rust-analyzer to have a basic autocompletion support without having to worry about all the dependencies std usually needs. alloc is added, as e.g. std::vec just reexports from alloc, so that macros can use autocompletion for Vec and similar.

If you say that's sufficient, then I believe you.

Quoted 1 line