aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/src/bin/args.rs23
-rw-r--r--xtask/Cargo.toml2
-rw-r--r--xtask/src/main.rs34
5 files changed, 40 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 901784bec..b06f32913 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1205,9 +1205,9 @@ dependencies = [
1205 1205
1206[[package]] 1206[[package]]
1207name = "pico-args" 1207name = "pico-args"
1208version = "0.3.4" 1208version = "0.4.0"
1209source = "registry+https://github.com/rust-lang/crates.io-index" 1209source = "registry+https://github.com/rust-lang/crates.io-index"
1210checksum = "28b9b4df73455c861d7cbf8be42f01d3b373ed7f02e378d55fa84eafc6f638b1" 1210checksum = "d70072c20945e1ab871c472a285fc772aefd4f5407723c206242f2c6f94595d6"
1211 1211
1212[[package]] 1212[[package]]
1213name = "pin-project-lite" 1213name = "pin-project-lite"
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 3cb45b030..268c00942 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -24,7 +24,7 @@ jod-thread = "0.1.0"
24log = "0.4.8" 24log = "0.4.8"
25lsp-types = { version = "0.86.0", features = ["proposed"] } 25lsp-types = { version = "0.86.0", features = ["proposed"] }
26parking_lot = "0.11.0" 26parking_lot = "0.11.0"
27pico-args = "0.3.1" 27pico-args = "0.4.0"
28oorandom = "11.1.2" 28oorandom = "11.1.2"
29rustc-hash = "1.1.0" 29rustc-hash = "1.1.0"
30serde = { version = "1.0.106", features = ["derive"] } 30serde = { version = "1.0.106", features = ["derive"] }
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index 0a471154e..7d917946e 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -109,7 +109,7 @@ impl Args {
109 let mut matches = Arguments::from_env(); 109 let mut matches = Arguments::from_env();
110 110
111 if matches.contains("--version") { 111 if matches.contains("--version") {
112 matches.finish()?; 112 finish_args(matches)?;
113 return Ok(Args { 113 return Ok(Args {
114 verbosity: Verbosity::Normal, 114 verbosity: Verbosity::Normal,
115 log_file: None, 115 log_file: None,
@@ -143,7 +143,7 @@ impl Args {
143 let subcommand = match matches.subcommand()? { 143 let subcommand = match matches.subcommand()? {
144 Some(it) => it, 144 Some(it) => it,
145 None => { 145 None => {
146 matches.finish()?; 146 finish_args(matches)?;
147 return Ok(Args { verbosity, log_file, command: Command::RunServer }); 147 return Ok(Args { verbosity, log_file, command: Command::RunServer });
148 } 148 }
149 }; 149 };
@@ -160,7 +160,7 @@ impl Args {
160 load_output_dirs: matches.contains("--load-output-dirs"), 160 load_output_dirs: matches.contains("--load-output-dirs"),
161 with_proc_macro: matches.contains("--with-proc-macro"), 161 with_proc_macro: matches.contains("--with-proc-macro"),
162 path: matches 162 path: matches
163 .free_from_str()? 163 .opt_free_from_str()?
164 .ok_or_else(|| format_err!("expected positional argument"))?, 164 .ok_or_else(|| format_err!("expected positional argument"))?,
165 }), 165 }),
166 "analysis-bench" => Command::Bench(BenchCmd { 166 "analysis-bench" => Command::Bench(BenchCmd {
@@ -187,21 +187,21 @@ impl Args {
187 load_output_dirs: matches.contains("--load-output-dirs"), 187 load_output_dirs: matches.contains("--load-output-dirs"),
188 with_proc_macro: matches.contains("--with-proc-macro"), 188 with_proc_macro: matches.contains("--with-proc-macro"),
189 path: matches 189 path: matches
190 .free_from_str()? 190 .opt_free_from_str()?
191 .ok_or_else(|| format_err!("expected positional argument"))?, 191 .ok_or_else(|| format_err!("expected positional argument"))?,
192 }), 192 }),
193 "diagnostics" => Command::Diagnostics { 193 "diagnostics" => Command::Diagnostics {
194 load_output_dirs: matches.contains("--load-output-dirs"), 194 load_output_dirs: matches.contains("--load-output-dirs"),
195 with_proc_macro: matches.contains("--with-proc-macro"), 195 with_proc_macro: matches.contains("--with-proc-macro"),
196 path: matches 196 path: matches
197 .free_from_str()? 197 .opt_free_from_str()?
198 .ok_or_else(|| format_err!("expected positional argument"))?, 198 .ok_or_else(|| format_err!("expected positional argument"))?,
199 }, 199 },
200 "proc-macro" => Command::ProcMacro, 200 "proc-macro" => Command::ProcMacro,
201 "ssr" => Command::Ssr { 201 "ssr" => Command::Ssr {
202 rules: { 202 rules: {
203 let mut acc = Vec::new(); 203 let mut acc = Vec::new();
204 while let Some(rule) = matches.free_from_str()? { 204 while let Some(rule) = matches.opt_free_from_str()? {
205 acc.push(rule); 205 acc.push(rule);
206 } 206 }
207 acc 207 acc
@@ -211,7 +211,7 @@ impl Args {
211 debug_snippet: matches.opt_value_from_str("--debug")?, 211 debug_snippet: matches.opt_value_from_str("--debug")?,
212 patterns: { 212 patterns: {
213 let mut acc = Vec::new(); 213 let mut acc = Vec::new();
214 while let Some(rule) = matches.free_from_str()? { 214 while let Some(rule) = matches.opt_free_from_str()? {
215 acc.push(rule); 215 acc.push(rule);
216 } 216 }
217 acc 217 acc
@@ -222,7 +222,14 @@ impl Args {
222 return Ok(Args { verbosity, log_file: None, command: Command::Help }); 222 return Ok(Args { verbosity, log_file: None, command: Command::Help });
223 } 223 }
224 }; 224 };
225 matches.finish()?; 225 finish_args(matches)?;
226 Ok(Args { verbosity, log_file, command }) 226 Ok(Args { verbosity, log_file, command })
227 } 227 }
228} 228}
229
230fn finish_args(args: Arguments) -> Result<()> {
231 if !args.finish().is_empty() {
232 bail!("Unused arguments.");
233 }
234 Ok(())
235}
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 4abc7b053..4e6b439fd 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
12[dependencies] 12[dependencies]
13anyhow = "1.0.26" 13anyhow = "1.0.26"
14flate2 = "1.0" 14flate2 = "1.0"
15pico-args = "0.3.1" 15pico-args = "0.4.0"
16proc-macro2 = "1.0.8" 16proc-macro2 = "1.0.8"
17quote = "1.0.2" 17quote = "1.0.2"
18ungrammar = "1.9" 18ungrammar = "1.9"
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index c3e5c7326..5a99f4a76 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -10,6 +10,7 @@
10 10
11use std::env; 11use std::env;
12 12
13use anyhow::bail;
13use codegen::CodegenCmd; 14use codegen::CodegenCmd;
14use pico_args::Arguments; 15use pico_args::Arguments;
15use xshell::{cmd, cp, pushd}; 16use xshell::{cmd, cp, pushd};
@@ -76,7 +77,7 @@ FLAGS:
76 77
77 let client_opt = args.opt_value_from_str("--client")?; 78 let client_opt = args.opt_value_from_str("--client")?;
78 79
79 args.finish()?; 80 finish_args(args)?;
80 81
81 InstallCmd { 82 InstallCmd {
82 client: if server { None } else { Some(client_opt.unwrap_or_default()) }, 83 client: if server { None } else { Some(client_opt.unwrap_or_default()) },
@@ -86,53 +87,53 @@ FLAGS:
86 } 87 }
87 "codegen" => { 88 "codegen" => {
88 let features = args.contains("--features"); 89 let features = args.contains("--features");
89 args.finish()?; 90 finish_args(args)?;
90 CodegenCmd { features }.run() 91 CodegenCmd { features }.run()
91 } 92 }
92 "format" => { 93 "format" => {
93 args.finish()?; 94 finish_args(args)?;
94 run_rustfmt(Mode::Overwrite) 95 run_rustfmt(Mode::Overwrite)
95 } 96 }
96 "install-pre-commit-hook" => { 97 "install-pre-commit-hook" => {
97 args.finish()?; 98 finish_args(args)?;
98 pre_commit::install_hook() 99 pre_commit::install_hook()
99 } 100 }
100 "lint" => { 101 "lint" => {
101 args.finish()?; 102 finish_args(args)?;
102 run_clippy() 103 run_clippy()
103 } 104 }
104 "fuzz-tests" => { 105 "fuzz-tests" => {
105 args.finish()?; 106 finish_args(args)?;
106 run_fuzzer() 107 run_fuzzer()
107 } 108 }
108 "pre-cache" => { 109 "pre-cache" => {
109 args.finish()?; 110 finish_args(args)?;
110 PreCacheCmd.run() 111 PreCacheCmd.run()
111 } 112 }
112 "release" => { 113 "release" => {
113 let dry_run = args.contains("--dry-run"); 114 let dry_run = args.contains("--dry-run");
114 args.finish()?; 115 finish_args(args)?;
115 ReleaseCmd { dry_run }.run() 116 ReleaseCmd { dry_run }.run()
116 } 117 }
117 "promote" => { 118 "promote" => {
118 let dry_run = args.contains("--dry-run"); 119 let dry_run = args.contains("--dry-run");
119 args.finish()?; 120 finish_args(args)?;
120 PromoteCmd { dry_run }.run() 121 PromoteCmd { dry_run }.run()
121 } 122 }
122 "dist" => { 123 "dist" => {
123 let nightly = args.contains("--nightly"); 124 let nightly = args.contains("--nightly");
124 let client_version: Option<String> = args.opt_value_from_str("--client")?; 125 let client_version: Option<String> = args.opt_value_from_str("--client")?;
125 args.finish()?; 126 finish_args(args)?;
126 DistCmd { nightly, client_version }.run() 127 DistCmd { nightly, client_version }.run()
127 } 128 }
128 "metrics" => { 129 "metrics" => {
129 let dry_run = args.contains("--dry-run"); 130 let dry_run = args.contains("--dry-run");
130 args.finish()?; 131 finish_args(args)?;
131 MetricsCmd { dry_run }.run() 132 MetricsCmd { dry_run }.run()
132 } 133 }
133 "bb" => { 134 "bb" => {
134 let suffix: String = args.free_from_str()?.unwrap(); 135 let suffix: String = args.free_from_str()?;
135 args.finish()?; 136 finish_args(args)?;
136 cmd!("cargo build --release").run()?; 137 cmd!("cargo build --release").run()?;
137 cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?; 138 cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?;
138 Ok(()) 139 Ok(())
@@ -161,3 +162,10 @@ SUBCOMMANDS:
161 } 162 }
162 } 163 }
163} 164}
165
166fn finish_args(args: Arguments) -> Result<()> {
167 if !args.finish().is_empty() {
168 bail!("Unused arguments.");
169 }
170 Ok(())
171}