@@ -315,28 +315,14 @@ class DottyLanguageServer extends LanguageServer
315
315
316
316
val pos = sourcePosition(driver, uri, params.getPosition)
317
317
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
318
-
319
- // Find definitions of the symbol under the cursor, so that we can determine
320
- // what projects are worth exploring
321
- val definitions = Interactive .findDefinitions(path, driver)
322
- val projectsToInspect = projectsSeeing(definitions)
323
-
324
318
val originalSymbol = Interactive .enclosingSourceSymbol(path)
325
319
val symbolName = originalSymbol.name.sourceModuleName.toString
326
- val references = {
327
- // Collect the information necessary to look into each project separately: representation of
328
- // `originalSymbol` in this project, the context and correct Driver.
329
- val perProjectInfo = projectsToInspect.toList.map { config =>
330
- val remoteDriver = drivers(config)
331
- val ctx = remoteDriver.currentCtx
332
- val definition = Interactive .localize(originalSymbol, driver, remoteDriver)
333
- (remoteDriver, ctx, definition)
334
- }
320
+ val definitions = Interactive .findDefinitions(path, driver)
321
+ val projectsInfo = inProjectsSeeing(driver, definitions, originalSymbol)
335
322
336
- perProjectInfo.par.flatMap { (remoteDriver, ctx, definition) =>
337
- val trees = remoteDriver.sourceTreesContaining(symbolName)(ctx)
338
- Interactive .findTreesMatching(trees, includes, definition)(ctx)
339
- }
323
+ val references = projectsInfo.par.flatMap { (driver, ctx, symbol) =>
324
+ val trees = driver.sourceTreesContaining(symbolName)(ctx)
325
+ Interactive .findTreesMatching(trees, includes, symbol)(ctx)
340
326
}.toList
341
327
342
328
references.flatMap(ref => location(ref.namePos, positionMapperFor(ref.source))).asJava
@@ -440,23 +426,15 @@ class DottyLanguageServer extends LanguageServer
440
426
val pos = sourcePosition(driver, uri, params.getPosition)
441
427
val uriTrees = driver.openedTrees(uri)
442
428
val path = Interactive .pathTo(uriTrees, pos)
443
-
444
429
val definitions = Interactive .findDefinitions(path, driver)
445
- val projectsToInspect = projectsSeeing(definitions)
446
-
447
430
val originalSymbol = Interactive .enclosingSourceSymbol(path)
448
- val implementations = {
449
- val perProjectInfo = projectsToInspect.toList.map { config =>
450
- val remoteDriver = drivers(config)
451
- val ctx = remoteDriver.currentCtx
452
- val definition = Interactive .localize(originalSymbol, driver, remoteDriver)
453
- (remoteDriver, ctx, definition)
454
- }
431
+ val projectsInfo = inProjectsSeeing(driver, definitions, originalSymbol)
455
432
456
- perProjectInfo.par.flatMap { (remoteDriver, ctx, definition) =>
457
- val trees = remoteDriver.sourceTrees(ctx)
458
- Interactive .namedTrees(trees, includeReferences = false , Interactive .isImplementation(definition)(ctx))(ctx)
459
- }
433
+ val implementations = projectsInfo.par.flatMap { (driver, ctx, symbol) =>
434
+ val trees = driver.sourceTrees(ctx)
435
+ Interactive .namedTrees(trees,
436
+ includeReferences = false ,
437
+ Interactive .isImplementation(symbol)(ctx))(ctx)
460
438
}.toList
461
439
462
440
implementations.flatMap { impl =>
@@ -478,6 +456,12 @@ class DottyLanguageServer extends LanguageServer
478
456
override def resolveCompletionItem (params : CompletionItem ) = null
479
457
override def signatureHelp (params : TextDocumentPositionParams ) = null
480
458
459
+ /**
460
+ * Find the set of projects that have any of `definitions` on their classpath.
461
+ *
462
+ * @param definitions The definitions to consider when looking for projects.
463
+ * @return The set of projects that have any of `definitions` on their classpath.
464
+ */
481
465
private def projectsSeeing (definitions : List [SourceTree ])(implicit ctx : Context ): Set [ProjectConfig ] = {
482
466
if (definitions.isEmpty) {
483
467
drivers.keySet
@@ -491,6 +475,28 @@ class DottyLanguageServer extends LanguageServer
491
475
}
492
476
}
493
477
478
+ /**
479
+ * Finds projects that can see any of `definitions`, translate `symbol` in their universe.
480
+ *
481
+ * @param baseDriver The driver responsible for the trees in `definitions` and `symbol`.
482
+ * @param definitions The definitions to consider when looking for projects.
483
+ * @param symbol A symbol to translate in the universes of the remote projects.
484
+ * @return A list consisting of the remote drivers, their context, and the translation of `symbol`
485
+ * into their universe.
486
+ */
487
+ private def inProjectsSeeing (baseDriver : InteractiveDriver ,
488
+ definitions : List [SourceTree ],
489
+ symbol : Symbol ): List [(InteractiveDriver , Context , Symbol )] = {
490
+ val projects = projectsSeeing(definitions)(baseDriver.currentCtx)
491
+ projects.toList.map { config =>
492
+ val remoteDriver = drivers(config)
493
+ val ctx = remoteDriver.currentCtx
494
+ val definition = Interactive .localize(symbol, baseDriver, remoteDriver)
495
+ (remoteDriver, ctx, definition)
496
+ }
497
+ }
498
+
499
+
494
500
}
495
501
496
502
object DottyLanguageServer {
0 commit comments