Skip to content

feat: auto import all missing items #19454

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 10 commits into
base: master
Choose a base branch
from

Conversation

discord9
Copy link

@discord9 discord9 commented Mar 26, 2025

Related Issue

#12761

Import all missing items

add a new assist to automatically import all missing items in scope.
For now it will only pick the most likely import when multiple import choices is found, this might could be improved by asking user which one do they want, but I can't figure out how to do that now

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 26, 2025
@discord9 discord9 changed the title feat: auto import all missing items(WIP) feat: auto import all missing items Mar 27, 2025
@discord9 discord9 marked this pull request as ready for review March 27, 2025 05:23
@discord9 discord9 force-pushed the feat/auto_import_all branch from 88f0ee9 to 982953a Compare March 27, 2025 07:54
@nemethf
Copy link
Contributor

nemethf commented Mar 27, 2025

this might could be improved by asking user which one do they want, but I can't figure out how to do that now

Rust-analyzer can potentially ask the user by sending a ShowMessage Request. (It seems the current code does not contain an example for this)

@discord9
Copy link
Author

discord9 commented Mar 28, 2025

this might could be improved by asking user which one do they want, but I can't figure out how to do that now

Rust-analyzer can potentially ask the user by sending a ShowMessage Request. (It seems the current code does not contain an example for this)

is adding this two methods to Assists a good idea?:

    /// For scenarios where the user needs to select one or more options from a predefined list
    pub(crate) fn add_multi_select_choice(
        &mut self,
        group: &GroupLabel,
        id: AssistId,
        label: impl Into<String>,
        target: TextRange,
        choices: Vec<Vec<String>>,
        f: impl FnOnce(&mut SourceChangeBuilder, &[String]),
    ) -> Option<()> {
        todo!()
    }

    /// For scenarios requiring sequential, stateful interactions where choices influence subsequent steps.
    pub(crate) fn add_multi_step_choice(
        &mut self,
        group: &GroupLabel,
        id: AssistId,
        label: impl Into<String>,
        target: TextRange,
        first_choice: Vec<String>,
        f: Vec<Box<dyn FnOnce(&mut SourceChangeBuilder, &str)->Vec<String>>>,
    ) -> Option<()> {
        todo!()
    }

@nemethf
Copy link
Contributor

nemethf commented Mar 28, 2025

is adding this two methods to Assists a good idea?:

I'm not qualified to determine that, but ...

/// For scenarios where the user needs to select one or more options from a predefined list

... a single ShowMessage request cannot be used to select more than one options. However, multiple requests can achieve this. For example, if there are three options: A, B, C, then the user can select A and B with the following exchange:

sequenceDiagram

RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[ ] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("[ ] Option B")
RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[X] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("[ ] Option A")
RA ->> LSP Client: ShowMessageRequest(["[X] Option A", "[X] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("Proceed")
Loading

@discord9
Copy link
Author

discord9 commented Mar 28, 2025

is adding this two methods to Assists a good idea?:

I'm not qualified to determine that, but ...

/// For scenarios where the user needs to select one or more options from a predefined list

... a single ShowMessage request cannot be used to select more than one options. However, multiple requests can achieve this. For example, if there are three options: A, B, C, then the user can select A and B with the following exchange:

sequenceDiagram

RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[ ] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("[ ] Option B")
RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[X] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("[ ] Option A")
RA ->> LSP Client: ShowMessageRequest(["[X] Option A", "[X] Option B", "[ ] Option C", "Proceed") 
LSP Client ->> RA: ActionItem("Proceed")
Loading

Unable to render rich display

sequenceDiagram

RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[ ] Option B", "[ ] Option C", "Proceed")
LSP Client ->> RA: ActionItem("[ ] Option B")
RA ->> LSP Client: ShowMessageRequest(["[ ] Option A", "[X] Option B", "[ ] Option C", "Proceed")
LSP Client ->> RA: ActionItem("[ ] Option A")
RA ->> LSP Client: ShowMessageRequest(["[X] Option A", "[X] Option B", "[ ] Option C", "Proceed")
LSP Client ->> RA: ActionItem("Proceed")

Yes, I don't mean mutli-select, but providing multiple question each with choices(and user choose one from each), I think that's likely the suitable way(a good enough api on the Assist side) to do it and decide to proceed to impl that

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