@@ -305,33 +305,38 @@ class DottyLanguageServer extends LanguageServer
305305 override def references (params : ReferenceParams ) = computeAsync { cancelToken =>
306306 val uri = new URI (params.getTextDocument.getUri)
307307 val driver = driverFor(uri)
308- implicit val ctx = driver.currentCtx
309308
310309 val includes = {
311310 val includeDeclaration = params.getContext.isIncludeDeclaration
312311 Include .references | Include .overriding | (if (includeDeclaration) Include .definitions else 0 )
313312 }
314313
315314 val pos = sourcePosition(driver, uri, params.getPosition)
316- val path = Interactive .pathTo(driver.openedTrees(uri), pos)
317315
318- // Find definitions of the symbol under the cursor, so that we can determine
319- // what projects are worth exploring
320- val definitions = Interactive .findDefinitions(path, driver)
321- val projectsToInspect =
322- if (definitions.isEmpty) {
323- drivers.keySet
324- } else {
325- for {
326- definition <- definitions
327- uri <- toUriOption(definition.pos.source).toSet
328- config = configFor(uri)
329- project <- dependentProjects(config) + config
330- } yield project
331- }
316+ val (definitions, projectsToInspect, originalSymbol, originalSymbolName) = {
317+ implicit val ctx : Context = driver.currentCtx
318+ val path = Interactive .pathTo(driver.openedTrees(uri), pos)
319+ val originalSymbol = Interactive .enclosingSourceSymbol(path)
320+ val originalSymbolName = originalSymbol.name.sourceModuleName.toString
321+
322+ // Find definitions of the symbol under the cursor, so that we can determine
323+ // what projects are worth exploring
324+ val definitions = Interactive .findDefinitions(path, driver)
325+ val projectsToInspect =
326+ if (definitions.isEmpty) {
327+ drivers.keySet
328+ } else {
329+ for {
330+ definition <- definitions
331+ uri <- toUriOption(definition.pos.source).toSet
332+ config = configFor(uri)
333+ project <- dependentProjects(config) + config
334+ } yield project
335+ }
336+
337+ (definitions, projectsToInspect, originalSymbol, originalSymbolName)
338+ }
332339
333- val originalSymbol = Interactive .enclosingSourceSymbol(path)
334- val symbolName = originalSymbol.name.sourceModuleName.toString
335340 val references = {
336341 // Collect the information necessary to look into each project separately: representation of
337342 // `originalSymbol` in this project, the context and correct Driver.
@@ -343,12 +348,13 @@ class DottyLanguageServer extends LanguageServer
343348 }
344349
345350 perProjectInfo.flatMap { (remoteDriver, ctx, definition) =>
346- val trees = remoteDriver.sourceTreesContaining(symbolName)(ctx)
347- Interactive .findTreesMatching(trees, includes, definition)(ctx)
351+ val trees = remoteDriver.sourceTreesContaining(originalSymbolName)(ctx)
352+ val matches = Interactive .findTreesMatching(trees, includes, definition)(ctx)
353+ matches.map(tree => location(tree.namePos(ctx), positionMapperFor(tree.source)))
348354 }
349355 }.toList
350356
351- references.flatMap(ref => location(ref.namePos, positionMapperFor(ref.source))) .asJava
357+ references.flatten .asJava
352358 }
353359
354360 override def rename (params : RenameParams ) = computeAsync { cancelToken =>
0 commit comments