This page is no longer maintained — Please continue to the home page at www.scala-lang.org

CompilerControl - askCompletion

No replies
Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.

Hi All,

I'm trying to fiddle with the trunk eclipse plugin (2.8.0), in
particular to get code completion working again. I'm finding it
particularly hit and miss when using askCompletion. Is there a magic
sauce to make it work reliably?

In particular either I get an assertion:

java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:92)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3476)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:3755)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:3797)
at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$2.apply(Analyzer.scala:80)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:312)
at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:328)
at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:328)
at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:102)
at scala.tools.nsc.interactive.Global$TyperRun.applyPhase(Global.scala:328)
at scala.tools.nsc.interactive.Global$TyperRun.typeCheck(Global.scala:297)
at scala.tools.nsc.interactive.Global$TyperRun.typedTreeAt(Global.scala:313)
at scala.tools.nsc.interactive.Global.typedTreeAt(Global.scala:223)
at scala.tools.nsc.interactive.Global$$anonfun$completion$1.apply(Global.scala:241)
at scala.tools.nsc.interactive.Global$$anonfun$completion$1.apply(Global.scala:240)
at scala.tools.nsc.interactive.Global.respond(Global.scala:194)
at scala.tools.nsc.interactive.Global.completion(Global.scala:240)
at scala.tools.nsc.interactive.CompilerControl$$anonfun$askCompletion$1.apply(CompilerControl.scala:57)
at scala.tools.nsc.interactive.CompilerControl$$anonfun$askCompletion$1.apply(CompilerControl.scala:57)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:98)
at scala.tools.nsc.interactive.Global$$anon$2.run(Global.scala:120)ERROR:
java.lang.AssertionError: assertion failed

or I get members for the base any types (!= == asInstanceOf etc)

or I get the List((value
,,CompilerControl.ValueSet(CompilerControl(0),
CompilerControl(1)))) --- Mostly when I try to complete a given
token such as isDefined (isDefi ).

and seemingly randomly I get the actual members belonging to the
Symbol under ctrl-space, i.e. I actually get what I want (just can't
reproduce this reliably).

code wise its:

val th = scu.getTreeHolder
import th._

val bsf = new BatchSourceFile(scu.aFile) // or indeed scu.getSourceFile
val pos = compiler.rangePos(bsf, offset , offset, offset)

val tree = compiler.locateTree(pos)

val members = new compiler.Response[List[compiler.Member]]
compiler.askCompletion(pos, members)
show(members)

and usually tree is the right part (but it will rarely type either).

As to the why.. I could simply wait for Miles to get this sorted out
after he returns, but I'd like to be able to start contributing (#2033
was an easy start), unfortunately the biggest hinderences for me are
the lack of code completion, navigation and debugging (i.e. somewhat
like the plugin used to have before the simplification :-).
Additionally I have a twisted dream about embedding the REPL into an
osgi container and exposing it via a web interface, but thats way down
the line.

cheers,
Chris

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland