1
1
//! Loads a Cargo project into a static instance of analysis, without support
2
2
//! for incorporating changes.
3
- use std:: { path:: Path , sync:: Arc } ;
3
+ use std:: { convert :: identity , path:: Path , sync:: Arc } ;
4
4
5
5
use anyhow:: Result ;
6
6
use crossbeam_channel:: { unbounded, Receiver } ;
@@ -17,10 +17,17 @@ use crate::reload::{load_proc_macro, ProjectFolders, SourceRootConfig};
17
17
// what otherwise would be `pub(crate)` has to be `pub` here instead.
18
18
pub struct LoadCargoConfig {
19
19
pub load_out_dirs_from_check : bool ,
20
- pub with_proc_macro : bool ,
20
+ pub with_proc_macro_server : ProcMacroServerChoice ,
21
21
pub prefill_caches : bool ,
22
22
}
23
23
24
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
25
+ pub enum ProcMacroServerChoice {
26
+ Sysroot ,
27
+ Explicit ( AbsPathBuf , Vec < String > ) ,
28
+ None ,
29
+ }
30
+
24
31
// Note: Since this function is used by external tools that use rust-analyzer as a library
25
32
// what otherwise would be `pub(crate)` has to be `pub` here instead.
26
33
pub fn load_workspace_at (
@@ -59,15 +66,17 @@ pub fn load_workspace(
59
66
Box :: new ( loader)
60
67
} ;
61
68
62
- let proc_macro_client = if load_config. with_proc_macro {
63
- let ( server_path, args) : ( _ , & [ _ ] ) = match ws. find_sysroot_proc_macro_srv ( ) {
64
- Some ( server_path) => ( server_path, & [ ] ) ,
65
- None => ( AbsPathBuf :: assert ( std:: env:: current_exe ( ) ?) , & [ "proc-macro" ] ) ,
66
- } ;
67
-
68
- ProcMacroServer :: spawn ( server_path, args) . map_err ( |e| e. to_string ( ) )
69
- } else {
70
- Err ( "proc macro server disabled" . to_owned ( ) )
69
+ let proc_macro_client = match & load_config. with_proc_macro_server {
70
+ ProcMacroServerChoice :: Sysroot => ws
71
+ . find_sysroot_proc_macro_srv ( )
72
+ . ok_or_else ( || "failed to find sysroot proc-macro server" . to_owned ( ) )
73
+ . and_then ( |it| {
74
+ ProcMacroServer :: spawn ( it, identity :: < & [ & str ] > ( & [ ] ) ) . map_err ( |e| e. to_string ( ) )
75
+ } ) ,
76
+ ProcMacroServerChoice :: Explicit ( path, args) => {
77
+ ProcMacroServer :: spawn ( path. clone ( ) , args) . map_err ( |e| e. to_string ( ) )
78
+ }
79
+ ProcMacroServerChoice :: None => Err ( "proc macro server disabled" . to_owned ( ) ) ,
71
80
} ;
72
81
73
82
let crate_graph = ws. to_crate_graph (
@@ -157,7 +166,7 @@ mod tests {
157
166
let cargo_config = CargoConfig :: default ( ) ;
158
167
let load_cargo_config = LoadCargoConfig {
159
168
load_out_dirs_from_check : false ,
160
- with_proc_macro : false ,
169
+ with_proc_macro_server : ProcMacroServerChoice :: None ,
161
170
prefill_caches : false ,
162
171
} ;
163
172
let ( host, _vfs, _proc_macro) =
0 commit comments