gpt4 book ai didi

scala - 如何在任何代码点查看所有可用的隐式及其类型?

转载 作者:行者123 更新时间:2023-12-04 12:16:04 26 4
gpt4 key购买 nike

我正在进行 Scala Play 项目迁移,由于积累了许多隐式,因此在代码中的不同点(例如,在 Play Controller 的 Action 中)找出可用的隐式变量及其类型成为一项艰巨的任务。在委托(delegate)给 View 之前,即

@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's Ctrl+Shift+Alt++ 启用隐式提示,但遗憾的是它只显示函数所需的隐式参数,而不是可用的隐式。例如,我想知道是否有 lang: Lang隐式可用及其类型,因为我正在处理一个 Play 混合 Java 和 Scala 项目,这 lang可以变成 play.i18n.Lang 类型对于前者和 play.api.i18n.Lang为以后。

最佳答案

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

InteliJ implicits

另请检查 page有关使用隐式的更多提示。

关于scala - 如何在任何代码点查看所有可用的隐式及其类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56037038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com