From: Zhiming Wang <zhimingw@princeton.edu>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
Date: Sat, 28 Jan 2017 20:40:00 +0000 [thread overview]
Message-ID: <7143D684-6FEB-4DF3-84CB-BE4F8656EFF1@princeton.edu> (raw)
In-Reply-To: <alpine.LRH.2.00.1701281005590.4560@toltec.zanshin.com>
[-- Attachment #1: Type: text/plain, Size: 7707 bytes --]
On Jan 28, 2017, at 1:08 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Probably the right thing is to add _swift, and use _pick_variant to choose
> whether to call _openstack or to complete Apple's compiler options.
Good call. I am attaching an implementation of _swift. Though I'd very much like
to parse --help output programmatically, some intricacies (like which options
can be repeated) are simply not visible from --help, so I'm hard coding options.
Hopefully Swift is stable enough that options won't fluctuate much across
versions.
From 0be3d1c9ac83bc46e8ce30ee5f0220bfca97395e Mon Sep 17 00:00:00 2001
From: Zhiming Wang <zmwangx@gmail.com>
Date: Sat, 28 Jan 2017 15:33:45 -0500
Subject: [PATCH] Completion/Unix/Command/_swift: new swift/swiftc completions
swift(1) and swiftc(1) are part of the Swift programming language.
https://swift.org/
_swift was written against Apple Swift version 3.0.2.
Note that swift(1) conflicts with the command of the same name from OpenStack.
Completion is delegated to _openstack when swift(1) is detected to be from
OpenStack.
---
Completion/Unix/Command/_swift | 123 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)
create mode 100644 Completion/Unix/Command/_swift
diff --git a/Completion/Unix/Command/_swift b/Completion/Unix/Command/_swift
new file mode 100644
index 000000000..6776f0dea
--- /dev/null
+++ b/Completion/Unix/Command/_swift
@@ -0,0 +1,123 @@
+#compdef swift swiftc
+
+# swift(1) and swiftc(1) are part of the Swift programming language.
+# https://swift.org/
+
+local -a common_options swiftc_mode_options swiftc_additional_options
+local -A swiftc_modes
+
+common_options=(
+ '-assert-config[specify the assert_configuration replacement]:config:(Debug Release Unchecked DisableReplacement)'
+ '*-D[marks a conditional compilation flag as true]:flag:'
+ '*-framework[specifies a framework which should be linked against]:framework:'
+ '*-F[add directory to framework search path]:path:_files -/'
+ '(-gnone)-gdwarf-types[emit full DWARF type info]'
+ '(-gnone)-gline-tables-only[emit minimal debug info for backtraces only]'
+ '(-gdwarf-types -gline-tables-only -g)-gnone[do not emit debug info]'
+ '(-gnone)-g[emit debug info]'
+ '(- : *)-help[display available options]'
+ '-index-store-path[store indexing data to the specified path]:directory:_files -/'
+ '*-I[add directory to the import search path]:path:_files -/'
+ '-j[number of commands to execute in parallel]:count:'
+ '*-L[add directory to library link search path]:path:_files -/'
+ '*-l-[specifies a library which should be linked against]:library:'
+ '-module-cache-path[specifies the Clang module cache path]:path:_files -/'
+ '-module-link-name[library to link against when using this module]:name:'
+ '-module-name[name of the module to build]:name:'
+ '-nostdimport[do not search the standard library import path for modules]'
+ '-num-threads[enable multi-threading and specify number of threads]:count:'
+ '(-Ounchecked -O)-Onone[compile without any optimization]'
+ '(-Onone)-Ounchecked[compile with optimizations and remove runtime safety checks]'
+ '(-Onone)-O[compile with optimizations]'
+ '-sdk[compile against SDK]:sdk:_files -/'
+ '-static-stdlib[statically link the Swift standard library]'
+ '-suppress-warnings[suppress all warnings]'
+ '-target-cpu[generate code for a particular CPU variant]:cpu'
+ '-target[generate code for the given target]:target'
+ '-use-ld=-[specifies the linker to be used]:linker:_files -/'
+ '(- : *)-version[print version information and exit]'
+ '-v[show commands to run and use verbose output]'
+ '-warnings-as-errors[treat warnings as errors]'
+ '*-Xcc[pass argument to the C/C++/Objective-C compiler]:arg:'
+ '*-Xlinker[specifies an option which should be passed to the linker]:option:'
+)
+
+swiftc_modes=(
+ -dump-ast 'parse and type-check input file(s) and dump AST(s)'
+ -dump-parse 'parse input file(s) and dump AST(s)'
+ -dump-type-refinement-contexts
+ 'type-check input file(s) and dump type refinement contexts(s)'
+ -emit-assembly 'emit assembly file(s) (-S)'
+ -emit-bc 'emit LLVM BC file(s)'
+ -emit-executable 'emit a linked executable'
+ -emit-ir 'emit LLVM IR file(s)'
+ -emit-library 'emit a linked library'
+ -emit-object 'emit object file(s) (-c)'
+ -emit-sibgen 'emit serialized AST + raw SIL file(s)'
+ -emit-sib 'emit serialized AST + canonical SIL file(s)'
+ -emit-silgen 'emit raw SIL file(s)'
+ -emit-sil 'emit canonical SIL file(s)'
+ -parse 'parse input file(s)'
+ -print-ast 'parse and type-check input file(s) and pretty print AST(s)'
+)
+local mode
+for mode in ${(k)swiftc_modes}; do
+ # Mode options are mutually exclusive
+ swiftc_mode_options+=("(${(k)swiftc_modes})${mode}[$swiftc_modes[$mode]]")
+done
+
+swiftc_additional_options=(
+ '-application-extension[restrict code to those available for App Extensions]'
+ '-embed-bitcode-marker[embed placeholder LLVM IR data as a marker]'
+ '-embed-bitcode[embed LLVM IR bitcode as data]'
+ '-emit-dependencies[emit basic Make-compatible dependencies files]'
+ '-emit-module-path[emit an importable module to the specified path]:path:_files -/'
+ '-emit-module[emit an importable module]'
+ '-emit-objc-header-path[emit an Objective-C header file to the specified path]:path:_files -/'
+ '-emit-objc-header[emit an Objective-C header file]'
+ '-fixit-all[apply all fixits from diagnostics without any filtering]'
+ '-fixit-code[get compiler fixits as code edits]'
+ '-import-underlying-module[implicitly imports the Objective-C half of a module]'
+ '-output-file-map[a file which specifies the location of outputs]:path:_files'
+ '-o[write output to specified file]:path:_files'
+ '-parse-as-library[parse the input file(s) as libraries, not scripts]'
+ '-parse-sil[parse the input file as SIL code, not Swift source]'
+ '-parseable-output[emit textual output in a parseable format]'
+ '-profile-coverage-mapping[generate coverage data for use with profiled execution counts]'
+ '-profile-generate[generate instrumented code to collect execution counts]'
+ '-sanitize-coverage=-[specify the type of coverage instrumentation for Sanitizers and additional options separated by commas]:type:'
+ '*-sanitize=-[turn on runtime checks for erroneous behavior]:check:'
+ '-save-temps[save intermediate compilation results]'
+ '-serialize-diagnostics[serialize diagnostics in a binary format]'
+ '-tools-directory[look for external executables (ld, clang, binutils) in the specified directory]:directory:_files -/'
+ '-whole-module-optimization[optimize input files together instead of individually]'
+)
+
+case "$words[1]" in
+ swift)
+ # The name swift conflicts with the command with the same name from the
+ # OpenStack project. We delegate completion to _openstack if swift(1) is
+ # detected to be from OpenStack.
+ local variant
+ _pick_variant -r variant openstack=OpenStack swiftlang='Swift compiler' unknown --help
+ case $variant in
+ openstack)
+ _openstack "$@"
+ ;;
+ swiftlang)
+ _arguments \
+ "$common_options[@]" \
+ '*:input:_files'
+ ;;
+ *)
+ _default "$@"
+ esac
+ ;;
+ swiftc)
+ _arguments \
+ "$swiftc_mode_options[@]" \
+ "$common_options[@]" \
+ "$swiftc_additional_options[@]" \
+ '*:input:_files'
+ ;;
+esac
--
2.11.0
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2017-01-28 20:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-28 17:34 Zhiming Wang
2017-01-28 17:42 ` Zhiming Wang
2017-01-28 18:08 ` Bart Schaefer
2017-01-28 19:54 ` Eric Cook
2017-01-28 20:40 ` Zhiming Wang [this message]
2017-01-28 20:52 ` Zhiming Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7143D684-6FEB-4DF3-84CB-BE4F8656EFF1@princeton.edu \
--to=zhimingw@princeton.edu \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).