_From @nikolay-borzov on May 22, 2018 12:37_
Usually imports are organized in groups separated by empty line (e.g. node packages, services, components). I think that organizeImports should respect existing groups and perform organizing within each group.
Steps to Reproduce:
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
source.organizeImports": true
}
.ts fileimport path from 'path'
import fs from 'fs'
const currentDir = path.resolve(__dirname)
const data = fs.readdirSync(currentDir)
Press Ctrl+S
Result:
import fs from 'fs'
import path from 'path'
const currentDir = path.resolve(__dirname)
const data = fs.readdirSync(currentDir)
Does this issue occur when all extensions are disabled?: Yes (Disabled TSLint and Prettier)
_Copied from original issue: Microsoft/vscode#50277_
looks like a duplicate of https://github.com/Microsoft/TypeScript/issues/22914
I believe #22914 tracks removing the newlines while this issue is about preserving the newlines and the import groups they define
ah. sorry misread the issue. thanks.
I do not think this is something we can easily accomplish, since the imports themselves move, and some even are completely removed with their contents merged into other imports; it is not clear how we can figure out what is a group and what is not in the midst of these transformations.
Agreed. Given the work required, unless there are many users requesting this, this kind of more advanced sorting seems like a better fit for an extension
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
I have to disable source.organizeImports for the same reason.
Most helpful comment
I have to disable
source.organizeImportsfor the same reason.