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

Potentially incompatible/unsupported import statements added to code by default #38773

Closed
oliversalzburg opened this issue Nov 20, 2017 · 6 comments
Assignees
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@oliversalzburg
Copy link

  • VSCode Version: Code 1.18.1 (929bacb, 2017-11-16T18:32:36.023Z)
  • OS Version: Windows_NT x64 10.0.15063
  • Extensions:
Extension Author (truncated) Version
vscode-eslint dba 1.4.3
EditorConfig Edi 0.11.1
vsc-material-theme Equ 1.1.2
JSDocTagComplete Hoo 0.0.2
vscode-esformatter how 1.5.2
output-colorizer IBM 0.1.2
vscode-puglint mrm 2.3.0
debugger-for-chrome msj 3.5.0
code-spell-checker str 1.4.12

(2 theme extensions excluded)


Steps to Reproduce:

  1. Type re and press Enter.
  2. Code will "auto-import" read from fs.

Even if we wanted this behavior, the import statement is inserted at the wrong location and violates our style rules. import is also only at experimental support level in Node (behind a flag), so I really don't understand this behavior.

@vscodebot vscodebot bot added the javascript JavaScript support issues label Nov 20, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Nov 20, 2017

You can disable auto imports by setting "typescript.autoImportSuggestions.enabled": false or by pressing esc before accepting the completion

Can you please provide an example of where the import being added incorrectly?

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Nov 20, 2017
@oliversalzburg
Copy link
Author

oliversalzburg commented Nov 21, 2017

typescript.autoImportSuggestions.enabled

Thanks a lot!

I'm not sure what controls this behavior. As in, what modules it suggests for auto-import. This just started happening in projects where it didn't happen before. These are NodeJS projects, but I don't know how Code identifies those. But this happens in all the projects I'm working on.

I've tried to reproduce this in https://github.com/villadora/express-bunyan-logger because I have it open right now and it happens there as well:

image

IMHO there are many things wrong with the current approach. The most important one being that it is enabled by default.
Other than that, it generates invalid code for the current context, the place where the code is inserted is potentially undesirable (no control over sorting of imports, code inserted above file headers), being other things on the list.

@oliversalzburg
Copy link
Author

typescript.autoImportSuggestions.enabled does not seem to have any effect when put into the settings of my workspace.

@Nighthawk22
Copy link

My best auto import so far
import { Dispatch, Dispatch } from '../../../../../Library/Caches/typescript/2.6/node_modules/@types/react-redux'; 😂

@oliversalzburg oliversalzburg changed the title Nonsense import statements are added to my code Potentially incompatible/unsupported import statements added to code by default Nov 23, 2017
@alirobe
Copy link

alirobe commented Nov 24, 2017

Related but not the same: I've requested the entire feature be disabled. I can't see why anyone could want this behavior by default, even if the imports made any sense (which, yep, they usually don't).

#38911

@mjbvz
Copy link
Collaborator

mjbvz commented Nov 27, 2017

Opened microsoft/TypeScript#20292 to track using require for auto imports and the import being inserted in the wrong location relative to existing requires.

@mjbvz mjbvz closed this as completed Nov 27, 2017
@mjbvz mjbvz added upstream Issue identified as 'upstream' component related (exists outside of VS Code) and removed info-needed Issue requires more information from poster labels Nov 27, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

4 participants