0

I want to write a live template for adding viewmodel in my android project val viewModel: SomeViewModel by viewModels()

I know that you can enter full path to some class, object etc and IDE would be automatically shorten these full paths when using template in your code. This however wouldn't work in this case since viewModels() is an extension function. Is there any alternative way for achieving such live template?

Tried to search if anyone had similar issue, unfortunately didn't find anything useful. One suggested post was about same issue, but no answer there

  • Can you attach code and template? – vanyochek May 05 '23 at 10:32
  • @vanyochek code I want to achieve is `private val viewModel: SomeViewModel by viewModels()`. My issue is that when I use full path to something, it will be shorten and moved to import unless it is an extension. My live template looks like this: `private val viewModel: $viewModelType$ by androidx.fragment.app.Fragment.viewModels()`. It will result in code like this: `private val viewModel: FlowDataViewModel by Fragment.viewModels()`. I somehow need to switch `androidx.fragment.app.Fragment.viewModels()` in my live template with full qualifier of `viewModels()` extension function – Chummer May 08 '23 at 13:34

0 Answers0