trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Changing CARGO_TARGET_DIR prevents file changes from being debounced

Open MasonMcGill opened this issue 2 years ago • 0 comments

I have the following directory structure:

artifacts/
  web-demo/
    dist/
    target/
  ...
web-demo/
  src/
    main.rs
  Cargo.lock
  Cargo.toml
...

with the intention being to separate source code that gets copied into Docker containers, committed to Git, etc. from files generated by running scripts or build commands (the latter all go in the artifacts directory).

I'm currently running Trunk using this script:

#!/bin/sh
mkdir -p artifacts/web-demo
export CARGO_TARGET_DIR=artifacts/web-demo/target
trunk serve web-demo/index.html --dist artifacts/web-demo/dist --watch web-demo

and when I change main.rs in VSCode the project rebuilds 10 times or so, with localhost:8080 furiously refreshing for a couple seconds. But when I change main.rs using Kate, a simpler text editor, I don't have this problem. My guess is that VSCode is translating a single save action into multiple file writes (running the formatter, maybe generating backup files?). With both editors, debouncing file change events works so long as I don't use a custom target directory.

MasonMcGill avatar Jul 05 '22 00:07 MasonMcGill