首页 > 解决方案 > 如何在任何代码点查看所有可用的隐式及其类型?

问题描述

Action我正在处理 Scala Play 项目迁移,由于积累了许多隐式,因此在代码中的不同点(例如,在 Play Controller 中和委派之前)找出可用的隐式变量及其类型成为一项艰巨的任务到一个视图,即

@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))
        }
      }
    }

我知道Idea 的 Ctrl++启用Shift隐式提示,但遗憾的是它只显示函数所需的隐式参数,而不是可用的隐式。例如,我想知道是否存在隐式可用及其类型,因为我正在处理 Play 混合 Java 和 Scala 项目,这可能会变成前者和后者的类型。Alt+lang: Langlangplay.i18n.Langplay.api.i18n.Lang

标签: scalaintellij-ideaplayframework

解决方案


您正在寻找的可能是ctrl++ 。您需要将鼠标悬停在需要隐式的地方,然后按下该组合。它甚至会告诉你是否有冲突的隐含:shiftP

InteliJ 隐含

另请查看该页面以获取有关使用隐式的更多提示。


推荐阅读