rust-lang / rust-lang/rust-analyzer

I'm using a proc_macro, rust-analyzer makes cargo recompile every dependencies

Open
#17,482 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Similar to this case.

Rust-Analyzer runs a slow cargo check every time I save, which takes about half a minute to complete.

This prevents me from running cargo run/build, as the lock file is being used. Additionally, because I'm using some macros, it forces my project to recompile every crate I'm using, making my workflow a horrible experience. When I want to change a single character, I have to wait up to 2 minutes to see the changes. This is just a testing file and not even the project itself, which will be much larger and I cannot imagine how this issue will scale.

What can I do to workaround this, my current setup deactivates cargo check on save, removing some ""quality of life"" that I had on other projects, nevertheless, this is almost the only way to do something, that or removing the extension.

Note

I tried using rust_analyzer (Pre-Release) to fix the issue, but it didn't help. I also tried other relevant solutions, but they didn't change the behavior.

$ rustc -V
rustc 1.76.0 (07dca489a 2024-02-04)

VSCode's about:
Version: 1.90.2
Commit: 5437499feb04f7a586f677b155b039bc2b3669eb
Date: 2024-06-18T22:33:48.698Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Linux x64 6.8.9-zen1-2-zen
Rust Analyzer
Name: rust-analyzer
Id: rust-lang.rust-analyzer
Description: Rust language support for Visual Studio Code
Version: 0.3.2002
Publisher: The Rust Programming Language 
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer
My PC's specs
OS: Arch Linux x86_64
Host: B560M DS3H AC
Kernel: Linux 6.8.9-zen1-2-zen
Packages: 1603 (pacman), 34 (nix-user)
Shell: zsh 5.9
Display (S24D300): 1920x1080 @ 60Hz [External]
WM: Hyprland (Wayland)
CPU: Intel(R) Core(TM) i5-10400 (12) @ 4.30 GHz
GPU: NVIDIA Geforce RTX 3050 [Discrete]
Memory: 15.49 GiB

No environment variable for rust, but:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/lib

used for my gtk4 project.

Links to the libraries I'm using:

Code that I'm testing with:
use gtk::prelude::*;
use gtk4_layer_shell::{Edge, Layer, LayerShell}; // Import the additional types
use relm4::prelude::*;
use std::convert::identity;

struct NavBar;

#[relm4::component]
impl SimpleComponent for NavBar {
    type Init = ();
    type Input = ();
    type Output = ();

    view! {
        gtk::Window {
            init_layer_shell: (), // Do gtk4_layer_shell stuff here
            set_layer: Layer::Overlay,
            auto_exclusive_zone_enable: (),
            set_margin: (Edge::Left, 10),
            set_margin: (Edge::Right, 10),
            set_anchor: (Edge::Top, true),
            set_anchor: (Edge::Right, true),
            set_anchor: (Edge::Left, true),
            set_title: Some("Master-Bar"),
            set_default_size: (300, 100),

            gtk::Box {
                gtk::Label{
                    set_label: "Hello navbar here!!"
                }
            }
        }
    }

    // Initialize the component.
    fn init(
        _counter: Self::Init,
        root: Self::Root,
        _sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let model = NavBar;

        // Insert the code generation of the view! macro here
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }
}
struct Main {
    navbar: Controller<NavBar>,
}
#[relm4::component]
impl SimpleComponent for Main {
    type Init = ();
    type Input = ();
    type Output = ();
    view! {
        gtk::Window{
            gtk::Label{
                set_label: "Hello"
            }
        }
    }
    fn init(
        init: Self::Init,
        root: Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let navbarx = NavBar::builder()
            .launch(())
            .forward(sender.input_sender(), identity);

        if let Some(window) = navbarx.widget().root() {
            window.show();
        }

        let model = Main { navbar: navbarx };
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }
}
fn main() {
    let app = RelmApp::new("relm4.example.simple");
    app.run::<Main>(());
}
Cargo Toml
[package]
name = "relm4-layer"
version = "0.1.0"
edition = "2021"

[dependencies]
gtk4-layer-shell = "0.3.0"
mpris = "2.0.1"
relm4 = "0.8.1"
relm4-components = "0.8.1"
tokio = { version = "1.38.0", features = ["full"] }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Rust reproduction and Cargo.toml, then observe rust-analyzer's cargo check on save while editing the proc_macro-using code. Compare rebuild behavior and lock-file contention before and after each change; done means saves no longer trigger unnecessary dependency recompilation or block cargo run/build.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.