2

I load source into compiler with askReload, and then i try to call askTypeCompletion after . (dot). Completion in first case (method with 2 arguments) is not working, but completion in method call with one arg works as expected.

  val list = Seq(1,2)
  def add(x: Int, y: Int): Int = x + y
  def minusOne(x: Int) = x - 1


  add(list.<completion is not working)
  minusOne(list.<works fine>)

what's interesting is if i have code:

  implicit class OptionW[T](opt: Option[T]) {
    def cata[A](some: T => A, none: A) = opt.map(some) getOrElse none
  }


  Option("").cata(x => x.<not working>)

completion after dot is not working again, but if i type comma after dot and then try again to complete after dot, it works: Option("").cata(x => x.<works!>,) Is it some bug or expected behaviour?

wedens
  • 1,782
  • 14
  • 18
  • What version of Scala are you using? I just tested this with 2.11, and both variants offer completions: https://github.com/retronym/scala/compare/scala:2.11.x...topic/completion?expand=1 – retronym Jul 20 '14 at 15:24
  • @retronym i'm using scala 2.11.1. after some attempts, first problem solved with moving completion position before dot. but i still can't get completion at second case without adding comma. – wedens Jul 20 '14 at 15:53
  • If you can express the issue with a failing test case of the presentation compiler, I can take a look. Just follow the pattern from my commit above and run `ant build; ./test/partest --update-check test/files/presentation/my-test-case` to run the test and produce a check file with the completion list. More docs about writing presentation compiler tests: https://github.com/scala/scala/blob/2.11.x/src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala#L12 – retronym Jul 21 '14 at 08:17
  • @retronym here it is https://github.com/wedens/scala/compare/scala:2.11.x...completion – wedens Jul 21 '14 at 14:05

1 Answers1

1

I've prototyped a change to the compiler to be more fault tolerant of missing arguments.

https://github.com/retronym/scala/commit/c1460f50945a161599d6d454da355ee20aa402b2

Rather than simply bailing out with the "not enough arguments" error, we can also typecheck the given arguments if we have resolved to a single (non-overloaded) method. We need to typecheck the argument x => x.... using the parameter type as the expected type in order to infer the lambda parameter type, and in turn to offer completions.

I've lodged this as an enhancement: https://issues.scala-lang.org/browse/SI-8739

retronym
  • 54,768
  • 12
  • 155
  • 168
  • can you explain me please, why do i need to call completion before dot in method call with incomplete argument list e.g.: `add(list.)` while i can call completion at dot position in any other case e.g.: `minusOne(list.)` `str.` etc. if i change position to position before dot, then it works everywhere except imports: `import scala.` – wedens Jul 24 '14 at 09:51