@@ -315,28 +315,14 @@ class DottyLanguageServer extends LanguageServer
315315
316316 val pos = sourcePosition(driver, uri, params.getPosition)
317317 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-
324318 val originalSymbol = Interactive .enclosingSourceSymbol(path)
325319 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)
335322
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)
340326 }.toList
341327
342328 references.flatMap(ref => location(ref.namePos, positionMapperFor(ref.source))).asJava
@@ -440,23 +426,15 @@ class DottyLanguageServer extends LanguageServer
440426 val pos = sourcePosition(driver, uri, params.getPosition)
441427 val uriTrees = driver.openedTrees(uri)
442428 val path = Interactive .pathTo(uriTrees, pos)
443-
444429 val definitions = Interactive .findDefinitions(path, driver)
445- val projectsToInspect = projectsSeeing(definitions)
446-
447430 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)
455432
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)
460438 }.toList
461439
462440 implementations.flatMap { impl =>
@@ -478,6 +456,12 @@ class DottyLanguageServer extends LanguageServer
478456 override def resolveCompletionItem (params : CompletionItem ) = null
479457 override def signatureHelp (params : TextDocumentPositionParams ) = null
480458
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+ */
481465 private def projectsSeeing (definitions : List [SourceTree ])(implicit ctx : Context ): Set [ProjectConfig ] = {
482466 if (definitions.isEmpty) {
483467 drivers.keySet
@@ -491,6 +475,28 @@ class DottyLanguageServer extends LanguageServer
491475 }
492476 }
493477
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+
494500}
495501
496502object DottyLanguageServer {
0 commit comments