Skip to content

Commit 4e93c7c

Browse files
committed
Auto merge of rust-lang#116643 - onur-ozkan:x-zsh-completion, r=Mark-Simulacrum
x.py zsh completion support self-explanatory ![image](https://github.com/rust-lang/rust/assets/39852038/81278f8b-3679-426b-b1c0-331b60593a1e)
2 parents dda7d4c + ae9c724 commit 4e93c7c

File tree

8 files changed

+809
-68
lines changed

8 files changed

+809
-68
lines changed

src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ dependencies = [
126126

127127
[[package]]
128128
name = "clap_complete"
129-
version = "4.2.2"
129+
version = "4.4.3"
130130
source = "registry+https://github.com/rust-lang/crates.io-index"
131-
checksum = "36774babb166352bb4f7b9cb16f781ffa3439d2a8f12cd31bea85a38c888fea3"
131+
checksum = "e3ae8ba90b9d8b007efe66e55e48fb936272f5ca00349b5b0e89877520d35ea7"
132132
dependencies = [
133133
"clap",
134134
]

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test = false
3636
build_helper = { path = "../tools/build_helper" }
3737
cc = "1.0.69"
3838
clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
39-
clap_complete = "4.2.2"
39+
clap_complete = "4.4.3"
4040
cmake = "0.1.38"
4141
filetime = "0.2"
4242
hex = "0.4"

src/bootstrap/run.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::path::PathBuf;
22
use std::process::Command;
33

4-
use clap_complete::shells;
5-
64
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
75
use crate::config::TargetSelection;
86
use crate::dist::distdir;
@@ -268,23 +266,29 @@ impl Step for GenerateWindowsSys {
268266
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
269267
pub struct GenerateCompletions;
270268

269+
macro_rules! generate_completions {
270+
( $( ( $shell:ident, $filename:expr ) ),* ) => {
271+
$(
272+
if let Some(comp) = get_completion($shell, &$filename) {
273+
std::fs::write(&$filename, comp).expect(&format!("writing {} completion", stringify!($shell)));
274+
}
275+
)*
276+
};
277+
}
278+
271279
impl Step for GenerateCompletions {
272280
type Output = ();
273281

274282
/// Uses `clap_complete` to generate shell completions.
275283
fn run(self, builder: &Builder<'_>) {
276-
// FIXME(clubby789): enable zsh when clap#4898 is fixed
277-
let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
278-
.map(|filename| builder.src.join("src/etc/completions").join(filename));
279-
if let Some(comp) = get_completion(shells::Bash, &bash) {
280-
std::fs::write(&bash, comp).expect("writing bash completion");
281-
}
282-
if let Some(comp) = get_completion(shells::Fish, &fish) {
283-
std::fs::write(&fish, comp).expect("writing fish completion");
284-
}
285-
if let Some(comp) = get_completion(shells::PowerShell, &powershell) {
286-
std::fs::write(&powershell, comp).expect("writing powershell completion");
287-
}
284+
use clap_complete::shells::{Bash, Fish, PowerShell, Zsh};
285+
286+
generate_completions!(
287+
(Bash, builder.src.join("src/etc/completions/x.py.sh")),
288+
(Zsh, builder.src.join("src/etc/completions/x.py.zsh")),
289+
(Fish, builder.src.join("src/etc/completions/x.py.fish")),
290+
(PowerShell, builder.src.join("src/etc/completions/x.py.ps1"))
291+
);
288292
}
289293

290294
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

src/bootstrap/test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1135,13 +1135,14 @@ help: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
11351135
builder.ensure(ExpandYamlAnchors);
11361136

11371137
builder.info("x.py completions check");
1138-
let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
1138+
let [bash, zsh, fish, powershell] = ["x.py.sh", "x.py.zsh", "x.py.fish", "x.py.ps1"]
11391139
.map(|filename| builder.src.join("src/etc/completions").join(filename));
11401140
if builder.config.cmd.bless() {
11411141
builder.ensure(crate::run::GenerateCompletions);
11421142
} else if crate::flags::get_completion(shells::Bash, &bash).is_some()
11431143
|| crate::flags::get_completion(shells::Fish, &fish).is_some()
11441144
|| crate::flags::get_completion(shells::PowerShell, &powershell).is_some()
1145+
|| crate::flags::get_completion(shells::Zsh, &zsh).is_some()
11451146
{
11461147
eprintln!(
11471148
"x.py completions were changed; run `x.py run generate-completions` to update them"

src/etc/completions/x.py.fish

+45-45
Large diffs are not rendered by default.

src/etc/completions/x.py.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
150150
break
151151
}
152152
'x.py;clippy' {
153-
[CompletionResult]::new('-A', 'A', [CompletionResultType]::ParameterName, 'clippy lints to allow')
154-
[CompletionResult]::new('-D', 'D', [CompletionResultType]::ParameterName, 'clippy lints to deny')
155-
[CompletionResult]::new('-W', 'W', [CompletionResultType]::ParameterName, 'clippy lints to warn on')
156-
[CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'clippy lints to forbid')
153+
[CompletionResult]::new('-A', 'A ', [CompletionResultType]::ParameterName, 'clippy lints to allow')
154+
[CompletionResult]::new('-D', 'D ', [CompletionResultType]::ParameterName, 'clippy lints to deny')
155+
[CompletionResult]::new('-W', 'W ', [CompletionResultType]::ParameterName, 'clippy lints to warn on')
156+
[CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'clippy lints to forbid')
157157
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
158158
[CompletionResult]::new('--build-dir', 'build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `config.toml`')
159159
[CompletionResult]::new('--build', 'build', [CompletionResultType]::ParameterName, 'build target of the stage0 compiler')

src/etc/completions/x.py.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1761,4 +1761,4 @@ _x.py() {
17611761
esac
17621762
}
17631763

1764-
complete -F _x.py -o bashdefault -o default x.py
1764+
complete -F _x.py -o nosort -o bashdefault -o default x.py

0 commit comments

Comments
 (0)