Giter Site home page Giter Site logo

soates / auto-import Goto Github PK

View Code? Open in Web Editor NEW
163.0 163.0 63.0 164 KB

vscode extension that will automatically finds, parses and provides code actions for all available imports. Only currently works with files in your folder and TypeScript.

License: MIT License

TypeScript 100.00%

auto-import's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

auto-import's Issues

Tries to auto-import after typing period in JS-doc comment or JS string literal

VS Code 1.6.1 with Auto-Import 1.2.2.

It seems to try to auto-import anytime I type a period in a JS-doc comment or a JS string literal. It also shows auto-complete options before I type the period (despite it not being an appropriate place to offer suggestions). I wind up with a bunch of unwanted imports and autocompletions if I don't pay attention.

auto-import and generated d.ts files

Regarding my comment from the marketplace:

Would be awesome but if you let tsc generate typing files then the auto-import stuggles and writes the typing files as import statements. It would be good to configure this plugin with a glob expression to allowed paths to scan.

If your tsconfig.json file contains the compiler option to generate definition files for your code ("definitions": true), then auto-import will struggle to find the correct type import. In my tests it imports the from the generated d.ts files which is clearly not what one expects (and it will fail if you clean all generated code for a full rebuild.

I think it would be great to exclude paths from auto-import (e.g. build artifact folders).

Import path contains redundant parts, as well as incorrect slashes

When auto-importing a class from a file in a sibling directory, the resulting import statement looks like this:
import { RequestActions } from ".\..\actions\request.actions";

The leading .\ in the import path is redundant and could be removed. Also, the path consists of backslashes instead of forward slashes.

I'm using 0.8.0 on a Windows system.

How to debug?

I've noticed the extension only seems to work some of the time for me (in a TypeScript project).

Are there any steps I can take to help me debug? E.g. see a list of files that are being scanned for possible import matches each time the plugin runs?

Stopped working after upgrade to 1.0 from 0.9

Hi!
First of all love your extension!

But it stopped working after I upgraded from 0.9 to 1.0,
it does not give any suggestions for imports("No fix suggestion").

I'm on windows 10, vscode 1.6.0-insider.
angular-cli": "1.0.0-beta.14,
angular 2.0.0
typescript 2.0.2

does not work with default new angular2-cli new project,

while at it, a feature request: sorting of imports, maybe after config?

Cheers

TSX support?

Currently, the extension can neither parse exports nor generate imports in/from TSX files.
Could this be added?
Thanks.

Find co-maintainer / support community fork

Hi!

Thank you so much for this work! I love this plugin.

Was gonna get to work on a PR for this repo, but I see that @soates looks very busy and not able to keep this repo updated. I totally get it! I've been there with my own OSS libraries -- it's a pain to respond to everyone's requests. Often community needs way outstrip your capacity to maintain something you began as a personal tool.

Wonder if it would make sense to give someone else ownership of this repo so that updates can get merged, or deprecate this plugin and support a community fork.

Thoughts?

Duplicate imports

When I have existing imports from ../foo, any auto completions for exports in this module will add another import from ./../foo.

E.g.

import { x } from '../foo';
// after auto importing y…
import { y } from './../foo';

Expected:

// after auto importing y…
import { x, y } from '../foo';

This may be related to #37

RxJs no import Suggestion

I am using version 1.2.2 and its not suggesting import for BehaviorSubject meanwhile it suggest for Subject. Both of them they are in the same "place"

import { Subject, BehaviorSubject } from 'rxjs';

So if i add to my code

var subject = new Subject();
var bs = new BehaviorSubject(2);

For first Subject i will have suggestion for BehaviorSubject i will not have import suggestion

Place imports after licence/comment headers

For the moment top comments (license headers) are not respected during auto-import. For example:

sample.ts

/*!
 * @license
 * Copyright 2016 Company.
*/

export class MyClass {}

During auto-import the line will be added to the top of the file:

sample.ts

import { Observable } from 'rxjs/Rx';
/*!
 * @license
 * Copyright 2016 Company.
*/

export class MyClass {}

Expected behaviour: it should put imports after top comment block (ideally to be configurable via some settings flag)

Imports module to self for static variables

When you use a static variable from within a module where it was declared, an import statement is created anyway, importing the module you're already in, and causing an error.

Example:

@Injectable()
export class SomeService {

   static SOME_VARIABLE = 'this is an example';

   someMethod(){
       let test = SomeService.SOME_VARIABLE;
       //    Upon typing "SomeService.", the service is imported into itself
   }

}

Question: Is there a keybinding I can use to initiate the import?

First: This plugin saved my bacon this weekend. I was migrating a project from namespaces to external modules, and this made it so easy. Thank you!

There might already be a way to do this, but I couldn't find it in my checking of the docs. Is there a keybinding I can use to initiate the lightbulb dropdown? That would speed me up significantly.

Prevent adding import when same already exists

Occasionally, auto-import will import a type that has already been imported.
For example, whilst typing the following:

var source = Observable.create(observer => {

a second import was added as follows:

import { Observable } from 'rxjs/Observable';

Annoyingly, I am not able to reliably reproduce this.

Importing Abstract Classes

On my project, the extension works fine when importing regular classes, but does not appear recognize exported abstract classes.

Although these classes can't be used on their own, they are sometimes used in the type declarations in other files, and as such, would be nice to still be able to import them automatically just as we do we regular classes.

Importing var from module

This extension works great with classes - it finds file with class in project and makes correct imports.
But I have a few files where I have exported not only a class but also a var - it can't find it and don't provide quick-fix for import it:

export class User extends Document<User> {
    ...
}
export var userModel: mongoose.Model<User> = defineSchema<User>(User);

It's a bug or you just don't support var export?

Ignore comments

// import {Widget} from './widget';
new Widget();

If I import Widget it is added to the comment like so:

// import {Widget, Widget} from './widget';
new Widget();

Also, may this should be another issue, but the using of existing imports is awkward in general.

import './widget';
new Widget

If I try to import Widget, nothing happens.

Ignore File List

Is it possible to add the ability to ignore a directory? Using Ionic2 I have a .tmp directory that is suggested by auto-import. I've tried to use filesToScan setting to limit to just src and node_modules but it then doesn't seem to suggest ionic and angular imports.

VSCode freezes when doing npm updates on a quite large project

Hi,

I'm using VSCode since several month with no freeze issues. After installing several extensions including 'Auto Import' I have freezes when doing npm updates in a larger project. I works in smaller projects.

When disabling your extension all works fine.

  • Windows 10 Pro 64
  • VSCode 1.8.1
  • Node 6.5.0

Regards, Walter

Files cannot be saved after the window has been open / in use for a while

I've run into a weird issue where the editor stops saving files when I use the keyboard shortcut or the UI (after clicking the close button on an unsaved file). The UI continues to show the files as unsaved. Restarting VS Code or uninstalling this extension fixes the problem.

I'll try to narrow down the actions/time required to trigger this issue - I know this is all a bit vague.

Original issue from VS Code project: microsoft/vscode#13492

Can't auto-import into TSX files.

Works perfectly in .ts files, and can also import from .tsx into .ts. However, the extension seems to not be running when editing a .tsx file.

Wasn't working when first installed.

I had just installed vscode on OS X Sierra and was working on a component. I did not yet have this plugin installed.

Here's the code:

import { Input, Component } from '@angular/core';
import {Account} from "./account";

@Component({
    selector: 'account-info',
    template: `
    <div>{{account.companyName}}</div>
    <div>{{account.address}}</div>
    <div>{{account.}}</div>
`
})
export class AccountInfoComponent implements OnInit {
    @Input() account: Account;
}

I installed this plugin, reloaded VSCode and tried to use the autocomplete feature to import OnInit.

The context menu showed up and displayed two options.
image

Nothing happened when I pressed enter on either one or clicked on either one.

I had to erase this line before the plugin would start working.

import { Input, Component } from '@angular/core';

Imports modules that are already imported (rxjs/<module> vs rxjs/Rx)

I keep having to remove duplicate imports. This is specifically with rxjs but I assume will happen with other libraries.

Here's an example:

I already have an import statement such as:

import { Observable } from 'rxjs/Rx';

Then I go try to use the "Observable" class and I get a new import statement like:

import { Observable } from 'rxjs/Observable';

At first it seemed like a minor price to pay for the power of this tool but as it kept happening I realized I should report it.

Option to use non-relative paths

Auto-Import always generate a relative path, like:

import { b } from "./moduleB"

Instead, I'd need to use non-relative paths, like:

import { b } from "root/src/moduleB"

It would just use the root of the tsconfig.json file, and eventually could use other roots defined in rootDirs.

Rationale: avoiding relative paths is an opinionated good practice and a coding standard in many code bases.

Manually update import index

Hi,

I can't seem to find a way to manually trigger refreshing the index, after adding new exports to my code.

Am I just blind? :D

Support default exports

I know default exports aren't required to have a name but there is a common pattern where a default export also has a name:

export default class MyClass {}

Is there any way this plugin can support autocomplete when I try to use MyClass somewhere and automatically add import MyClass from './my-file';?

Not importing angular modules

I could swear this was working before so maybe something broke on my end?

It's still working to import my own custom modules and components (say, I made a service called LessonsService - works beautifully) but when I, for instance, try to use FormBuilder, FormGroup, or Validators from @angular/forms, it must be done manually...

Is there some step I'm missing to link things up?

EDIT: Looking more closely at your changelog I see the

Todo: Work with node_modules (@angular / underscore for example).

Thank you so much for your hard work! Is there some way we can get the functionality in the mean time such as configuring filesToScan?

Merge 1.1 to master

I was confused when I saw master was not up-to-date with the latest version available on the VSCode market place, then I realised this is the 1.1 branch. Can we merge that to master to avoid confusion?

How do I use this?

I added this extension to Visual Studion code and enabled it. Now what?

Support function exports

There was a recent commit to support const exports. Would be great to support function exports too, e.g:

export function add(n1: number, n2: number) {
  return n1 + n2;
}

Always picks first option

VSCode 1.7.0, Auto Import 1.2.2, Windows 10

When multiple options are available for imports, the first one will be inserted regardless of which one you pick.

How to use AutoImport extension with angular quickstart sample?

This is the first time I am trying to use Auto-Import extension.
My environment is like this-
AutoImport version: 1.2.2
VScode version: 1.8.1
angular version: ~2.4.0

Steps I followed so far-

  1. Downloaded sample from https://github.com/angular/quickstart
  2. Open VScode and open respective folder.
  3. By using npm start, I am able to run quickstart sample.

However, I am NOT able to get AutoImport working. Refer below image-

autoimport

Please let me know if I am missing anything here?

Unnecessary option to import current file

Sometimes, auto-import will suggest the current file to import:

image

In this case, the default option / 1st result will add an import statement to the top of the file to import itself. The 2nd option is the class LoginProvider option which doesn't add an import (and the 3rd line is just a superfluous file from a tmp folder which can be ignored for this issue).

This option should probably be removed for the current file. Importing of the current file will simply cause TypeScript compile issues (and relatively confusing ones at that, e.g: Individual declarations in merged declaration 'LoginProvider' must all be exported or all local).

Option to remove leading . in path of outer file

Given module foo/a.ts and bar/b.ts, if I want to import the latter in the former, this plugin would generate:

import { whatever } from './../bar/b.ts'

I would like the option to remove the leading . in this path

import { whatever } from '../bar/b.ts'

duplicate quote

Import class from external module add additional quotes:

import {SomeClass} from ""other-module"";

but it's fine when import class from the same workspace.

Support type export

The export export type Severity = "error" | "warning" | "info" | "success" cannot be found automatically.

Annoying popup about autoimport cache

Is there an config option which allow to disable annoying notification about autoimport cache has been build?

Maybe you could move this info to statusbar on bottom like other extensions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.