Skip to content

Permit asynchronous code to be given to the custom completion type #555

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

Open
thafner0 opened this issue Feb 21, 2023 · 3 comments
Open

Permit asynchronous code to be given to the custom completion type #555

thafner0 opened this issue Feb 21, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@thafner0
Copy link

thafner0 commented Feb 21, 2023

At the moment the custom case of the CompletionKind enumeration supports being given a custom closure to generate completions on the command line. However, since the provided closure must be synchronous, it is difficult to incorporate functionality that requires swift's concurrency features. The lack of this functionality prevents certain tasks from being possible with these completions and causes other tasks to be possible, but only in a non-thread safe way. Examples of this include working with databases (such as those managed by Apple's Core Data framework).

Example:

struct SomeCommand: AsyncParseableCommand {

@Argument(help: "<Helpful help>", completion: .custom({ arguments in
return try? await completionGenerator(arguments: arguments) ?? []
}))
var argument: String

mutating func run() async throws {
// Code that makes the command Run
}
}

@MainActor
private func completionGenerator(arguments: [String]) async throws -> [String] {
// Code that generates completions that has some asynchronous system in use and/or must be run on the main actor.
}
@natecook1000 natecook1000 added the enhancement New feature or request label Feb 28, 2023
@luispadron
Copy link

This would be great, along with completion we could really use this for transform.

@natecook1000 is this something you think would be wanted? I could work on this if you don't think it's too complicated as a first task

@rgoldberg
Copy link
Contributor

rgoldberg commented Feb 16, 2025

@natecook1000 @rauhul Is this issue on the roadmap for imminent development? Would it be difficult to implement?

Is there any public roadmap for what issues will be worked on soon?

Thanks for any info.

@rgoldberg
Copy link
Contributor

I have code that implements this that I will submit as a PR after #770 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants