rust: Nicer launch-rust-analyzer signature with #:share and #:expose

This commit is contained in:
Davie Li 2024-01-11 00:51:30 +01:00
parent b9a4a014f3
commit c5662606df
Signed by: davie
GPG key ID: 29FD88532FC91BF4

20
env/rust.scm vendored
View file

@ -148,9 +148,25 @@ function."
(exec-in-rustup-environment '("/bin/sh") #:home home))
(define* (launch-rust-analyzer env target-name
#:key (tag 'current) mappings)
#:key
(tag 'current) (share '()) (expose '()))
(define (remap w)
(let ((home (getenv "HOME")))
(λ (m)
(let loop ((m m))
(match m
((s t) (file-system-mapping (source s) (target t) (writable? w)))
(s (if (file-exists? s)
(if (string-prefix? home s)
(loop (list s (string-replace s "rustup"
6 (string-length home))))
(loop (list s s)))
(throw 'file-doesnt-exist))))))))
(let* ((target (string-append (@@ (env) %env-directory) "/" target-name))
(mnt (mount-environment env #:tag tag #:target target)))
(mnt (mount-environment env #:tag tag #:target target))
(mappings (append (map (remap #f) expose)
(map (remap #t) share))))
(exec-in-rustup-environment '("./.cargo/bin/rust-analyzer")
#:home (overlay-mount-merged mnt)
#:mappings mappings)