Re: [PATCH v3] scripts: generate_rust_analyzer.py: add missing macros deps
From: Tamir Duberstein
Date: Fri Mar 07 2025 - 06:06:18 EST
On Fri, Mar 7, 2025 at 5:57 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> "Tamir Duberstein" <tamird@xxxxxxxxx> writes:
>
> > The macros crate has depended on std and proc_macro since its
> > introduction in commit 1fbde52bde73 ("rust: add `macros` crate"). These
> > dependencies were omitted from commit 8c4555ccc55c ("scripts: add
> > `generate_rust_analyzer.py`") resulting in missing go-to-definition and
> > autocomplete, and false-positive warnings emitted from rust-analyzer
> > such as:
> >
> > [{
> > "resource": "/Users/tamird/src/linux/rust/macros/module.rs",
> > "owner": "_generated_diagnostic_collection_name_#1",
> > "code": {
> > "value": "non_snake_case",
> > "target": {
> > "$mid": 1,
> > "path": "/rustc/",
> > "scheme": "https",
> > "authority": "doc.rust-lang.org",
> > "query": "search=non_snake_case"
> > }
> > },
> > "severity": 4,
> > "message": "Variable `None` should have snake_case name, e.g. `none`",
> > "source": "rust-analyzer",
> > "startLineNumber": 123,
> > "startColumn": 17,
> > "endLineNumber": 123,
> > "endColumn": 21
> > }]
> >
> > Add the missing dependencies to improve the developer experience.
> >
> > Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
> > Reviewed-by: Fiona Behrens <me@xxxxxxxxxx>
> > Suggested-by: Chayim Refael Friedman <chayimfr@xxxxxxxxx>
> > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
> > ---
> > Changes in v3:
> > - Avoid shuffling compilter_builtins; it is not needed for RA support.
> > - Align more closely with the long-term solution:
> > https://lore.kernel.org/all/20250209-rust-analyzer-host-v1-0-a2286a2a2fa3@xxxxxxxxx/.
> > - Link to v2: https://lore.kernel.org/r/20250209-rust-analyzer-macros-core-dep-v2-1-897338344d16@xxxxxxxxx
> >
> > Changes in v2:
> > - Change macros deps from [core] to [std, proc_macro], improving
> > autocomplete and go-to-definition.
> > - Remove Wedson Almeida Filho <wedsonaf@xxxxxxxxxx> from cc; email
> > bounced.
> > - Link to v1: https://lore.kernel.org/r/20250209-rust-analyzer-macros-core-dep-v1-1-5ebeb3eb60a9@xxxxxxxxx
> > ---
> > scripts/generate_rust_analyzer.py | 30 +++++++++++++++++++++---------
> > 1 file changed, 21 insertions(+), 9 deletions(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index aa8ea1a4dbe5..1394baa5ee9e 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -57,14 +57,26 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> > crates_indexes[display_name] = len(crates)
> > crates.append(crate)
> >
> > - # First, the ones in `rust/` since they are a bit special.
> > - append_crate(
> > - "core",
> > - sysroot_src / "core" / "src" / "lib.rs",
> > - [],
> > - cfg=crates_cfgs.get("core", []),
> > - is_workspace_member=False,
> > - )
> > + def append_sysroot_crate(
> > + display_name,
> > + deps,
> > + cfg=[],
> > + ):
> > + return append_crate(
>
> Why the `return` here?
It's in anticipation of this follow up patch
https://lore.kernel.org/all/20250209-rust-analyzer-host-v1-2-a2286a2a2fa3@xxxxxxxxx/
where the return value is used to identify the crate. I developed the
two in parallel so I added this return to reduce overall churn.
> Otherwise looks good to me.
>
> I never had any errors as described above, but I can confirm that go to
> definition in `macros` for items in `proc_macro` work with this patch
> applied. It does not work prior to applying the patch.
>
>
> Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
Thanks!