@@ -69,10 +69,16 @@ config_data! {
69
69
cargo_autoreload: bool = "true" ,
70
70
/// Run build scripts (`build.rs`) for more precise code analysis.
71
71
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\" " ,
72
79
/// 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.
76
82
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
77
83
/// is set.
78
84
cargo_buildScripts_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
@@ -129,10 +135,17 @@ config_data! {
129
135
///
130
136
/// Set to `"all"` to pass `--all-features` to Cargo.
131
137
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\" " ,
132
146
/// 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.
136
149
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
137
150
/// is set.
138
151
checkOnSave_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
@@ -1074,6 +1087,12 @@ impl Config {
1074
1087
InvocationStrategy :: Once => project_model:: InvocationStrategy :: Once ,
1075
1088
InvocationStrategy :: PerWorkspace => project_model:: InvocationStrategy :: PerWorkspace ,
1076
1089
} ,
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
+ } ,
1077
1096
run_build_script_command : self . data . cargo_buildScripts_overrideCommand . clone ( ) ,
1078
1097
extra_env : self . data . cargo_extraEnv . clone ( ) ,
1079
1098
}
@@ -1097,10 +1116,6 @@ impl Config {
1097
1116
if !self . data . checkOnSave_enable {
1098
1117
return None ;
1099
1118
}
1100
- let invocation_strategy = match self . data . checkOnSave_invocationStrategy {
1101
- InvocationStrategy :: Once => flycheck:: InvocationStrategy :: Once ,
1102
- InvocationStrategy :: PerWorkspace => flycheck:: InvocationStrategy :: PerWorkspace ,
1103
- } ;
1104
1119
let flycheck_config = match & self . data . checkOnSave_overrideCommand {
1105
1120
Some ( args) if !args. is_empty ( ) => {
1106
1121
let mut args = args. clone ( ) ;
@@ -1109,7 +1124,18 @@ impl Config {
1109
1124
command,
1110
1125
args,
1111
1126
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
+ } ,
1113
1139
}
1114
1140
}
1115
1141
Some ( _) | None => FlycheckConfig :: CargoCommand {
@@ -1139,7 +1165,6 @@ impl Config {
1139
1165
} ,
1140
1166
extra_args : self . data . checkOnSave_extraArgs . clone ( ) ,
1141
1167
extra_env : self . check_on_save_extra_env ( ) ,
1142
- invocation_strategy,
1143
1168
} ,
1144
1169
} ;
1145
1170
Some ( flycheck_config)
@@ -1618,6 +1643,13 @@ enum InvocationStrategy {
1618
1643
PerWorkspace ,
1619
1644
}
1620
1645
1646
+ #[ derive( Deserialize , Debug , Clone ) ]
1647
+ #[ serde( rename_all = "snake_case" ) ]
1648
+ enum InvocationLocation {
1649
+ Root ,
1650
+ Workspace ,
1651
+ }
1652
+
1621
1653
#[ derive( Deserialize , Debug , Clone ) ]
1622
1654
#[ serde( untagged) ]
1623
1655
enum LifetimeElisionDef {
@@ -2036,8 +2068,16 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
2036
2068
"type" : "string" ,
2037
2069
"enum" : [ "per_workspace" , "once" ] ,
2038
2070
"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."
2041
2081
] ,
2042
2082
} ,
2043
2083
_ => panic ! ( "missing entry for {}: {}" , ty, default ) ,
0 commit comments