Skip to content
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

addMissingImports code action doesn't prompt for ambiguous imports #139131

Closed
rothfels opened this issue Dec 14, 2021 · 2 comments
Closed

addMissingImports code action doesn't prompt for ambiguous imports #139131

rothfels opened this issue Dec 14, 2021 · 2 comments
Assignees
Labels
*as-designed Described behavior is as designed

Comments

@rothfels
Copy link

rothfels commented Dec 14, 2021

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.63.0
  • OS Version: macOS 114

(I think this is a bug as I remember this behavior existing in the past...but I could be wrong and it's a feature request)

Steps to Reproduce:

  1. Add to settings.json
"editor.codeActionsOnSave": {
    "source.addMissingImports": true,
}
  1. Save a file with ambiguous imports, e.g
function myFunction(id: ID) {
  
}

Where ID hasn't been imported. Make sure you have a local file with an export like

export type ID = string

and also some dependency like aws-sdk which also exports ID.

Expected:

The auto-import action detects multiple options for IDand prompts the user to select which value to import, similar to the tooltip prompt:

image

It would do this once for each ambiguous import.

Actual:

The auto-import action imports the first possible match, which often is not the desired import.

@mjbvz
Copy link
Collaborator

mjbvz commented Dec 16, 2021

This is by-design as we don't want our source actions to (sometimes) prompt for user interaction. Doing so would be especially weird on save

Instead source.addMissingImports is designed to only add imports it is confident in. More complex cases require manual review by the developer

@mjbvz mjbvz closed this as completed Dec 16, 2021
@mjbvz mjbvz added the *as-designed Described behavior is as designed label Dec 16, 2021
@rothfels
Copy link
Author

@mjbvz thanks, that makes sense.

Instead source.addMissingImports is designed to only add imports it is confident in

In that case, isn't it weird that the auto-importer would always choose the first when there are multiple import options? That's what feels like the bug to me -- in the case where there's ambiguous imports, I would rather vscode import none of the options than the current behavior of choosing the wrong one.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed
Projects
None yet
Development

No branches or pull requests

2 participants