File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
src/main/scala/scala/async/internal Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -43,20 +43,26 @@ abstract class AsyncBase {
4343 (body : c.Expr [T ])
4444 (execContext : c.Expr [futureSystem.ExecContext ]): c.Expr [futureSystem.Fut [T ]] = {
4545 import c .universe ._
46-
4746 val asyncMacro = AsyncMacro (c, self)
4847
48+ val isPresentationCompiler = asyncMacro.global.forInteractive
49+
4950 val code = asyncMacro.asyncTransform[T ](
5051 body.tree.asInstanceOf [asyncMacro.global.Tree ],
5152 execContext.tree.asInstanceOf [asyncMacro.global.Tree ]
52- )(implicitly[c.WeakTypeTag [T ]].asInstanceOf [asyncMacro.global.WeakTypeTag [T ]]).asInstanceOf [Tree ]
53-
54- // Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges
55- for (t <- code)
56- t.pos = t.pos.makeTransparent
53+ )(implicitly[c.WeakTypeTag [T ]].asInstanceOf [asyncMacro.global.WeakTypeTag [T ]]).asInstanceOf [Tree ]
5754
5855 AsyncUtils .vprintln(s " async state machine transform expands to: \n ${code}" )
59- c.Expr [futureSystem.Fut [T ]](code)
56+ val result = if (isPresentationCompiler) {
57+ asyncMacro.suppressExpansion()
58+ c.macroApplication
59+ } else {
60+ // Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges
61+ for (t <- code)
62+ t.pos = t.pos.makeTransparent
63+ code
64+ }
65+ c.Expr [futureSystem.Fut [T ]](result)
6066 }
6167
6268 protected [async] def awaitMethod (u : Universe )(asyncMacroSymbol : u.Symbol ): u.Symbol = {
Original file line number Diff line number Diff line change @@ -32,4 +32,21 @@ private[async] trait AsyncMacro
3232 lazy val macroPos = macroApplication.pos.makeTransparent
3333 def atMacroPos (t : global.Tree ) = global.atPos(macroPos)(t)
3434
35+ def suppressExpansion () {
36+ // Have your cake : Scala IDE sees original trees and hyperlinking, etc within async blocks "Just Works"
37+ // Eat it too : (domain specific errors like "unsupported use of await"
38+ //
39+ // TODO roll this idea back into scala/scala
40+ def suppress (globalOrAnalzer : Any ) = {
41+ type Suppress = { def suppressMacroExpansion (a : Object ): Object }
42+ globalOrAnalzer.asInstanceOf [Suppress ].suppressMacroExpansion(macroApplication)
43+ }
44+ try {
45+ suppress(global) // 2.10.x
46+ } catch {
47+ case _ : NoSuchMethodException =>
48+ suppress(global.analyzer) // 2.11
49+ }
50+ }
51+
3552}
Original file line number Diff line number Diff line change @@ -203,6 +203,7 @@ private[async] trait TransformUtils {
203203
204204 abstract class MacroTypingTransformer extends TypingTransformer (callSiteTyper.context.unit) {
205205 currentOwner = callSiteTyper.context.owner
206+ curTree = EmptyTree
206207
207208 def currOwner : Symbol = currentOwner
208209
You can’t perform that action at this time.
0 commit comments