Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
Feature/awesome import manager (#210)
Browse files Browse the repository at this point in the history
* add schema for setting

* adding classes for import grouping

* change interface

* add barrel file

* change from yarn lock to npm5

* change commands

* change prepare release script

* update travis script

* rename folder

* correct escaping

* adding first impl for module improts

* tests and code for keyword import group

* adding regex import group

* add remain import group

* adding settings parser and error for not matching ones

* add setting parser tests

* add remain grp to default

* change ignore file

* remove more stuff from extension

* code st yle, export type

* add more sofisticated info

* adding import settings

* do not cache (because of the array)

* add remain grp if no is specified, adding back some tests

* upgrade deps

* refactor add imports

* deps

* adding method to add import groups

* adding reset to groups

* adding organize tests for group

* remove \n from import ts gen

* try to generate code

* correctly generating organized imports

* comment

* changelog

* remove "newImportLocation"

* add sortedImports property

* generate the correct imports at the correct places (imp mgmt)

* add remaining as keyword and parsing for it

* changelog

* refactor code completion to use import manager

* adding stringtemplate func and multiline comma import

* fix tests

* update tests & code style

* fix bug and change the tests to new import groups

* improve performance for code completion

* documentation

* rename commands

* readme

* explained old ver

* upgrade dependencies

* Revert "upgrade dependencies"

This reverts commit b652bea.

* package log

* upgrade tslint (npm 5)

* code style

* Fix/upgrade vscode deps (#212)

* upgrade packages

* upgrade vscode.d.ts

* TS 2.3.4

* refactoring undefined stuff

* ts errors

* fix undefiend

* fixing build errors
  • Loading branch information
buehler authored Jun 15, 2017
1 parent df98216 commit 57ee9a0
Show file tree
Hide file tree
Showing 52 changed files with 5,098 additions and 3,302 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ sudo: false

language: node_js
node_js:
- '7'
- '8'

env:
global:
- CODE_TESTS_WORKSPACE=$TRAVIS_BUILD_DIR/test/_workspace
- secure: ZFxa817TgXMaJc/zC0PUHFqPt4aSXJxuMAXpsthyZyCMC0M2HAyZH14fDf8o7LX24q90EO6eAn3/JRhHWyQK9MygM4wW3J5mTc4Hm/2sJpqmDgmwHaoa1jZSxf7bykb1dPvkdgR15U0Xd0vtmMVR0gY7yQ6pcRVUPO6TNceCsu6p1nUfPGBDjLAKAa5wdJhaxOmfKjoIyT36jrJ2U5lCs7YtYuJGSgu4wHBnVsNjZIYyA8cF6FNMYYe/lRTheCz9vE0IYlmXT5aPEQL2kWZRGyWZOzBbtQXI+5XVqlKNbao4l15K62BvKuBu70bOa9Hxz7nR2ycwcfcpdxiJeDbOYwF5zsXVYY633p3SngPrkKBOww6gqbkMDEN6dqkT7clSZzqHnlL/o35b8LKNwdO9pxqU5YFALFHMSms5zJpTo3TAz4wxlb6TZCJlk+9Y4QaE3JqwTRxfk0Xw79w6N6eQXY2qq0zmL4MMyu3Q0KTCRAYX9CoWEbDD4WanWrLyXTkQbkNO7rZ+nSbS7CmEnt4Zs8AlLqdtsdf93cw7LcDotWnLQ+Fj+hUnApivSJkcQCFpqaJqFJcUutkn70ziqPe3b/BZZtHsbc1Dvda2GLl9gR9jFh61wrlk2WM/Q5kr+BVfT5RtKMSXRrEasEjz15tS0EQMP1k7VXjGMV4P1b57i4A=

os:
#- osx
- linux

addons:
Expand All @@ -35,11 +34,13 @@ before_install:
fi

install:
- yarn install
- yarn run build
- npm install

before_script:
- npm run build

script:
- yarn test --silent
- npm test --silent

deploy:
provider: script
Expand Down
15 changes: 9 additions & 6 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.github/**
.vscode/**
.vscode-test/**
typings/**
out/test/**

.gitignore
package-lock.json
prepare-release.js

config/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
tslint.json
typings.json

*.vsix
_workspace/**
out/test/**
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
#### Added
- Import grouping, imports are now grouped and sorted (read the docs in README) ([#102](https://github.com/buehler/typescript-hero/issues/102))
- Option to add a trailing comma to a multiline import (at the last import) ([#100](https://github.com/buehler/typescript-hero/issues/100))

#### Changed
- Multiline import statement threshold to a new default value `125`, since github thinks this is a good value [source-code-line-length](http://hilton.org.uk/blog/source-code-line-length)

#### Removed
- `newImportLocation` setting, since the imports are grouped and sorted, the new import location is obsolete ([#102](https://github.com/buehler/typescript-hero/issues/102))

#### Fixed
- Default imports are removed regardless if they are used or not ([#149](https://github.com/buehler/typescript-hero/issues/149))
- Support for generic interfaces and abstract classes for the implement elements feature of the light bulb ([#158](https://github.com/buehler/typescript-hero/issues/158))
Expand Down
91 changes: 88 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ All commands are preceeded by `typescriptHero`.

| Command | Extension part | Description |
| ---------------------------- | --------------- | --------------------------------------------------------- |
| showCmdGui | general | Shows a small gui with all available internal commands |
| resolve.addImport | import resolver | Shows a pick list with all recognized, importable symbols |
| resolve.addImportUnderCursor | import resolver | Imports the symbol under the cursor |
| resolve.addMissingImports | import resolver | Imports all missing symbols for the actual document |
Expand Down Expand Up @@ -74,13 +73,14 @@ The following settings do have the prefix `resolver`. So an example setting coul

| Setting | Description |
| ------------------------------------- | ------------------------------------------------------------------------------------ |
| stringQuoteStyle | The string delimiter to use for the imports |
| stringQuoteStyle | The string delimiter to use for the imports (`'` or `"`) |
| ignorePatterns | If any of these strings is part of a file path, the file is ignored |
| insertSpaceBeforeAndAfterImportBraces | If the extension should place spaces into import braces (`{Symbol}` vs `{ Symbol }`) |
| insertSemicolons | If the extension should add a semicolon to the end of a statement |
| multiLineWrapThreshold | The threshold, when imports are converted into multiline imports |
| newImportLocation | The location of new imports (at the top of the file, or at the cursor location) |
| multiLineTrailingComma | When multiline imports are created, `true` inserts a trailing comma to the last line |
| disableImportSorting | Disable sorting during organize imports action |
| importGroups | The groups that are used for sorting the imports (description below) |

## Features (extended)

Expand All @@ -93,6 +93,91 @@ TypeScript Hero can manage your imports. It is capable of:
- Import all missing identifiers of the current file
- Remove unused imports and sort the remaining ones by alphabet

#### Import groups

The import groups setting allows you to order all your imports as you may want. The settings is an array of elements.
An element can either be a string (with a certain keyword or a regex like string) or an object that contains an
identifier (with a certain keyword or a regex like string) and a sort order. The order you enter those objects / string
does matter since it is used to define the import groups.

An example (complex) could be:

```json
[
"Plains",
"/@angular/",
{
"identifier": "/Foo[1-9]Bar/",
"order": "desc"
},
"Workspace",
{
"identifier": "Remaining",
"order": "desc"
}
]
```

##### Keyword imports

- `Modules` : contains all imports from modules (npm etc) `import ... from 'vscode';`
- `Plains` : contains all string only imports `import 'reflect-metadata;`
- `Workspace` : contains all local project files `import ... from '../server';`
- `Remaining` : contains all imports that are not matched by other import groups

(_hint_: The `Remaining` group is added implicitly as the last import group if not added specifically)

The default is as follows:

```json
[
"Plains",
"Modules",
"Workspace"
]
```

For everybody that just wants all imports ordered in asc or desc, just overwrite the default with:

For all imports sorted asc:
```json
[]
```

For all imports sorted desc:
```json
[
{
"identifier": "Remaining",
"order": "desc"
}
]
```

##### Regex imports

The regex import group contains a regex string. Let's say you want to group all your `@angular` namespaced imports together
in one group you'd use `/@angular/` as "identifier" (either in the object when you want to change the order or just
the plain regex since default order is `asc`).

(_hint_: only the name of the library is matched against the regex)

```json
[
"/@angular/"
]
```

The setting above would create two groups: one with all @angular imports another with all other imports.

```typescript
import {http} from '@angular/http';
import {component} from '@angular/core';

import 'reflect-metadata';
import {Server} from './server';
```

### Intellisense

Intellisense is a common IDE feature. TypeScript Hero provides you with symbols as you type your code
Expand Down
Loading

0 comments on commit 57ee9a0

Please sign in to comment.