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

feature request: Auto import dependencies #2635

Closed
wxqqh opened this issue Feb 2, 2016 · 35 comments
Closed

feature request: Auto import dependencies #2635

wxqqh opened this issue Feb 2, 2016 · 35 comments
Assignees
Labels
feature-request Request for new features or functionality on-testplan plan-item VS Code - planned item for upcoming typescript Typescript support issues
Milestone

Comments

@wxqqh
Copy link

wxqqh commented Feb 2, 2016

Can VSCode support automatically import dependencies just link eclipse(ctrl+shift+o)?

@jrieken jrieken added feature-request Request for new features or functionality info-needed Issue requires more information from poster labels Feb 2, 2016
@jrieken
Copy link
Member

jrieken commented Feb 2, 2016

@wxqqh Any specific languages you have in mind?

@wxqqh
Copy link
Author

wxqqh commented Feb 2, 2016

en, such as TypeScript~~~ I haven't tried any other languages.

Just like this, the workspace:

root(workspace root)
  │
  ├ route
  │  │
  │  ├ index.ts
  │  ...
  ├ util
  │  │
  │  ├ utilsubdir <-- this
  │  │  │
  │  │  ├ util1.ts
  │  │  ├ util2.ts
  │  ├ util3.ts
  │ ...
  │  
  ...

In index.ts, if need to use module util1, util2, i must

import * as util1 from "../util/utilsubdir/uitl1.ts";
import * as util2 from "../util/utilsubdir/uitl2.ts";

In this process, it's easy to get wrong.

It maybe to write the wrong path utilSubDir. It can run smoothly on window, but not in *nux.
Or I want to rename the directory to otherutil. All files that use these module must be modified.

So, if VSCode can support this feature, it will be very easy to resolve by just press the shortcut key.
Or show the import suggession/content assist message when i write code util1.xxx().
Of course, the same as dependencies modules which written in package.json.

@jrieken jrieken removed the info-needed Issue requires more information from poster label Feb 3, 2016
@dbaeumer dbaeumer added the typescript Typescript support issues label Feb 11, 2016
@dbaeumer dbaeumer added this to the Backlog milestone Feb 11, 2016
@choeller
Copy link

choeller commented Mar 9, 2016

This would be a really cool feature. I'm currently using Webstorm for Angular 2 development - there you can just type util1 in your code and then hit ALT+ENTER which would suggest adding an import... Something like this would be quite nice!

@Artazor
Copy link

Artazor commented Jun 12, 2016

It is a hot feature!
I suspect, it will speedup the adoption of the VSCode itself.

Desired behavior for TypeScript:

  • Identify all project *.ts and *.d.ts files including referenced ones
  • Collect all exported names from those files
  • When identidier is not resolved suggest importing it from the list of possible files
  • On import maintain import {member1,... memberN} from "../../relative/path" for project files and import {member1,... memberN} from "module/path" for node modules

This scenario is not suited well for CommonJS export = smth style exports, nevertheless, it would be great for the new ES6 module style exports that eventually replace the old style.

@dbaeumer you are our hope!

@dbaeumer
Copy link
Member

@Artazor the actual implementation of that feature has to come from the TS team which maintain the tsserver which we use for TS language smartness. They have several bugs for this:

  • provide quick fixes on unresolved imports
  • provide code complete in import statements (e.g. the module / file part)

@dbaeumer
Copy link
Member

The repository is: https://github.com/Microsoft/TypeScript

@ghost
Copy link

ghost commented Jun 13, 2016

@Artazor the actual implementation of that feature has to come from the TS team which maintain the tsserver which we use for TS language smartness. They have several bugs for this:

provide quick fixes on unresolved imports
provide code complete in import statements (e.g. the module / file part)

Why / how is Webstorm able to do it? That seems to work pretty fine.

@dbaeumer
Copy link
Member

dbaeumer commented Jun 13, 2016

@Artazor didn't make myself clear enough: this is not a technical problem. The TypeScript team is working on addressing it. I The coding of that feature has to happen in this https://github.com/Microsoft/TypeScript and not in VS Code itself. We use the tsserver from that repository via npm inside VS Code.

@vytautas-pranskunas-
Copy link

Is there any progress on this?

@texastoland
Copy link

See microsoft/TypeScript#188 CC @jbrownson.

@nfantone
Copy link

So now that microsoft/TypeScript#188 has been closed and a bunch of extensions already provide autoimport for TS, will this be baked into VSCode? Or will it remain something from userland?

@ghost
Copy link

ghost commented Oct 12, 2016

Yeah, I'm very interested to know that as well. Along with VSTS integration it's the most important missing feature I believe.

@dbaeumer
Copy link
Member

Just for the record. microsoft/TypeScript#188 will not solve this request. microsoft/TypeScript#188 is about code complete in file name in import statements. It will not automatically add imports like Ctrl+Shift+O in Eclipse.

microsoft/TypeScript#188 will very likely land in the next VS Code release

@OliverJAsh
Copy link
Contributor

Potentially solved by this plugin https://github.com/soates/Auto-Import

@caseyhoward
Copy link

@OliverJAsh I use this and it's great. However, I don't think it supports removing unused imports and sorting them. I could be wrong though.

@nfantone
Copy link

nfantone commented Nov 2, 2016

@OliverJAsh and @caseyhoward Have you guys tried Typescript Hero?

@dbaeumer dbaeumer assigned waderyan and unassigned dbaeumer Nov 4, 2016
@dbaeumer
Copy link
Member

dbaeumer commented Nov 4, 2016

This is of dup of the Orange code assist example. The item it adds is the cleanup of unused imports.

@nfantone
Copy link

nfantone commented Nov 4, 2016

@dbaeumer Is there any place where "auto-importing" is being tracked as an issue, then?

@dbaeumer
Copy link
Member

dbaeumer commented Nov 4, 2016

Yes, @waderyan knows which I forgot to ping in my last comment.

@ghost
Copy link

ghost commented Nov 6, 2016

Okay, but will THIS issue solve it? Or what issue will solve it? Why do we need extensions for such a basic feature? #2635 (comment)

@nfantone
Copy link

nfantone commented Nov 6, 2016

@roblourens Clearly, you didn't read into the rest of the comments.

@waderyan
Copy link

I believe this is the correct issue - microsoft/TypeScript#7849

@mjbvz mjbvz self-assigned this Jan 26, 2017
@fightingcat
Copy link

fightingcat commented Mar 14, 2017

It is annoying writing code without this feature, I've tried typescript-hero, seems that it doesn't import symbols in module declaration in d.ts. (I want auto alias actually.)

@PhoneixS
Copy link

I think that now Typescript 2.2 and Visual Studio Code 1.10 allow adding missing imports as stated on the blog:
https://blogs.msdn.microsoft.com/typescript/2017/02/22/announcing-typescript-2-2/
And the Code support:
https://code.visualstudio.com/updates/v1_10#_languages

So, should this issue be closed?

@fightingcat
Copy link

fightingcat commented Mar 15, 2017

what we request is different with what they stated, I don't want to select or move cursor to every symbols to fix missing imports, fixing every missing import automatically with one single command is better.
(doing this one by one, again and again is particular rediculous while writing variable declarations, really disturb the mind.)

@ng-state
Copy link

Is there a way to say for auto-import to use single quotes?

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 15, 2017

@ng-state This is being tracked upstream: microsoft/TypeScript#13270

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 15, 2017

Yes, VScode 1.10 added a quick fix for imports but as @fightingcat notes, we do not automatically apply these fixes and I believe that is what this issue is tracking. This feature would likely behave like eslint'/tslint's autoFixOnSave option.

We will only be able to auto fix symbols that have a single potential import. Otherwise, you will still have to manually apply the quick fix and select the correct import to use. We also want to make sure this does not get in the way while you are working on a file

@ng-state
Copy link

@mjbvz it was opened in Jan 3 and still not fixed.. forcing devs to correct each import by hand :(

@vytautas-pranskunas-
Copy link

What is missing - intellisence. E.g. when using AutoImport plugin you begin to write class name and you can pick it from the list, once picked import is added automatically. With current implementation developer needs to know exact class name to get yellow bulb for import.

@fightingcat
Copy link

fightingcat commented Mar 16, 2017

In my view, this feature is much more urgent than others, would save much time.

@shahata
Copy link

shahata commented Apr 10, 2017

Are there any plans to have this also for javascript?

@theamazingfedex
Copy link

Having this feature for .net would be great..

@waderyan waderyan removed their assignment Jul 13, 2017
@mjbvz mjbvz modified the milestones: Backlog, October 2017 Oct 11, 2017
@mjbvz mjbvz added the plan-item VS Code - planned item for upcoming label Oct 11, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Oct 11, 2017

Adding to the October iteration plan. This will depend on microsoft/TypeScript#19069 which should land in TypeScript 2.6

@cyrilletuzi
Copy link

@mjbvz As I'm not sure it's a TS or VS Code problem, please see microsoft/TypeScript#19417 about an important problem with this new feature.

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality on-testplan plan-item VS Code - planned item for upcoming typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests