From 89a740be2d5487c96f01e4eaae7e280caf555019 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 6 Oct 2021 22:43:09 +0200 Subject: refactor(rust)!: merge `cargo` and `rustup` plugins into `rust` plugin (#10270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: `cargo` and `rustup` plugins have been moved to the `rust` plugin since they're part of the Rust toolchain. If you're using these, update your .zshrc file to use `rust` instead. Closes #10270 Co-authored-by: Marc Cornellà --- plugins/cargo/README.md | 10 +- plugins/cargo/cargo.plugin.zsh | 27 ++--- plugins/rust/README.md | 2 +- plugins/rust/_rust | 228 --------------------------------------- plugins/rust/_rustc | 228 +++++++++++++++++++++++++++++++++++++++ plugins/rust/rust.plugin.zsh | 28 +++++ plugins/rustup/README.md | 8 +- plugins/rustup/rustup.plugin.zsh | 27 ++--- 8 files changed, 273 insertions(+), 285 deletions(-) delete mode 100644 plugins/rust/_rust create mode 100644 plugins/rust/_rustc create mode 100644 plugins/rust/rust.plugin.zsh diff --git a/plugins/cargo/README.md b/plugins/cargo/README.md index 31bae4efe..93e69ae7f 100644 --- a/plugins/cargo/README.md +++ b/plugins/cargo/README.md @@ -1,11 +1,3 @@ # cargo -This plugin adds completion for the Rust build tool [`Cargo`](https://github.com/rust-lang/cargo). - -To use it, add `cargo` to the plugins array in your zshrc file: - -```zsh -plugins=(... cargo) -``` - -Updated on March 3rd, 2019, from [Cargo 0.34.0](https://github.com/rust-lang/cargo/releases/tag/0.34.0). +**Deprecated: use the [`rust`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/rust) plugin instead.** diff --git a/plugins/cargo/cargo.plugin.zsh b/plugins/cargo/cargo.plugin.zsh index 9d1d23757..51a80d4f1 100644 --- a/plugins/cargo/cargo.plugin.zsh +++ b/plugins/cargo/cargo.plugin.zsh @@ -1,24 +1,11 @@ -if ! (( $+commands[rustup] && $+commands[cargo] )); then - return -fi +print ${(%):-'%F{yellow}The `cargo` plugin is deprecated and has been moved to the `rust` plugin.'} +print ${(%):-'Please update your .zshrc to use the `%Brust%b` plugin instead.%f'} # Remove old generated completion file -# TODO: 2021-09-15: remove this line +# TODO: 2021-12-28: remove this line command rm -f "${0:A:h}/_cargo" -# Add completions/ folder in $ZSH_CACHE_DIR -comp_file="$ZSH_CACHE_DIR/completions/_cargo" -command mkdir -p "${comp_file:h}" -(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath) - -# If the completion file doesn't exist yet, we need to autoload it and -# bind it to `cargo`. Otherwise, compinit will have already done that -if [[ ! -f "$comp_file" ]]; then - autoload -Uz _cargo - declare -A _comps - _comps[cargo]=_cargo -fi - -# Generate completion file in the background -rustup completions zsh cargo >| "$comp_file" &| -unset comp_file +(( ${fpath[(Ie)$ZSH/plugins/rust]} )) || { + fpath=("$ZSH/plugins/rust" $fpath) + source "$ZSH/plugins/rust/rust.plugin.zsh" +} diff --git a/plugins/rust/README.md b/plugins/rust/README.md index 83d7d91ba..e05364474 100644 --- a/plugins/rust/README.md +++ b/plugins/rust/README.md @@ -1,6 +1,6 @@ # rust -This plugin adds completion for [`rustc`](https://doc.rust-lang.org/rustc/index.html), the compiler for the Rust programming language. +This plugin adds completion for [`rustc`](https://doc.rust-lang.org/rustc/index.html), the compiler for the Rust programming language, as well as for `rustup` and `cargo` if you have the Rust toolchain installed. To use it, add `rust` to the plugins array in your zshrc file: diff --git a/plugins/rust/_rust b/plugins/rust/_rust deleted file mode 100644 index 6e3f344cd..000000000 --- a/plugins/rust/_rust +++ /dev/null @@ -1,228 +0,0 @@ -#compdef rustc - -local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug - -typeset -A opt_args - -_rustc_debuginfo_levels=( - "0[no debug info]" - "1[line-tables only (for stacktraces and breakpoints)]" - "2[full debug info with variable and type information (same as -g)]" -) - -_rustc_crate_types=( - 'bin' - 'lib' - 'rlib' - 'dylib' - 'cdylib' - 'staticlib' - 'proc-macro' -) - -_rustc_emit_types=( - 'asm' - 'llvm-bc' - 'llvm-ir' - 'obj' - 'metadata' - 'link' - 'dep-info' - 'mir' -) -_rustc_print_types=( - 'crate-name' - 'file-names' - 'sysroot' - 'cfg' - 'target-list' - 'target-cpus' - 'target-features' - 'relocation-models' - 'code-models' - 'target-spec-json' - 'native-static-libs' -) -_rustc_pretty_types=( - 'normal[un-annotated source]' - 'expanded[crates expanded]' - 'expanded,identified[fully parenthesized, AST nodes with IDs]' -) -_rustc_unpretty_types=( - 'normal[un-annotated source]' - 'expanded[crates expanded]' - 'expanded,identified[fully parenthesized, AST nodes with IDs]' - 'flowgraph=[graphviz formatted flowgraph for node]:NODEID:' - 'everybody_loops[all function bodies replaced with `loop {}`]' - 'hir[the HIR]' - 'hir,identified' - 'hir,typed[HIR with types for each node]' -) -_rustc_color_types=( - 'auto[colorize, if output goes to a tty (default)]' - 'always[always colorize output]' - 'never[never colorize output]' -) -_rustc_error_format=( - 'human' - 'json' -) - -_rustc_opts_vals=( - --cfg='[Configure the compilation environment]:SPEC:' - -L'[Add a directory to the library search path]:DIR:_files -/' - --crate-name='[Specify the name of the crate being built]' - --crate-type='[Comma separated list of types of crates for the compiler to emit]:TYPES:_values -s "," "Crate types" "$_rustc_crate_types[@]"' - --emit='[Comma separated list of types of output for the compiler to emit]:TYPES:_values -s "," "Emit Targets" "$_rustc_emit_types[@]"' - --print='[Comma separated list of compiler information to print on stdout]:TYPES:_values -s "," "Printable info" "$_rustc_print_types[@]"' - -o'[Write output to . Ignored if more than one --emit is specified.]:FILENAME:_files' - --out-dir='[Write output to compiler-chosen filename in . Ignored if -o is specified. (default the current directory)]:DIR:_files -/' - --explain='[Provide a detailed explanation of an error message]:OPT:' - --target='[Target triple cpu-manufacturer-kernel\[-os\] to compile]:TRIPLE:' - --extern'[Specify where an external rust library is located]:ARG:' - --sysroot='[Override the system root]:PATH:_files -/' - --error-format='[How errors and other messages are produced]:TYPES:_values "$_rustc_error_format"' - --debuginfo='[Emit DWARF debug info to the objects created]:LEVEL:_values "Debug Levels" "$_rustc_debuginfo_levels[@]"' - --dep-info='[Output dependency info to after compiling]::FILE:_files -/' - --opt-level='[Optimize with possible levels 0-3]:LEVEL:(0 1 2 3)' - --pretty='[Pretty-print the input instead of compiling]::TYPE:_values "TYPES" "$_rustc_pretty_types[@]"' - --unpretty='[Present the input source, unstable (and less-pretty)]::TYPE:_values "TYPES" "$_rustc_unpretty_types[@]"' - --color='[Configure coloring of output]:CONF:_values "COLORS" "$_rustc_color_types[@]"' -) - -_rustc_opts_switches=( - -g'[Equivalent to --debuginfo=2]' - -O'[Equivalent to --opt-level=2]' - --test'[Build a test harness]' - {-v,--verbose}'[Use verbose output]' - {-V,--version}'[Print version info and exit]' - {-h,--help}'[Display this message]' - --no-analysis'[Parse and expand the output, but run no analysis or produce output]' - --no-trans'[Run all passes except translation; no output]' - --parse-only'[Parse only; do not compile, assemble, or link]' - --print-crate-name'[Output the crate name and exit]' - --print-file-name'[Output the file(s) that would be written if compilation continued and exit]' -) -_rustc_opts_codegen=( - 'ar=[Path to the archive utility to use when assembling archives.]:BIN:_path_files' - 'linker=[Path to the linker utility to use when linking libraries, executables, and objects.]:BIN:_path_files' - 'link-args=[A space-separated list of extra arguments to pass to the linker when the linker is invoked.]:ARGS:' - 'target-cpu=[Selects a target processor. If the value is "help", then a list of available CPUs is printed.]:CPU:' - 'target-feature=[A space-separated list of features to enable or disable for the target. A preceding "+" enables a feature while a preceding "-" disables it. Available features can be discovered through target-cpu=help.]:FEATURE:' - 'passes=[A space-separated list of extra LLVM passes to run. A value of "list" will cause rustc to print all known passes and exit. The passes specified are appended at the end of the normal pass manager.]:LIST:' - 'llvm-args=[A space-separated list of arguments to pass through to LLVM.]:ARGS:' - 'save-temps[If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.]' - 'rpath[If specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.]' - 'no-prepopulate-passes[Suppresses pre-population of the LLVM pass manager that is run over the module.]' - 'no-vectorize-loops[Suppresses running the loop vectorization LLVM pass, regardless of optimization level.]' - 'no-vectorize-slp[Suppresses running the LLVM SLP vectorization pass, regardless of optimization level.]' - 'soft-float[Generates software floating point library calls instead of hardware instructions.]' - 'prefer-dynamic[Prefers dynamic linking to static linking.]' - "no-integrated-as[Force usage of an external assembler rather than LLVM's integrated one.]" - 'no-redzone[disable the use of the redzone]' - 'relocation-model=[The relocation model to use. (default: pic)]:MODEL:(pic static dynamic-no-pic)' - 'code-model=[choose the code model to use (llc -code-model for details)]:MODEL:' - 'metadata=[metadata to mangle symbol names with]:VAL:' - 'extra-filenames=[extra data to put in each output filename]:VAL:' - 'codegen-units=[divide crate into N units to optimize in parallel]:N:' - 'help[Show all codegen options]' -) - -_rustc_opts_lint=( - 'help[Show a list of all lints]' - 'experimental[detects use of #\[experimental\] items]' - 'heap-memory[use of any (Box type or @ type) heap memory]' - 'managed-heap-memory[use of managed (@ type) heap memory]' - 'missing-doc[detects missing documentation for public members]' - 'non-uppercase-statics[static constants should have uppercase identifiers]' - 'owned-heap-memory[use of owned (~ type) heap memory]' - 'unnecessary-qualification[detects unnecessarily qualified names]' - 'unsafe-block[usage of an `unsafe` block]' - 'unstable[detects use of #\[unstable\] items (incl. items with no stability attribute)]' - 'unused-result[unused result of an expression in a statement]' - 'variant-size-difference[detects enums with widely varying variant sizes]' - 'ctypes[proper use of libc types in foreign modules]' - 'dead-assignment[detect assignments that will never be read]' - 'dead-code[detect piece of code that will never be used]' - 'deprecated[detects use of #\[deprecated\] items]' - 'non-camel-case-types[types, variants and traits should have camel case names]' - 'non-snake-case[methods, functions, lifetime parameters and modules should have snake case names]' - 'path-statement[path statements with no effect]' - 'raw-pointer-deriving[uses of #\[deriving\] with raw pointers are rarely correct]' - 'type-limits[comparisons made useless by limits of the types involved]' - 'type-overflow[literal out of range for its type]' - 'unnecessary-allocation[detects unnecessary allocations that can be eliminated]' - 'unnecessary-parens[`if`, `match`, `while` and `return` do not need parentheses]' - 'unreachable-code[detects unreachable code]' - 'unrecognized-lint[unrecognized lint attribute]' - 'unsigned-negate[using an unary minus operator on unsigned type]' - 'unused-attribute[detects attributes that were not used by the compiler]' - 'unused-imports[imports that are never used]' - 'unused-must-use[unused result of a type flagged as #\[must_use\]]' - "unused-mut[detect mut variables which don't need to be mutable]" - 'unused-unsafe[unnecessary use of an `unsafe` block]' - 'unused-variable[detect variables which are not used in any way]' - 'visible-private-types[detect use of private types in exported type signatures]' - 'warnings[mass-change the level for lints which produce warnings]' - 'while-true[suggest using `loop { }` instead of `while true { }`]' - 'unknown-crate-type[unknown crate type found in #\[crate_type\] directive]' - 'unknown-features[unknown features found in crate-level #\[feature\] directives]' - 'bad-style[group of non_camel_case_types, non_snake_case, non_uppercase_statics]' - 'unused[group of unused_imports, unused_variable, dead_assignment, dead_code, unused_mut, unreachable_code]' -) - -_rustc_opts_debug=( - 'verbose[in general, enable more debug printouts]' - 'span-free-formats[when debug-printing compiler state, do not include spans]' - "identify-regions[make unnamed regions display as '# (where # is some non-ident unique id)]" - 'emit-end-regions[emit EndRegion as part of MIR; enable transforms that solely process EndRegion]' - 'time-passes[measure time of each rustc pass]' - 'count-llvm-insns[count where LLVM instrs originate]' - 'time-llvm-passes[measure time of each LLVM pass]' - 'trans-stats[gather trans statistics]' - 'asm-comments[generate comments into the assembly (may change behavior)]' - 'no-verify[skip LLVM verification]' - 'borrowck-stats[gather borrowck statistics]' - 'no-landing-pads[omit landing pads for unwinding]' - 'debug-llvm[enable debug output from LLVM]' - 'show-span[show spans for compiler debugging]' - 'count-type-sizes[count the sizes of aggregate types]' - 'meta-stats[gather metadata statistics]' - 'no-opt[do not optimize, even if -O is passed]' - 'print-link-args[Print the arguments passed to the linker]' - 'gc[Garbage collect shared data (experimental)]' - 'print-llvm-passes[Prints the llvm optimization passes being run]' - 'lto[Perform LLVM link-time optimizations]' - 'ast-json[Print the AST as JSON and halt]' - 'ast-json-noexpand[Print the pre-expansion AST as JSON and halt]' - 'ls[List the symbols defined by a library crate]' - 'save-analysis[Write syntax and type analysis information in addition to normal output]' - 'flowgraph-print-loans[Include loan analysis data in --pretty flowgraph output]' - 'flowgraph-print-moves[Include move analysis data in --pretty flowgraph output]' - 'flowgraph-print-assigns[Include assignment analysis data in --pretty flowgraph output]' - 'flowgraph-print-all[Include all dataflow analysis data in --pretty flowgraph output]' -) - -_rustc_opts_fun_lint(){ - _values -s , 'options' \ - "$_rustc_opts_lint[@]" -} - -_rustc_opts_fun_debug(){ - _values 'options' "$_rustc_opts_debug[@]" -} - -_rustc_opts_fun_codegen(){ - _values 'options' "$_rustc_opts_codegen[@]" -} - -_arguments -s : \ - '(-W --warn)'{-W,--warn=}'[Set lint warnings]:lint options:_rustc_opts_fun_lint' \ - '(-A --allow)'{-A,--allow=}'[Set lint allowed]:lint options:_rustc_opts_fun_lint' \ - '(-D --deny)'{-D,--deny=}'[Set lint denied]:lint options:_rustc_opts_fun_lint' \ - '(-F --forbid)'{-F,--forbid=}'[Set lint forbidden]:lint options:_rustc_opts_fun_lint' \ - '*-Z[Set internal debugging options]:debug options:_rustc_opts_fun_debug' \ - '*-C[Set internal Codegen options]:codegen options:_rustc_opts_fun_codegen' \ - "$_rustc_opts_switches[@]" \ - "$_rustc_opts_vals[@]" \ - '::files:_files -g "*.rs"' diff --git a/plugins/rust/_rustc b/plugins/rust/_rustc new file mode 100644 index 000000000..6e3f344cd --- /dev/null +++ b/plugins/rust/_rustc @@ -0,0 +1,228 @@ +#compdef rustc + +local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug + +typeset -A opt_args + +_rustc_debuginfo_levels=( + "0[no debug info]" + "1[line-tables only (for stacktraces and breakpoints)]" + "2[full debug info with variable and type information (same as -g)]" +) + +_rustc_crate_types=( + 'bin' + 'lib' + 'rlib' + 'dylib' + 'cdylib' + 'staticlib' + 'proc-macro' +) + +_rustc_emit_types=( + 'asm' + 'llvm-bc' + 'llvm-ir' + 'obj' + 'metadata' + 'link' + 'dep-info' + 'mir' +) +_rustc_print_types=( + 'crate-name' + 'file-names' + 'sysroot' + 'cfg' + 'target-list' + 'target-cpus' + 'target-features' + 'relocation-models' + 'code-models' + 'target-spec-json' + 'native-static-libs' +) +_rustc_pretty_types=( + 'normal[un-annotated source]' + 'expanded[crates expanded]' + 'expanded,identified[fully parenthesized, AST nodes with IDs]' +) +_rustc_unpretty_types=( + 'normal[un-annotated source]' + 'expanded[crates expanded]' + 'expanded,identified[fully parenthesized, AST nodes with IDs]' + 'flowgraph=[graphviz formatted flowgraph for node]:NODEID:' + 'everybody_loops[all function bodies replaced with `loop {}`]' + 'hir[the HIR]' + 'hir,identified' + 'hir,typed[HIR with types for each node]' +) +_rustc_color_types=( + 'auto[colorize, if output goes to a tty (default)]' + 'always[always colorize output]' + 'never[never colorize output]' +) +_rustc_error_format=( + 'human' + 'json' +) + +_rustc_opts_vals=( + --cfg='[Configure the compilation environment]:SPEC:' + -L'[Add a directory to the library search path]:DIR:_files -/' + --crate-name='[Specify the name of the crate being built]' + --crate-type='[Comma separated list of types of crates for the compiler to emit]:TYPES:_values -s "," "Crate types" "$_rustc_crate_types[@]"' + --emit='[Comma separated list of types of output for the compiler to emit]:TYPES:_values -s "," "Emit Targets" "$_rustc_emit_types[@]"' + --print='[Comma separated list of compiler information to print on stdout]:TYPES:_values -s "," "Printable info" "$_rustc_print_types[@]"' + -o'[Write output to . Ignored if more than one --emit is specified.]:FILENAME:_files' + --out-dir='[Write output to compiler-chosen filename in . Ignored if -o is specified. (default the current directory)]:DIR:_files -/' + --explain='[Provide a detailed explanation of an error message]:OPT:' + --target='[Target triple cpu-manufacturer-kernel\[-os\] to compile]:TRIPLE:' + --extern'[Specify where an external rust library is located]:ARG:' + --sysroot='[Override the system root]:PATH:_files -/' + --error-format='[How errors and other messages are produced]:TYPES:_values "$_rustc_error_format"' + --debuginfo='[Emit DWARF debug info to the objects created]:LEVEL:_values "Debug Levels" "$_rustc_debuginfo_levels[@]"' + --dep-info='[Output dependency info to after compiling]::FILE:_files -/' + --opt-level='[Optimize with possible levels 0-3]:LEVEL:(0 1 2 3)' + --pretty='[Pretty-print the input instead of compiling]::TYPE:_values "TYPES" "$_rustc_pretty_types[@]"' + --unpretty='[Present the input source, unstable (and less-pretty)]::TYPE:_values "TYPES" "$_rustc_unpretty_types[@]"' + --color='[Configure coloring of output]:CONF:_values "COLORS" "$_rustc_color_types[@]"' +) + +_rustc_opts_switches=( + -g'[Equivalent to --debuginfo=2]' + -O'[Equivalent to --opt-level=2]' + --test'[Build a test harness]' + {-v,--verbose}'[Use verbose output]' + {-V,--version}'[Print version info and exit]' + {-h,--help}'[Display this message]' + --no-analysis'[Parse and expand the output, but run no analysis or produce output]' + --no-trans'[Run all passes except translation; no output]' + --parse-only'[Parse only; do not compile, assemble, or link]' + --print-crate-name'[Output the crate name and exit]' + --print-file-name'[Output the file(s) that would be written if compilation continued and exit]' +) +_rustc_opts_codegen=( + 'ar=[Path to the archive utility to use when assembling archives.]:BIN:_path_files' + 'linker=[Path to the linker utility to use when linking libraries, executables, and objects.]:BIN:_path_files' + 'link-args=[A space-separated list of extra arguments to pass to the linker when the linker is invoked.]:ARGS:' + 'target-cpu=[Selects a target processor. If the value is "help", then a list of available CPUs is printed.]:CPU:' + 'target-feature=[A space-separated list of features to enable or disable for the target. A preceding "+" enables a feature while a preceding "-" disables it. Available features can be discovered through target-cpu=help.]:FEATURE:' + 'passes=[A space-separated list of extra LLVM passes to run. A value of "list" will cause rustc to print all known passes and exit. The passes specified are appended at the end of the normal pass manager.]:LIST:' + 'llvm-args=[A space-separated list of arguments to pass through to LLVM.]:ARGS:' + 'save-temps[If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.]' + 'rpath[If specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.]' + 'no-prepopulate-passes[Suppresses pre-population of the LLVM pass manager that is run over the module.]' + 'no-vectorize-loops[Suppresses running the loop vectorization LLVM pass, regardless of optimization level.]' + 'no-vectorize-slp[Suppresses running the LLVM SLP vectorization pass, regardless of optimization level.]' + 'soft-float[Generates software floating point library calls instead of hardware instructions.]' + 'prefer-dynamic[Prefers dynamic linking to static linking.]' + "no-integrated-as[Force usage of an external assembler rather than LLVM's integrated one.]" + 'no-redzone[disable the use of the redzone]' + 'relocation-model=[The relocation model to use. (default: pic)]:MODEL:(pic static dynamic-no-pic)' + 'code-model=[choose the code model to use (llc -code-model for details)]:MODEL:' + 'metadata=[metadata to mangle symbol names with]:VAL:' + 'extra-filenames=[extra data to put in each output filename]:VAL:' + 'codegen-units=[divide crate into N units to optimize in parallel]:N:' + 'help[Show all codegen options]' +) + +_rustc_opts_lint=( + 'help[Show a list of all lints]' + 'experimental[detects use of #\[experimental\] items]' + 'heap-memory[use of any (Box type or @ type) heap memory]' + 'managed-heap-memory[use of managed (@ type) heap memory]' + 'missing-doc[detects missing documentation for public members]' + 'non-uppercase-statics[static constants should have uppercase identifiers]' + 'owned-heap-memory[use of owned (~ type) heap memory]' + 'unnecessary-qualification[detects unnecessarily qualified names]' + 'unsafe-block[usage of an `unsafe` block]' + 'unstable[detects use of #\[unstable\] items (incl. items with no stability attribute)]' + 'unused-result[unused result of an expression in a statement]' + 'variant-size-difference[detects enums with widely varying variant sizes]' + 'ctypes[proper use of libc types in foreign modules]' + 'dead-assignment[detect assignments that will never be read]' + 'dead-code[detect piece of code that will never be used]' + 'deprecated[detects use of #\[deprecated\] items]' + 'non-camel-case-types[types, variants and traits should have camel case names]' + 'non-snake-case[methods, functions, lifetime parameters and modules should have snake case names]' + 'path-statement[path statements with no effect]' + 'raw-pointer-deriving[uses of #\[deriving\] with raw pointers are rarely correct]' + 'type-limits[comparisons made useless by limits of the types involved]' + 'type-overflow[literal out of range for its type]' + 'unnecessary-allocation[detects unnecessary allocations that can be eliminated]' + 'unnecessary-parens[`if`, `match`, `while` and `return` do not need parentheses]' + 'unreachable-code[detects unreachable code]' + 'unrecognized-lint[unrecognized lint attribute]' + 'unsigned-negate[using an unary minus operator on unsigned type]' + 'unused-attribute[detects attributes that were not used by the compiler]' + 'unused-imports[imports that are never used]' + 'unused-must-use[unused result of a type flagged as #\[must_use\]]' + "unused-mut[detect mut variables which don't need to be mutable]" + 'unused-unsafe[unnecessary use of an `unsafe` block]' + 'unused-variable[detect variables which are not used in any way]' + 'visible-private-types[detect use of private types in exported type signatures]' + 'warnings[mass-change the level for lints which produce warnings]' + 'while-true[suggest using `loop { }` instead of `while true { }`]' + 'unknown-crate-type[unknown crate type found in #\[crate_type\] directive]' + 'unknown-features[unknown features found in crate-level #\[feature\] directives]' + 'bad-style[group of non_camel_case_types, non_snake_case, non_uppercase_statics]' + 'unused[group of unused_imports, unused_variable, dead_assignment, dead_code, unused_mut, unreachable_code]' +) + +_rustc_opts_debug=( + 'verbose[in general, enable more debug printouts]' + 'span-free-formats[when debug-printing compiler state, do not include spans]' + "identify-regions[make unnamed regions display as '# (where # is some non-ident unique id)]" + 'emit-end-regions[emit EndRegion as part of MIR; enable transforms that solely process EndRegion]' + 'time-passes[measure time of each rustc pass]' + 'count-llvm-insns[count where LLVM instrs originate]' + 'time-llvm-passes[measure time of each LLVM pass]' + 'trans-stats[gather trans statistics]' + 'asm-comments[generate comments into the assembly (may change behavior)]' + 'no-verify[skip LLVM verification]' + 'borrowck-stats[gather borrowck statistics]' + 'no-landing-pads[omit landing pads for unwinding]' + 'debug-llvm[enable debug output from LLVM]' + 'show-span[show spans for compiler debugging]' + 'count-type-sizes[count the sizes of aggregate types]' + 'meta-stats[gather metadata statistics]' + 'no-opt[do not optimize, even if -O is passed]' + 'print-link-args[Print the arguments passed to the linker]' + 'gc[Garbage collect shared data (experimental)]' + 'print-llvm-passes[Prints the llvm optimization passes being run]' + 'lto[Perform LLVM link-time optimizations]' + 'ast-json[Print the AST as JSON and halt]' + 'ast-json-noexpand[Print the pre-expansion AST as JSON and halt]' + 'ls[List the symbols defined by a library crate]' + 'save-analysis[Write syntax and type analysis information in addition to normal output]' + 'flowgraph-print-loans[Include loan analysis data in --pretty flowgraph output]' + 'flowgraph-print-moves[Include move analysis data in --pretty flowgraph output]' + 'flowgraph-print-assigns[Include assignment analysis data in --pretty flowgraph output]' + 'flowgraph-print-all[Include all dataflow analysis data in --pretty flowgraph output]' +) + +_rustc_opts_fun_lint(){ + _values -s , 'options' \ + "$_rustc_opts_lint[@]" +} + +_rustc_opts_fun_debug(){ + _values 'options' "$_rustc_opts_debug[@]" +} + +_rustc_opts_fun_codegen(){ + _values 'options' "$_rustc_opts_codegen[@]" +} + +_arguments -s : \ + '(-W --warn)'{-W,--warn=}'[Set lint warnings]:lint options:_rustc_opts_fun_lint' \ + '(-A --allow)'{-A,--allow=}'[Set lint allowed]:lint options:_rustc_opts_fun_lint' \ + '(-D --deny)'{-D,--deny=}'[Set lint denied]:lint options:_rustc_opts_fun_lint' \ + '(-F --forbid)'{-F,--forbid=}'[Set lint forbidden]:lint options:_rustc_opts_fun_lint' \ + '*-Z[Set internal debugging options]:debug options:_rustc_opts_fun_debug' \ + '*-C[Set internal Codegen options]:codegen options:_rustc_opts_fun_codegen' \ + "$_rustc_opts_switches[@]" \ + "$_rustc_opts_vals[@]" \ + '::files:_files -g "*.rs"' diff --git a/plugins/rust/rust.plugin.zsh b/plugins/rust/rust.plugin.zsh new file mode 100644 index 000000000..ced6eb4aa --- /dev/null +++ b/plugins/rust/rust.plugin.zsh @@ -0,0 +1,28 @@ +if ! (( $+commands[rustup] && $+commands[cargo] )); then + return +fi + +# Add completions folder in $ZSH_CACHE_DIR +# TODO: 2021-12-28: remove this bit of code as it exists in oh-my-zsh.sh +command mkdir -p "$ZSH_CACHE_DIR/completions" +(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath) + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `cargo`. Otherwise, compinit will have already done that +if [[ ! -f "$ZSH_CACHE_DIR/completions/_cargo" ]]; then + autoload -Uz _cargo + declare -A _comps + _comps[cargo]=_cargo +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `rustup`. Otherwise, compinit will have already done that +if [[ ! -f "$ZSH_CACHE_DIR/completions/_rustup" ]]; then + autoload -Uz _rustup + declare -A _comps + _comps[rustup]=_rustup +fi + +# Generate completion files in the background +rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &| +rustup completions zsh cargo >| "$ZSH_CACHE_DIR/completions/_cargo" &| diff --git a/plugins/rustup/README.md b/plugins/rustup/README.md index ba037f8f6..c620e72a8 100644 --- a/plugins/rustup/README.md +++ b/plugins/rustup/README.md @@ -1,9 +1,3 @@ # rustup -This plugin adds completion for [`rustup`](https://rustup.rs/), the toolchain installer for the Rust programming language. - -To use it, add `rustup` to the plugins array in your zshrc file: - -```zsh -plugins=(... rustup) -``` +**Deprecated: use the [`rust`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/rust) plugin instead.** diff --git a/plugins/rustup/rustup.plugin.zsh b/plugins/rustup/rustup.plugin.zsh index af8cf03a2..0ca745b7e 100644 --- a/plugins/rustup/rustup.plugin.zsh +++ b/plugins/rustup/rustup.plugin.zsh @@ -1,24 +1,11 @@ -if (( ! $+commands[rustup] )); then - return -fi +print ${(%):-'%F{yellow}The `rustup` plugin is deprecated and has been moved to the `rust` plugin.'} +print ${(%):-'Please update your .zshrc to use the `%Brust%b` plugin instead.%f'} # Remove old generated completion file -# TODO: 2021-09-15: remove this line +# TODO: 2021-12-28: remove this line command rm -f "${0:A:h}/_rustup" -# Add completions/ folder in $ZSH_CACHE_DIR -comp_file="$ZSH_CACHE_DIR/completions/_rustup" -command mkdir -p "${comp_file:h}" -(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath) - -# If the completion file doesn't exist yet, we need to autoload it and -# bind it to `rustup`. Otherwise, compinit will have already done that -if [[ ! -f "$comp_file" ]]; then - autoload -Uz _rustup - declare -A _comps - _comps[rustup]=_rustup -fi - -# Generate completion file in the background -rustup completions zsh >| "$comp_file" &| -unset comp_file +(( ${fpath[(Ie)$ZSH/plugins/rust]} )) || { + fpath=("$ZSH/plugins/rust" $fpath) + source "$ZSH/plugins/rust/rust.plugin.zsh" +} -- cgit v1.2.3-70-g09d2