@@ -43,10 +43,7 @@ object Interactive {
43
43
/** Include trees whose symbol is overridden by `sym` */
44
44
val overridden : Set = Set (1 << 0 )
45
45
46
- /**
47
- * Include trees whose symbol overrides `sym` (but for performance only in same source
48
- * file)
49
- */
46
+ /** Include trees whose symbol overrides `sym` */
50
47
val overriding : Set = Set (1 << 1 )
51
48
52
49
/** Include references */
@@ -328,34 +325,45 @@ object Interactive {
328
325
path.find(_.isInstanceOf [DefTree ]).getOrElse(EmptyTree )
329
326
330
327
/**
331
- * Find the definitions of the symbol at the end of `path`.
328
+ * Find the definitions of the symbol at the end of `path`. In the case of an import node,
329
+ * all imported symbols will be considered.
332
330
*
333
331
* @param path The path to the symbol for which we want the definitions.
334
332
* @param driver The driver responsible for `path`.
335
333
* @return The definitions for the symbol at the end of `path`.
336
334
*/
337
- def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
338
- enclosingSourceSymbols(path, pos).flatMap { sym =>
339
- val enclTree = enclosingTree(path)
340
- val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
341
-
342
- val (trees, include) =
343
- if (enclTree.isInstanceOf [MemberDef ])
344
- (driver.allTreesContaining(sym.name.sourceModuleName.toString),
345
- Include .definitions | Include .overriding | Include .overridden)
346
- else sym.topLevelClass match {
347
- case cls : ClassSymbol =>
348
- val trees = Option (cls.sourceFile).flatMap(InteractiveDriver .toUriOption) match {
349
- case Some (uri) if driver.openedTrees.contains(uri) =>
350
- driver.openedTrees(uri)
351
- case _ => // Symbol comes from the classpath
352
- SourceTree .fromSymbol(cls).toList
353
- }
354
- (trees, Include .definitions | Include .overriding)
355
- case _ =>
356
- (Nil , Include .empty)
357
- }
335
+ def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver ): List [SourceTree ] = {
336
+ implicit val ctx = driver.currentCtx
337
+ val enclTree = enclosingTree(path)
338
+ val includeOverridden = enclTree.isInstanceOf [MemberDef ]
339
+ val symbols = enclosingSourceSymbols(path, pos)
340
+ val includeExternal = symbols.exists(! _.isLocal)
341
+ findDefinitions(symbols, driver, includeOverridden, includeExternal)
342
+ }
358
343
344
+ /**
345
+ * Find the definitions of `symbols`.
346
+ *
347
+ * @param symbols The list of symbols for which to find a definition.
348
+ * @param driver The driver responsible for the given symbols.
349
+ * @param includeOverridden If true, also include the symbols overridden by any of `symbols`.
350
+ * @param includeExternal If true, also look for definitions on the classpath.
351
+ * @return The definitions for the symbols in `symbols`, and if `includeOverridden` is set, the
352
+ * definitions for the symbols that they override.
353
+ */
354
+ def findDefinitions (symbols : List [Symbol ],
355
+ driver : InteractiveDriver ,
356
+ includeOverridden : Boolean ,
357
+ includeExternal : Boolean ): List [SourceTree ] = {
358
+ implicit val ctx = driver.currentCtx
359
+ val include = Include .definitions | Include .overriding |
360
+ (if (includeOverridden) Include .overridden else Include .empty)
361
+ symbols.flatMap { sym =>
362
+ val name = sym.name.sourceModuleName.toString
363
+ val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
364
+ val trees =
365
+ if (includeExternal) driver.allTreesContaining(name)
366
+ else driver.sourceTreesContaining(name)
359
367
findTreesMatching(trees, include | includeLocal, sym)
360
368
}
361
369
}
0 commit comments