@@ -314,29 +314,20 @@ class DottyLanguageServer extends LanguageServer
314314
315315 val pos = sourcePosition(driver, uri, params.getPosition)
316316
317- val (definitions, projectsToInspect, originalSymbol, originalSymbolName) = {
317+ val (definitions, originalSymbol, originalSymbolName) = {
318318 implicit val ctx : Context = driver.currentCtx
319319 val path = Interactive .pathTo(driver.openedTrees(uri), pos)
320320 val originalSymbol = Interactive .enclosingSourceSymbol(path)
321321 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
325322 val definitions = Interactive .findDefinitions(path, driver)
326- val projectsToInspect = projectsSeeing(definitions)
327323
328- (definitions, projectsToInspect, originalSymbol, originalSymbolName)
324+ (definitions, originalSymbol, originalSymbolName)
329325 }
330326
331327 val references = {
332328 // Collect the information necessary to look into each project separately: representation of
333329 // `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)
340331
341332 perProjectInfo.flatMap { (remoteDriver, ctx, definition) =>
342333 val trees = remoteDriver.sourceTreesContaining(originalSymbolName)(ctx)
@@ -444,26 +435,16 @@ class DottyLanguageServer extends LanguageServer
444435
445436 val pos = sourcePosition(driver, uri, params.getPosition)
446437
447- val (definitions, projectsToInspect, originalSymbol) = {
438+ val (definitions, originalSymbol) = {
448439 implicit val ctx : Context = driver.currentCtx
449440 val path = Interactive .pathTo(driver.openedTrees(uri), pos)
450441 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
454442 val definitions = Interactive .findDefinitions(path, driver)
455- val projectsToInspect = projectsSeeing(definitions)
456-
457- (definitions, projectsToInspect, originalSymbol)
443+ (definitions, originalSymbol)
458444 }
459445
460446 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)
467448
468449 perProjectInfo.flatMap { (remoteDriver, ctx, definition) =>
469450 val trees = remoteDriver.sourceTrees(ctx)
@@ -490,6 +471,12 @@ class DottyLanguageServer extends LanguageServer
490471 override def resolveCompletionItem (params : CompletionItem ) = null
491472 override def signatureHelp (params : TextDocumentPositionParams ) = null
492473
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+ */
493480 private def projectsSeeing (definitions : List [SourceTree ])(implicit ctx : Context ): Set [ProjectConfig ] = {
494481 if (definitions.isEmpty) {
495482 drivers.keySet
@@ -503,6 +490,28 @@ class DottyLanguageServer extends LanguageServer
503490 }
504491 }
505492
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+
506515}
507516
508517object DottyLanguageServer {
0 commit comments