I'm using VSCode and trying to correct the way imports are written across multiple files in my project to a more performant format - does VSCode have functionality that would facilitate this? Could it be done with the built-in find and replace? Or is some other VSCode feature able to do this?
The imports I've got look like this (substance-ux
is an obfuscated version of a real module name, as I don't want module specific answers):
import { Foo, Bar as BarBar } from '@substance-ux/glyphs';
Or maybe:
import {
GlyphWithLongName as LongName,
GlyphWithExtraLongName as ExtraLong
} from '@substance-ux/glyphs';
And I need to convert it into this style, matching imports elsewhere in our project:
import Foo from '@substance-ux/glyphs/Foo';
import BarBar from '@substance-ux/glyphs/Bar';
Or this:
import LongName from '@substance-ux/glyphs/GlyphWithLongName';
import ExtraLong from '@substance-ux/glyphs/GlyphWithExtraLongName';
(As an aside, the files like '@substance-ux/glyphs/GlyphWithExtraLongName'
already exist and the docs for the package say that the @substance-ux/glyphs
module runs a lot of code on import, which slows down development builds.)
Now if I know I have one format or the other, or I know how many then I'm ok to rely on find and replace, e.g. I can use a bit of regex (find: import \{ (.*), (.*) } from '(@substance-ux/glyphs)';
replace import $1 from '$3/$1';\nimport $2 from '$3/$2';
) and the Find and Replace feature in VSCode.
But if I have variable number of imports, or mixed style (some 'as' some not) I become completely unstuck, if I try to do this in one go.
I know snippets can do regex capture and some clever replacing using TextMate syntax, but I don't think they can handle variable number of capture groups? Or can they?
Is this possible in VSCode without extensions etc?