5

I've got a few snippets set up and working as I would like to, but I'm having a hard time getting one snippet to work where I believe I will need to have multiple transforms occur?

Essentially I have a TypeScript Interface defined for one of my components.

i.e. IRadioButtonListProps.ts which is inside of an Interfaces folder. The Interfaces folder has a sibling folder named Theme containing an interface named IRadioButtonListTheme.ts

Inside of IRadioButtonListProps I'm trying to stub out the entire interface. The snippet I currently have stubs out the interface like...

import * as React from 'react';
import IRadioButtonListPropsTheme from '../Theme/IRadioButtonListPropsTheme';
export interface IRadioButtonListPropsProps {
 ...props...
}
export default IRadioButtonListPropsProps;

The import line inside of the snippet is...

"import I${TM_FILENAME_BASE/(.*)\\..+$/1ドル/}Props from './Interfaces/I${TM_FILENAME_BASE/(.*)\\..+$/1ドル/}Props';"

What I'm trying to have happen and can't seem to figure out is how to also remove the word "Props". So instead of import IRadioButtonListPropsTheme... I would get import import IRadioButtonListTheme....

At the same time, I want to remove all extensions, including those of the form *.abc.abc ("two" extensions) and *.abc (one simple extension).

Is this possible?

Mark
191k32 gold badges555 silver badges577 bronze badges
asked Oct 11, 2018 at 21:20
4
  • What is (.*)\\..+$ supposed to match? Commented Oct 11, 2018 at 21:25
  • code.visualstudio.com/docs/editor/… This removes the extension from the file name if there is one. Commented Oct 11, 2018 at 21:27
  • Try changing (.*)\\..+$ to (.*?)(?:Props)?\\.[^.]+$ Commented Oct 11, 2018 at 21:35
  • That didn't break like what I was attempting, but it also didn't change the output. Commented Oct 11, 2018 at 21:58

1 Answer 1

2

It isn't crystal clear what you what but try:

"import ${TM_FILENAME/((\\w*)Props)*?(\\..*)/2ドル/}Theme from './Interfaces/${TM_FILENAME/((\\w*)Props)*?(\\..*)/2ドル/}Theme';"

which results in:

import IRadioButtonListTheme from './Interfaces/IRadioButtonListTheme';

from IRadioButtonListProps.ts and

import CheckboxListTheme from './Interfaces/CheckboxListTheme';

from CheckboxListProps.test.tsx

[Edit] Here is a simpler version which I think also works:

 "import ${TM_FILENAME/(Props)*?(\\..*)//}Theme from './Interfaces/${TM_FILENAME/(Props)*?(\\..*)//}Theme';"
  1. match any "Props", if any, replace with nothing.
  2. match from first \. to end of filename, replace with nothing.
answered Oct 11, 2018 at 22:26
Sign up to request clarification or add additional context in comments.

7 Comments

This did remove the word Props, but stopped ensuring that there wasn't an extension. Some of the snippets are used on test files named similar to CheckboxList.test.tsx. I was using the TM_FILENAME_BASE to remove the .tsx and then the existing transform to remove .test
So one of your intentions is to remove anything after and including the first . (dot)? What should running the snippet on CheckboxList.test.tsx produce for the import statement?
CheckboxList.test.tsx and CheckboxListProps.test.tsx should both produce CheckboxList (as far as the transform is concerned).
I edited the answer above to address your multiple extension cae scenarios as well.
Any chance you could include a transform to grab the last directory in a path produced by TM_DIRECTORY? i.e. c:\a\b\c\d\e would produce e
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.