Git Product home page Git Product logo

vscode-exports-autocomplete's Introduction

Deprecation notice

Since publishing this extensions the same functionality was added into vscode core so this extension in not needed anymore. Actually it's undesirable because vscode's implementation is faster.

vscode-exports-autocomplete

Marketplace Version Installs Rating Build Status

Showcase

showcase

Features

Collects ES6 exports from your project and autocompletes them. Upon completion, item is also imported using a relative path. Import is placed after last import in that file.

Generated import has no semicolon when you have a standard package in your package.json devDependencies. If you have eslint, it should pick up it's semicolon config and insert/omit semicolon accordingly to what you have set.

Of course it works even with huge projects which contain thousands of JS files. All JS/JSX files are parsed and cached on startup, then vscode internal file watcher is used to observe changed files.

We also parse ES6 files in node_modules-just the roots. For example if you have redux package in your dependencies, we will parse this file giving us exactly the exports we want. So if you're a lib author, don't forget to add module property to your package.json.

Another nifty feature is adding imports when you paste some code, see:

adding on paste

Usage inside JSX

Since VSCode does have it's own JSX support, there are some usability choices made to complement that.

If you're writing a component WITH children, you need to write a pair. Utilize a vscode's feature that will make any text into a JSX opening and closing pair when you hit a TAB key. Like this:

TODO add gif

If you're writing a component WITHOUT children, start by typing <. When you choose autocomplete, plugin will automatically close the tag for you. Like this:

TODO add gif

Extension Settings

This extension has the following settings:

  • vscode-exports-autocomplete.enable: enable/disable this extension
  • vscode-exports-autocomplete.addImportsOnPaste: set this to false when you're annoyed by import tokens being added on paste
  • vscode-exports-autocomplete.minimumWordLengthToImportOnPaste: set this to a higher value if 'on paste' is too aggressive for you
  • vscode-exports-autocomplete.enableNpmDependencies: set this to false when you're annoyed by the stuff you get from your npm modules*
  • vscode-exports-autocomplete.addSpacingAroundCurlyBraces: set this to true when you prefer spaces around curly braces
  • vscode-exports-autocomplete.indentationOverride: string to be used when indenting, default is two spaces,
  • vscode-exports-autocomplete.quoteCharOverride: string to be used when writing string literals, default is single quote, for doublequote use """
  • vscode-exports-autocomplete.cacheSizeLimit: size limit for the cache of parsed exports, parsed with bytes npm package, shared among all projects, default "25MB"

You need to restart VSCode for the changes to take effect.

vscode-exports-autocomplete's People

Contributors

capaj avatar cheapsteak avatar flying-sheep avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vscode-exports-autocomplete's Issues

Module resolve

Hi in our projects we like to use module resolve:

// instead
import A from "../../components/A";

// resolve
import A from 'components/A';

Can you add a config for this? or respect jsconfig from VSCode

flow import type is not properly handled

import Router from 'koa-router'
import boom from 'boom'
import type { Context } from 'koa'

when adding a new import db to this I get

import Router from 'koa-router'
import boom from 'boom'
import typeimport db from '../../db';
 { Context } from 'koa'

we should handle flow type imports properly

Feature Request: Add option to exclude directories in user settings

@capaj, Thank you for the wonderful plugin.

I have an issue with the way plugin imports from all the folders in the project when used with the history plugin. The history plugin stores older versions of edited files in case needed to revert, and autocomplete always picks this to resolve the imports.
Would be nice if ignore directories option is provided to tackle such scenario.

cache the exports

save them in a json once we walk the whole project. Then on reopen:

  • validate against git that the files haven't changed
  • use the cache or rebuild
  • clean the cache once we have more than X MB of data(every 5th run), X should be in config

introduce "add missing imports" command

when writing in the one line separating imports and the rest of the code, remove the written token oncompletion. This will allow ti quickly add a missing import wihout having to manually delete the imported word

Feature Request: Understanding "import type" from flow

Thank you for a great plugin.
Are there any plans to make this work with types from flow?
ie understand the "import type" statement.

Or in the interim perhaps a setting to ignore any "import type" statements in a js file?

Thanks

Cannot match against 'undefined' or 'null'.:

I am getting this in the Developer Console, version 0.5.1

[capaj.vscode-exports-autocomplete] Cannot match against 'undefined' or 'null'.: TypeError: Cannot match against 'undefined' or 'null'.
	at workspace.onDidChangeTextDocument (C:\Users\carsonh\.vscode\extensions\capaj.vscode-exports-autocomplete-0.5.1\lib\add-import-on-paste.js:30:45)
	at e.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:55287)
	at e.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:57078)
	at e.$acceptDirtyStateChanged (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:348716)
	at e.$acceptModelSaved (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:348499)
	at t.e.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:423958)
	at e._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:280554)
	at e._receiveOneMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:280244)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:279271
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:281190
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:56058
	at e.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:55287)
	at e.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:57078)
	at Socket.<anonymous> (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:28:102495)
	at emitOne (events.js:96:13)
	at Socket.emit (events.js:191:7)

It was fine for a while, stopped working recently (maybe a few days ago?)

TypeError: Cannot match against 'undefined' or 'null'.

Cannot match against 'undefined' or 'null'.: TypeError: Cannot match against 'undefined' or 'null'.
at fs.readFile (C:\Users\admin.vscode-insiders\extensions\capaj.vscode-exports-autocomplete-0.4.9\lib\uses-semi.js:11:38)
at tryToString (fs.js:426:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:413:12)

add project specific moduleResolverRoot option

some people use stuff like babel-plugin-module-resolver with a root set to some dir in the project and they prefer their paths to not start with ./. For these people, we'll add this options so that you can use this plugin without manually editing the import statement.

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.