@@ -69,10 +69,16 @@ config_data! {
6969 cargo_autoreload: bool = "true" ,
7070 /// Run build scripts (`build.rs`) for more precise code analysis.
7171 cargo_buildScripts_enable: bool = "true" ,
72+ /// Specifies the working directory for running build scripts.
73+ /// - "workspace": run build scripts for a workspace in the workspace's root directory.
74+ /// This is incompatible with `#rust-analyzer.cargo.buildScripts.invocationStrategy#` set to `once`.
75+ /// - "root": run build scripts in the project's root directory.
76+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
77+ /// is set.
78+ cargo_buildScripts_invocationLocation: InvocationLocation = "\" workspace\" " ,
7279 /// Specifies the invocation strategy to use when running the build scripts command.
73- /// If `per_workspace` is set, the command will be executed for each workspace from the
74- /// corresponding workspace root.
75- /// If `once` is set, the command will be executed once in the project root.
80+ /// If `per_workspace` is set, the command will be executed for each workspace.
81+ /// If `once` is set, the command will be executed once.
7682 /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
7783 /// is set.
7884 cargo_buildScripts_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
@@ -129,10 +135,17 @@ config_data! {
129135 ///
130136 /// Set to `"all"` to pass `--all-features` to Cargo.
131137 checkOnSave_features: Option <CargoFeaturesDef > = "null" ,
138+ /// Specifies the working directory for running checks.
139+ /// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
140+ // FIXME: Ideally we would support this in some way
141+ /// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
142+ /// - "root": run checks in the project's root directory.
143+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
144+ /// is set.
145+ checkOnSave_invocationLocation: InvocationLocation = "\" workspace\" " ,
132146 /// Specifies the invocation strategy to use when running the checkOnSave command.
133- /// If `per_workspace` is set, the command will be executed for each workspace from the
134- /// corresponding workspace root.
135- /// If `once` is set, the command will be executed once in the project root.
147+ /// If `per_workspace` is set, the command will be executed for each workspace.
148+ /// If `once` is set, the command will be executed once.
136149 /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
137150 /// is set.
138151 checkOnSave_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
@@ -1074,6 +1087,12 @@ impl Config {
10741087 InvocationStrategy :: Once => project_model:: InvocationStrategy :: Once ,
10751088 InvocationStrategy :: PerWorkspace => project_model:: InvocationStrategy :: PerWorkspace ,
10761089 } ,
1090+ invocation_location : match self . data . cargo_buildScripts_invocationLocation {
1091+ InvocationLocation :: Root => {
1092+ project_model:: InvocationLocation :: Root ( self . root_path . clone ( ) )
1093+ }
1094+ InvocationLocation :: Workspace => project_model:: InvocationLocation :: Workspace ,
1095+ } ,
10771096 run_build_script_command : self . data . cargo_buildScripts_overrideCommand . clone ( ) ,
10781097 extra_env : self . data . cargo_extraEnv . clone ( ) ,
10791098 }
@@ -1097,10 +1116,6 @@ impl Config {
10971116 if !self . data . checkOnSave_enable {
10981117 return None ;
10991118 }
1100- let invocation_strategy = match self . data . checkOnSave_invocationStrategy {
1101- InvocationStrategy :: Once => flycheck:: InvocationStrategy :: Once ,
1102- InvocationStrategy :: PerWorkspace => flycheck:: InvocationStrategy :: PerWorkspace ,
1103- } ;
11041119 let flycheck_config = match & self . data . checkOnSave_overrideCommand {
11051120 Some ( args) if !args. is_empty ( ) => {
11061121 let mut args = args. clone ( ) ;
@@ -1109,7 +1124,18 @@ impl Config {
11091124 command,
11101125 args,
11111126 extra_env : self . check_on_save_extra_env ( ) ,
1112- invocation_strategy,
1127+ invocation_strategy : match self . data . checkOnSave_invocationStrategy {
1128+ InvocationStrategy :: Once => flycheck:: InvocationStrategy :: Once ,
1129+ InvocationStrategy :: PerWorkspace => {
1130+ flycheck:: InvocationStrategy :: PerWorkspace
1131+ }
1132+ } ,
1133+ invocation_location : match self . data . checkOnSave_invocationLocation {
1134+ InvocationLocation :: Root => {
1135+ flycheck:: InvocationLocation :: Root ( self . root_path . clone ( ) )
1136+ }
1137+ InvocationLocation :: Workspace => flycheck:: InvocationLocation :: Workspace ,
1138+ } ,
11131139 }
11141140 }
11151141 Some ( _) | None => FlycheckConfig :: CargoCommand {
@@ -1139,7 +1165,6 @@ impl Config {
11391165 } ,
11401166 extra_args : self . data . checkOnSave_extraArgs . clone ( ) ,
11411167 extra_env : self . check_on_save_extra_env ( ) ,
1142- invocation_strategy,
11431168 } ,
11441169 } ;
11451170 Some ( flycheck_config)
@@ -1618,6 +1643,13 @@ enum InvocationStrategy {
16181643 PerWorkspace ,
16191644}
16201645
1646+ #[ derive( Deserialize , Debug , Clone ) ]
1647+ #[ serde( rename_all = "snake_case" ) ]
1648+ enum InvocationLocation {
1649+ Root ,
1650+ Workspace ,
1651+ }
1652+
16211653#[ derive( Deserialize , Debug , Clone ) ]
16221654#[ serde( untagged) ]
16231655enum LifetimeElisionDef {
@@ -2036,8 +2068,16 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
20362068 "type" : "string" ,
20372069 "enum" : [ "per_workspace" , "once" ] ,
20382070 "enumDescriptions" : [
2039- "The command will be executed for each workspace from the corresponding workspace root." ,
2040- "The command will be executed once in the project root."
2071+ "The command will be executed for each workspace." ,
2072+ "The command will be executed once."
2073+ ] ,
2074+ } ,
2075+ "InvocationLocation" => set ! {
2076+ "type" : "string" ,
2077+ "enum" : [ "workspace" , "root" ] ,
2078+ "enumDescriptions" : [
2079+ "The command will be executed in the corresponding workspace root." ,
2080+ "The command will be executed in the project root."
20412081 ] ,
20422082 } ,
20432083 _ => panic ! ( "missing entry for {}: {}" , ty, default ) ,
0 commit comments