@@ -305,33 +305,38 @@ class DottyLanguageServer extends LanguageServer
305
305
override def references (params : ReferenceParams ) = computeAsync { cancelToken =>
306
306
val uri = new URI (params.getTextDocument.getUri)
307
307
val driver = driverFor(uri)
308
- implicit val ctx = driver.currentCtx
309
308
310
309
val includes = {
311
310
val includeDeclaration = params.getContext.isIncludeDeclaration
312
311
Include .references | Include .overriding | (if (includeDeclaration) Include .definitions else 0 )
313
312
}
314
313
315
314
val pos = sourcePosition(driver, uri, params.getPosition)
316
- val path = Interactive .pathTo(driver.openedTrees(uri), pos)
317
315
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
+ }
332
339
333
- val originalSymbol = Interactive .enclosingSourceSymbol(path)
334
- val symbolName = originalSymbol.name.sourceModuleName.toString
335
340
val references = {
336
341
// Collect the information necessary to look into each project separately: representation of
337
342
// `originalSymbol` in this project, the context and correct Driver.
@@ -343,12 +348,13 @@ class DottyLanguageServer extends LanguageServer
343
348
}
344
349
345
350
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)))
348
354
}
349
355
}.toList
350
356
351
- references.flatMap(ref => location(ref.namePos, positionMapperFor(ref.source))) .asJava
357
+ references.flatten .asJava
352
358
}
353
359
354
360
override def rename (params : RenameParams ) = computeAsync { cancelToken =>
0 commit comments