Skip to content

Commit

Permalink
Add a hacky shell for fun code reading (#17503)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun authored May 26, 2021
1 parent 3d40ec3 commit 7ce910f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/sed-i-all-rs-files-for-rust-analyzer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

# rust-analyzer doesn't support hiding noisy test calls in the call hierarchy from tests/benches
# so, here's some wild hack from ryoqun!

if [[ $1 = "doit" ]]; then
# it's true that we put true just for truely-aligned lines
# shellcheck disable=SC2046 # our rust files are sanely named with no need to escape
true &&
sed -i -e 's/#\[cfg(test)\]/#[cfg(escaped-cfg-test)]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[bench\]/#[cfg(escaped-bench)]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[test\]/#[cfg(escaped-test)]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[tokio::test\]/#[cfg(escaped-tokio-test)]/g' $(git ls-files :**.rs :^**/build.rs)
elif [[ $1 = "undoit" ]]; then
# shellcheck disable=SC2046 # our rust files are sanely named with no need to escape
true &&
sed -i -e 's/#\[cfg(escaped-cfg-test)\]/#[cfg(test)]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[cfg(escaped-bench)\]/#[bench]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[cfg(escaped-test)\]/#[test]/g' $(git ls-files :**.rs :^**/build.rs) &&
sed -i -e 's/#\[cfg(escaped-tokio-test)\]/#[tokio::test]/g' $(git ls-files :**.rs :^**/build.rs)
else
echo "usage: $0 [doit|undoit]" > /dev/stderr
exit 1
fi

0 comments on commit 7ce910f

Please sign in to comment.