Skip to content

feat: question chain api #19828

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
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

discord9
Copy link

@discord9 discord9 commented May 20, 2025

related

#19454

overview

Added a API for asking user multiple questions and get answers, useful for quick fix that need to ask multiple question and get user choice(i.e. import all missing item, choose multiple import crates etc.)

details

Use ShowMessageRequest to send message to user, and get MessageAction in return.

The major impl is in ask_for_choice function and is somewhere twisted as writing async code using callback is certainly very uncomfortable. ask_for_choice send with a empty request id as can't determine what request id it should belong to.

On the Assists side, developer basically provide a callback with signature of dyn FnOnce(&mut SourceChangeBuilder, &[usize]) + Send + 'static to handle what to do after get user choices results, so it's similar to add_group method

todo

test this with a integration test

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 20, 2025
/// A list of choice groups. Each inner tuple's first string is title, second vector represents a set of options
/// from which the user can make one selection.
/// For example, `choice_options[0]` might be `["Question 1", ["Option A", "Option B"]]` and
/// `choices[1]` might be `["Question 2", ["Setting X", "Setting Y"]]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be choice_options[1] instead of choices[1] ?

@@ -202,6 +203,45 @@ impl Assists {
self.add_impl(Some(group), id, label.into(), target, &mut |it| f.take().unwrap()(it))
}

/// Give user multiple choices, user's choice will be passed to `f` as a list of indices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I once again got a bit confused with the distinction between a multiple choice question and many consecutive questions. Surely the problem is with me, but a clarification never hurts. Thanks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I once again got a bit confused with the distinction between a multiple choice question and many consecutive questions. Surely the problem is with me, but a clarification never hurts. Thanks.

yes that's confusing, I should come up with a better name for them, because this api intended to provide multiple consecutive questions with multiple choices, it's a bit of confusing.

@discord9 discord9 changed the title feat: user choice group api feat: question chain api Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants