eclipse-typescript
eclipse-typescript copied to clipboard
Organize imports
Would be a killer feature! Although I suppose it is quite a lot of work.
Interesting idea - how would you organize them? Check for unused ones and then sort them alphabetically? Might not be as hard as you think actually - please feel free to submit a pull request.
Well, yeah, like in Java. Ctrl/Cmd+Shift+O and it tries to find matches for currently missing classes (not sure if you can efficiently tell a missing "symbol" from a "class"). If it finds multiple definitions, then a dialog pops out. Sorting can be arbitrary.
Yup - makes sense, I'm just not sure how well some of those concepts translate over to TypeScript.
The organize imports of java do several things:
- Remove unused imports
- Resolve and add missing imports from "Not found" errors
- Normalize and sort imports (depending on settings)
The main difference with java is that imports are named
import myDependencyName = require("dependency/path");
So
- "Remove unused imports" is even easier than in java
- "Normalize and sort imports" could also be provided with some associated settings (like for example sorting alphabetically, transforming relative imports to absolute ones:
require("siblingDependency")=>require("path/to/siblingDependency") - "Resolve and add missing imports from Not found errors" is maybe harder but could be done easier assuming a naming pattern (like for example dependency name = file name)
The "resolving and add missing imports" process would be:
- Find all "Could not find symbol" errors
- Foreach errors, list typescript files having the same name than the symbol name (class or variable)
- If there is more than one match, either skip (easier to implement) or prompt for the file to import (better)
- generate import line at the top of the file
And yes, It would be a killed feature ! Additionally it could also be done automatically on save, like for Java
The biggest problem right now is that the language services have a bug that makes it impossible to detect unused imports: https://typescript.codeplex.com/workitem/2526
Any progress on this? It would be really nice if we could at least "Resolve and add missing imports from "Not found" errors" since that is the biggest pain point right now when using CommonJS style imports.
Sorry, no progress - I haven't had much time to work on this recently. If you'd like to take a look at implementing this feature we'd love to have the PR.