0

I have a snippet that is not working. this snippet should convert the file name into pascal case then remove the Impl word after implements

"body": [
    "class ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g} implements ${${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}/(Impl)//} {",
    "final ${2:RemoteDataSource} remoteDataSource;",
    "${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}({required this.remoteDataSource});",
    "}"],

Expected Result

class HomeRepositoryImpl implements HomeRepository {
  final HomeDataSource remoteDataSource;
  HomeRepositoryImpl({required this.remoteDataSource});
}

Actual Result

class HomeRepositoryImpl implements ${HomeRepositoryImpl/(Impl)//} {
    final RemoteDataSource remoteDataSource;
    HomeRepositoryImpl({required this.remoteDataSource});
   }
7
  • ${${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}/(Impl)//} - if you were trying to nest a transform inside another transform here - that cannot be done. Commented Feb 4, 2023 at 18:55
  • and what is the solution to achieve that? Commented Feb 4, 2023 at 19:23
  • What is the filename you are starting from? That would be helpful, so everyone starts from the same information. Commented Feb 4, 2023 at 19:57
  • See my comment below the answer - small change to the regex makes it work. Commented Feb 4, 2023 at 20:25
  • what is the original file name Commented Feb 5, 2023 at 22:05

1 Answer 1

3

Capture the possible impl part in the matched regex but don't use it in the replacement and do it case insensitive

    "body": [
      "class ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/} implements ${TM_FILENAME_BASE/(.*?)(impl)?$/${1:/pascalcase}/i} {",
      "final ${2:RemoteDataSource} remoteDataSource;",
      "${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}({required this.remoteDataSource});",
      "}"]

What is the use of all the g? You have no recurring matches.

Edit small modification based on Mark's comment. Match till end of string with $

Edit needed the case insensitive i, based on the given filename.

Sign up to request clarification or add additional context in comments.

4 Comments

result is not what I'm expecting your answer result class HomeRepositoryImpl implements HomeRepositoryImpl { final HomeDataSource remoteDataSource; HomeRepositoryImpl({required this.remoteDataSource}); }
i want it to be like that class HomeRepositoryImpl implements HomeRepository { final HomeDataSource remoteDataSource; HomeRepositoryImpl({required this.remoteDataSource}); }
Try this instead: ${TM_FILENAME_BASE/(.*?)(Impl)?$/${1:/pascalcase}/} for the after the implements part. Note I added $ to the end of the regex to make it work correctly.
still not working

Your Answer

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.