@@ -314,29 +314,20 @@ class DottyLanguageServer extends LanguageServer
314
314
315
315
val pos = sourcePosition(driver, uri, params.getPosition)
316
316
317
- val (definitions, projectsToInspect, originalSymbol, originalSymbolName) = {
317
+ val (definitions, originalSymbol, originalSymbolName) = {
318
318
implicit val ctx : Context = driver.currentCtx
319
319
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
320
320
val originalSymbol = Interactive .enclosingSourceSymbol(path)
321
321
val originalSymbolName = originalSymbol.name.sourceModuleName.toString
322
-
323
- // Find definitions of the symbol under the cursor, so that we can determine
324
- // what projects are worth exploring
325
322
val definitions = Interactive .findDefinitions(path, driver)
326
- val projectsToInspect = projectsSeeing(definitions)
327
323
328
- (definitions, projectsToInspect, originalSymbol, originalSymbolName)
324
+ (definitions, originalSymbol, originalSymbolName)
329
325
}
330
326
331
327
val references = {
332
328
// Collect the information necessary to look into each project separately: representation of
333
329
// `originalSymbol` in this project, the context and correct Driver.
334
- val perProjectInfo = projectsToInspect.toList.map { config =>
335
- val remoteDriver = drivers(config)
336
- val ctx = remoteDriver.currentCtx
337
- val definition = Interactive .localize(originalSymbol, driver, remoteDriver)
338
- (remoteDriver, ctx, definition)
339
- }
330
+ val perProjectInfo = inProjectsSeeing(driver, definitions, originalSymbol)
340
331
341
332
perProjectInfo.flatMap { (remoteDriver, ctx, definition) =>
342
333
val trees = remoteDriver.sourceTreesContaining(originalSymbolName)(ctx)
@@ -444,26 +435,16 @@ class DottyLanguageServer extends LanguageServer
444
435
445
436
val pos = sourcePosition(driver, uri, params.getPosition)
446
437
447
- val (definitions, projectsToInspect, originalSymbol) = {
438
+ val (definitions, originalSymbol) = {
448
439
implicit val ctx : Context = driver.currentCtx
449
440
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
450
441
val originalSymbol = Interactive .enclosingSourceSymbol(path)
451
-
452
- // Find definitions of the symbol under the cursor, so that we can determine what projects are
453
- // worth exploring
454
442
val definitions = Interactive .findDefinitions(path, driver)
455
- val projectsToInspect = projectsSeeing(definitions)
456
-
457
- (definitions, projectsToInspect, originalSymbol)
443
+ (definitions, originalSymbol)
458
444
}
459
445
460
446
val implementations = {
461
- val perProjectInfo = projectsToInspect.toList.map { config =>
462
- val remoteDriver = drivers(config)
463
- val ctx = remoteDriver.currentCtx
464
- val definition = Interactive .localize(originalSymbol, driver, remoteDriver)
465
- (remoteDriver, ctx, definition)
466
- }
447
+ val perProjectInfo = inProjectsSeeing(driver, definitions, originalSymbol)
467
448
468
449
perProjectInfo.flatMap { (remoteDriver, ctx, definition) =>
469
450
val trees = remoteDriver.sourceTrees(ctx)
@@ -490,6 +471,12 @@ class DottyLanguageServer extends LanguageServer
490
471
override def resolveCompletionItem (params : CompletionItem ) = null
491
472
override def signatureHelp (params : TextDocumentPositionParams ) = null
492
473
474
+ /**
475
+ * Find the set of projects that have any of `definitions` on their classpath.
476
+ *
477
+ * @param definitions The definitions to consider when looking for projects.
478
+ * @return The set of projects that have any of `definitions` on their classpath.
479
+ */
493
480
private def projectsSeeing (definitions : List [SourceTree ])(implicit ctx : Context ): Set [ProjectConfig ] = {
494
481
if (definitions.isEmpty) {
495
482
drivers.keySet
@@ -503,6 +490,28 @@ class DottyLanguageServer extends LanguageServer
503
490
}
504
491
}
505
492
493
+ /**
494
+ * Finds projects that can see any of `definitions`, translate `symbol` in their universe.
495
+ *
496
+ * @param baseDriver The driver responsible for the trees in `definitions` and `symbol`.
497
+ * @param definitions The definitions to consider when looking for projects.
498
+ * @param symbol A symbol to translate in the universes of the remote projects.
499
+ * @return A list consisting of the remote drivers, their context, and the translation of `symbol`
500
+ * into their universe.
501
+ */
502
+ private def inProjectsSeeing (baseDriver : InteractiveDriver ,
503
+ definitions : List [SourceTree ],
504
+ symbol : Symbol ): List [(InteractiveDriver , Context , Symbol )] = {
505
+ val projects = projectsSeeing(definitions)(baseDriver.currentCtx)
506
+ projects.toList.map { config =>
507
+ val remoteDriver = drivers(config)
508
+ val ctx = remoteDriver.currentCtx
509
+ val definition = Interactive .localize(symbol, baseDriver, remoteDriver)
510
+ (remoteDriver, ctx, definition)
511
+ }
512
+ }
513
+
514
+
506
515
}
507
516
508
517
object DottyLanguageServer {
0 commit comments