rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

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

Open ARKye03 opened this issue 1 year ago • 1 comments
trafficstars

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"] }

ARKye03 avatar Jun 23 '24 16:06 ARKye03

I recommend using a different target directory for RA, that should solve all your lock file and incremental rebuild issues.

mqudsi avatar Jun 24 '24 17:06 mqudsi