@@ -8,6 +8,7 @@ import scala.collection._
88import ast .{NavigateAST , Trees , tpd , untpd }
99import core ._ , core .Decorators .{sourcePos => _ , _ }
1010import Contexts ._ , Flags ._ , Names ._ , NameOps ._ , Symbols ._ , Trees ._ , Types ._
11+ import transform .SymUtils .decorateSymbol
1112import util .Positions ._ , util .SourceFile , util .SourcePosition
1213import core .Denotations .SingleDenotation
1314import NameKinds .SimpleNameKind
@@ -33,6 +34,7 @@ object Interactive {
3334 def isDefinitions : Boolean = (bits & definitions.bits) != 0
3435 def isLinkedClass : Boolean = (bits & linkedClass.bits) != 0
3536 def isImports : Boolean = (bits & imports.bits) != 0
37+ def isLocal : Boolean = (bits & local.bits) != 0
3638 }
3739
3840 /** The empty set */
@@ -59,6 +61,9 @@ object Interactive {
5961 /** Include imports in the results */
6062 val imports : Set = Set (1 << 5 )
6163
64+ /** Include local symbols, inspect local trees */
65+ val local : Set = Set (1 << 6 )
66+
6267 /** All the flags */
6368 val all : Set = Set (~ 0 )
6469 }
@@ -327,23 +332,29 @@ object Interactive {
327332
328333 def traverser (source : SourceFile ) = {
329334 new untpd.TreeTraverser {
335+ private def handle (utree : untpd.NameTree ): Unit = {
336+ val tree = utree.asInstanceOf [tpd.NameTree ]
337+ if (tree.symbol.exists
338+ && ! tree.symbol.is(Synthetic )
339+ && ! tree.symbol.isPrimaryConstructor
340+ && tree.pos.exists
341+ && ! tree.pos.isZeroExtent
342+ && (include.isReferences || isDefinition(tree))
343+ && treePredicate(tree))
344+ buf += SourceTree (tree, source)
345+ }
330346 override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
331347 tree match {
332348 case imp : untpd.Import if include.isImports && tree.hasType =>
333349 val tree = imp.asInstanceOf [tpd.Import ]
334350 val selections = tpd.importSelections(tree)
335351 traverse(imp.expr)
336352 selections.foreach(traverse)
353+ case utree : untpd.ValOrDefDef if tree.hasType =>
354+ handle(utree)
355+ if (include.isLocal) traverseChildren(tree)
337356 case utree : untpd.NameTree if tree.hasType =>
338- val tree = utree.asInstanceOf [tpd.NameTree ]
339- if (tree.symbol.exists
340- && ! tree.symbol.is(Synthetic )
341- && ! tree.symbol.isPrimaryConstructor
342- && tree.pos.exists
343- && ! tree.pos.isZeroExtent
344- && (include.isReferences || isDefinition(tree))
345- && treePredicate(tree))
346- buf += SourceTree (tree, source)
357+ handle(utree)
347358 traverseChildren(tree)
348359 case tree : untpd.Inlined =>
349360 traverse(tree.call)
@@ -474,6 +485,7 @@ object Interactive {
474485 def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
475486 enclosingSourceSymbols(path, pos).flatMap { sym =>
476487 val enclTree = enclosingTree(path)
488+ val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
477489
478490 val (trees, include) =
479491 if (enclTree.isInstanceOf [MemberDef ])
@@ -492,7 +504,7 @@ object Interactive {
492504 (Nil , Include .empty)
493505 }
494506
495- findTreesMatching(trees, include, sym)
507+ findTreesMatching(trees, include | includeLocal , sym)
496508 }
497509 }
498510
0 commit comments