Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see all the implicits and their types available at any code point?

I'm working on a Scala Play project migration and due to the many implicits accumulated it becomes a daunting task to figure out the available implicit variables and their types at different points in the code, for example, within a Play Controller's Action and right before delegating to a view i.e.

@Singleton
class Application @Inject() (implicit
                             val verifier: RecaptchaVerifier,
                             config: Configuration,
                             env: Environment,
                             mat: Materializer,
                             indexView: views.html.index,
                             restrictedView: views.html.restricted,
                             profileView: views.html.profile,
                             loginView: views.html.login,
                             restrictedForbidCookieView: views.html.restricted_forbid_cookie,
                             reloginView: views.html.relogin,
                             googleAuthenticationView: views.html.google_authentication,
                             signupView: views.html.signup,
                             widgetHelper: WidgetHelper,
                             webJarUtil: WebJarsUtil,
                             deadbolt: DeadboltActions,
                             auth: PlayAuthenticate,
                             userService: UserService,
                             authProvider: MyAuthProvider,
                             formContext: FormContext,
                             googleAuthService: GoogleAuthService,
                             recaptchaWidget: recaptcha.recaptchaWidget) extends InjectedController with I18nSupport {
  import scala.concurrent._
  import ExecutionContext.Implicits.global

  //-------------------------------------------------------------------
  // public
  //-------------------------------------------------------------------
  def index =
    TryCookieAuthAction { implicit jContext =>
      deadbolt.WithAuthRequest()() { implicit request =>
        Future {
          implicit val lang = request.acceptLanguages.head
          Ok(indexView(userService))
        }
      }
    }

I'm aware of Idea's Ctrl+Shift+Alt++ to enable implicit hints but sadly it only shows the implicit arguments required by a function and not the implicits available. For example, I'd like to know whether there is a lang: Lang implicit available and its type as I'm working on a Play mixed Java & Scala project, this lang could turn to be of type play.i18n.Lang for the former and play.api.i18n.Lang for the later.

like image 313
SkyWalker Avatar asked May 08 '19 08:05

SkyWalker


Video Answer


1 Answers

What you're looking for is probably ctrl + shift + P. You need to hover over place, that needs implicit and then press that combination. It even shows you if you've got conflicting implicits:

InteliJ implicits

Please also check that page for more tips for working with implicits.

like image 117
Krzysztof Atłasik Avatar answered Oct 18 '22 18:10

Krzysztof Atłasik