Scala REPL 无法自动完成来自隐式转换的方法 [英] Scala REPL fails to autocomplete methods that comes from implicit conversion

查看:60
本文介绍了Scala REPL 无法自动完成来自隐式转换的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用 Scala 2.10 REPL(交互式 Scala shell)编写:

if I write in scala 2.10 REPL (interactive Scala shell):

 """\w""".

然后按 TAB 它给了我:

+                     asInstanceOf          charAt                   
codePointAt           codePointBefore        
codePointCount        compareTo             compareToIgnoreCase       
concat                contains              ....

但是,缺少 .r.当我将相同的字符串放入 eclipse 时,它​​也会为我提供 .r.如果我之前插入 import scala.util.matching._ 也是如此.为什么 REPL 没有提供所有的可能性?

However, .r is missing. When I put the same string into eclipse, it offers me .r as well. The same is true if I insert import scala.util.matching._ before. Why REPL is not offering all possibilities?

如果我尝试使用 unicode,REPL 会遇到更大的问题,例如我写:

Even bigger problem REPL has if i try to work with unicode, e.g. I write:

"""\p{L}""".

然后按TAB它给了我错误:

scala> """\p{L}""".<console>:1: error: unclosed multi-line string literal
"""
^

同样,它在 Eclipse 中运行良好.

Again, it works fine in Eclipse.

REPL 是不是有很多问题,还是我遗漏了什么?

Is REPL so buggy, or am I missing something?

推荐答案

REPL 只显示对象的字段和方法,而 .r 只能通过隐式转换(augmentStringscala.Predef) 将其转换为 StringOps.除了需要实施并且没有人能够做到这一点之外,可能没有理由这样做.当然,您仍然可以对此调用 .r.

The REPL only displays fields and methods of the object, while .r is only available through an implicit conversion (augmentString in scala.Predef) which turns it into a StringOps. There is probably no reason for this besides the fact that it would need to be implemented and nobody got around to doing it. You can still call .r on this, of course.

Scala IDE 足够智能,可以解析隐式,这就是为什么你可以在那里看到它.

The Scala IDE is smart enough to resolve implicits, which is why you can see it there.

这篇关于Scala REPL 无法自动完成来自隐式转换的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆