Skip to content

Proposal: simplify auto import descriptions #47631

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

Merged

Conversation

andrewbranch
Copy link
Member

Compliments #47552 and makes progress on #47521.

Now, when a codefix will result in a new import declaration, the message is Add import from "foo". When adding an import to an existing import declaration, the message is Update import from "foo". The exception is when the thing being imported doesn’t share a name with the identifier that triggered the error—the only way this happens today is when you are prompted to import React (or whatever your JSX element factory is) on an arbitrary JSX element name. In that case, the message is Import 'React' from "react".

This change is based on two assumptions:

  • You don’t need to see the name of the thing you’re importing repeated in the description because you’re fixing an error on that name or are in the process of typing that name.
  • Nobody really cares whether the import is going to be a default import or named import.

Copy link
Contributor

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

The new wording makes sense to me. Thanks for taking a look!

@@ -6354,18 +6354,14 @@
"category": "Message",
"code": 90012
},
"Import '{0}' from module \"{1}\"": {
"Import '{0}' from \"{1}\"": {
Copy link
Member

Choose a reason for hiding this comment

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

This is used for both add and update? Also, nitpicky, but why one set of single quotes and one set of double quotes?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think I even see this message used the diff. Am I missing it?

Copy link
Member

Choose a reason for hiding this comment

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

I missed it too - it's referred to by its property name in the tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

@amcasey yes, both add and update. We always use double quotes for module specifiers for some reason, and single quotes for other code quoting 🤷‍♂️

importKind === ImportKind.Default ? Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : Diagnostics.Add_0_to_existing_import_declaration_from_1,
symbolName,
moduleSpecifierWithoutQuotes
]; // you too!
Copy link
Member

Choose a reason for hiding this comment

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

you too!

Copy link
Member Author

Choose a reason for hiding this comment

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

I left it in for so long, never knowing what it was referencing.

@andrewbranch andrewbranch merged commit e9092f3 into microsoft:main Jan 27, 2022
@andrewbranch andrewbranch deleted the improve-auto-import-descriptions branch January 27, 2022 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants