-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom completion per shell (zsh, bash, or fish) #672
Comments
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Oct 31, 2024
Swift shell completion functions can determine the shell requesting completions from a CompletionShell singleton named CompletionShell.requesting. For the custom(:) CompletionKind, the singleton is populated at runtime (when a completion script requests completions from the Swift app) from an environment variable export by each completion script. For all other CompletionKinds, the singleton is populated when a completion script is generated. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Nov 1, 2024
A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Nov 1, 2024
…ates A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
4 tasks
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Nov 1, 2024
…ates A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Nov 1, 2024
…ates A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Nov 24, 2024
…ates A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
rgoldberg
added a commit
to rgoldberg/swift-argument-parser
that referenced
this issue
Dec 5, 2024
…ates A CompletionShell singleton named CompletionShell.requesting has been created that indicates which shell is requesting completion candidates. The singleton is populated when a completion script is generated, so functions used to generate arguments for CompletionKind creation functions can return completion candidate syntax / shell commands tailored for that shell. For the custom(:) CompletionKind creation function, the singleton is populated at runtime (when a completion script requests completions from the Swift app after a user types tab while composing a command line to call the app). The requesting shell is communicated to the Swift app via an environment variable named SAP_SHELL, which is exported by each of the generated completion scripts. Resolve apple#672 Signed-off-by: Ross Goldberg <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
Different shells use different syntaxes for their completions.
e.g., zsh's
_describe
accepts a different syntax than bash'scompgen
.The
completion:
parameter for@Argument
& for@Option
is used for all shells.To the best of my knowledge, Swift Argument Parser (SAP) doesn't inform Swift the shell for which completions are being requested.
It is thus difficult to output the correct values to properly configure completion in multiple shells.
Versions
ArgumentParser version:
1.5.0
Swift version:
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.0
Checklist
main
branch of this packageSteps to Reproduce
Expected behavior
Ability to easily output completions that are correct for the current shell.
Actual behavior
Cannot easily output completions that are correct for the current shell.
Solution
There are many ways to solve this, but the simplest way to do so without changing the existing
CompletionKind
s or thecompletion:
parameter of@Argument
or@Option
seems to be for SAP to provide a singletonCompletionShell
namedCompletionShell.requesting
(requesting
for short) that can be used by code supplying an associated value for aCompletionKind
to determine the shell for which completions are being requested.For
.custom(:)
,requesting
must be available at runtime when a completion script requests completions. For the other currentCompletionKind
s,requesting
need only be available when a completion script is generated by using--generate-completion-script <shell>
.For
.custom(:)
, each completion script generated by using--generate-completion-script <shell>
will export an environment variableSAP_SHELL
=<shell>
so SAP can use it to populaterequesting
before it callscompletion
from.custom(:)
.For the other current
CompletionKind
s, the*CompletionsGenerator.generateCompletionScript(type:)
function will populaterequesting
with the correct value before calling the shell-specific*CompletionsGenerator.generateCompletionScript(:)
. Any function called to supply the associated value for theseCompletionKind
s can readrequesting
to determine the shell for which completions are being requested.The text was updated successfully, but these errors were encountered: