Skip to content

Commit 59275a8

Browse files
committed
Remove Include.renamingImport
1 parent eefcb59 commit 59275a8

File tree

2 files changed

+22
-49
lines changed

2 files changed

+22
-49
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ object Interactive {
2929
val definitions: Int = 8 // include definitions
3030
val linkedClass: Int = 16 // include `symbol.linkedClass`
3131
val imports: Int = 32 // include imports in the results
32-
val renamingImports: Int = 64 // Include renamed symbols and renaming part of imports in the results
3332
}
3433

3534
/** Does this tree define a symbol ? */
@@ -302,7 +301,6 @@ object Interactive {
302301
(implicit ctx: Context): List[SourceNamedTree] = safely {
303302
val includeReferences = (include & Include.references) != 0
304303
val includeImports = (include & Include.imports) != 0
305-
val includeRenamingImports = (include & Include.renamingImports) != 0
306304
val buf = new mutable.ListBuffer[SourceNamedTree]
307305

308306
def traverser(source: SourceFile) = {
@@ -340,30 +338,31 @@ object Interactive {
340338
/**
341339
* Find trees that match `symbol` in `trees`.
342340
*
343-
* @param trees The trees to inspect.
344-
* @param includes Whether to include references, definitions, etc.
345-
* @param symbol The symbol for which we want to find references.
341+
* @param trees The trees to inspect.
342+
* @param includes Whether to include references, definitions, etc.
343+
* @param symbol The symbol for which we want to find references.
344+
* @param predicate An additional predicate that the trees must match.
346345
*/
347346
def findTreesMatching(trees: List[SourceTree],
348347
includes: Include.Set,
349-
symbol: Symbol)(implicit ctx: Context): List[SourceNamedTree] = {
348+
symbol: Symbol,
349+
predicate: NameTree => Boolean = util.common.alwaysTrue
350+
)(implicit ctx: Context): List[SourceNamedTree] = {
350351
val linkedSym = symbol.linkedClass
351352
val includeDeclaration = (includes & Include.definitions) != 0
352353
val includeLinkedClass = (includes & Include.linkedClass) != 0
353-
val includeRenamingImports = (includes & Include.renamingImports) != 0
354-
val predicate: NameTree => Boolean = tree =>
354+
val fullPredicate: NameTree => Boolean = tree =>
355355
( !tree.symbol.isPrimaryConstructor
356356
&& (includeDeclaration || !Interactive.isDefinition(tree))
357-
&& (includeRenamingImports || !isRenamed(tree))
358357
&& ( Interactive.matchSymbol(tree, symbol, includes)
359-
|| ( includeDeclaration
360-
&& includeLinkedClass
358+
|| ( includeLinkedClass
361359
&& linkedSym.exists
362360
&& Interactive.matchSymbol(tree, linkedSym, includes)
363361
)
364362
)
363+
&& predicate(tree)
365364
)
366-
namedTrees(trees, includes, predicate)
365+
namedTrees(trees, includes, fullPredicate)
367366
}
368367

369368
/** The reverse path to the node that closest encloses position `pos`,
@@ -555,35 +554,4 @@ object Interactive {
555554
}
556555
}
557556

558-
/**
559-
* In `enclosing`, find all the references to any of `syms` that have been renamed to `toName`.
560-
*
561-
* If `enclosing` is empty, it means the renaming import was top-level and the whole source file
562-
* should be considered. Otherwise, we can restrict the search to this tree because renaming
563-
* imports are local.
564-
*
565-
* @param toName The name that is set by the renaming.
566-
* @param enclosing The tree that encloses the renaming import, if it exists.
567-
* @param syms The symbols to which we want to find renamed references.
568-
* @param allTrees All the trees in this source file, in case we can't find `enclosing`.
569-
* @param source The sourcefile that where to look for references.
570-
* @return All the references to the symbol under the cursor that are using `toName`.
571-
*/
572-
def findTreesMatchingRenaming(toName: Name,
573-
syms: List[Symbol],
574-
trees: List[SourceTree]
575-
)(implicit ctx: Context): List[SourceNamedTree] = {
576-
577-
val includes =
578-
Include.references | Include.imports | Include.renamingImports
579-
580-
syms.flatMap { sym =>
581-
Interactive.namedTrees(trees,
582-
includes,
583-
tree =>
584-
Interactive.sameName(tree.name, toName) &&
585-
(Interactive.matchSymbol(tree, sym, includes) || Interactive.matchSymbol(tree, sym.linkedClass, includes)))
586-
}
587-
}
588-
589557
}

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ class DottyLanguageServer extends LanguageServer
308308

309309
val includes = {
310310
val includeDeclaration = params.getContext.isIncludeDeclaration
311-
Include.references | Include.overriding | Include.imports | Include.renamingImports |
312-
(if (includeDeclaration) Include.definitions else 0)
311+
Include.references | Include.overriding | Include.imports | (if (includeDeclaration) Include.definitions else 0)
313312
}
314313

315314
val uriTrees = driver.openedTrees(uri)
@@ -376,19 +375,25 @@ class DottyLanguageServer extends LanguageServer
376375
path match {
377376
// Selected a renaming in an import node
378377
case Thicket(_ :: (rename: Ident) :: Nil) :: (_: Import) :: rest if rename.pos.contains(pos.pos) =>
379-
Interactive.findTreesMatchingRenaming(rename.name, syms, uriTrees)
378+
val includes = Include.references | Include.linkedClass | Include.imports
379+
syms.flatMap { sym =>
380+
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, rename.name))
381+
}
380382

381383
// Selected a reference that has been renamed
382384
case (nameTree: NameTree) :: rest if Interactive.isRenamed(nameTree) =>
383-
Interactive.findTreesMatchingRenaming(nameTree.name, syms, uriTrees)
385+
val includes = Include.references | Include.linkedClass | Include.imports
386+
syms.flatMap { sym =>
387+
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, nameTree.name))
388+
}
384389

385390
case _ =>
386391
val includes =
387392
Include.references | Include.definitions | Include.linkedClass | Include.overriding | Include.imports
388393

389394
syms.flatMap { sym =>
390395
val trees = driver.allTreesContaining(sym.name.sourceModuleName.toString)
391-
Interactive.findTreesMatching(trees, includes, sym)
396+
Interactive.findTreesMatching(trees, includes, sym, t => Interactive.sameName(t.name, sym.name))
392397
}
393398
}
394399

@@ -411,7 +416,7 @@ class DottyLanguageServer extends LanguageServer
411416
val uriTrees = driver.openedTrees(uri)
412417
val path = Interactive.pathTo(uriTrees, pos)
413418
val syms = Interactive.enclosingSourceSymbols(path, pos)
414-
val includes = Include.definitions | Include.references | Include.imports | Include.renamingImports
419+
val includes = Include.definitions | Include.references | Include.imports
415420

416421
syms.flatMap { sym =>
417422
val refs = Interactive.findTreesMatching(uriTrees, includes, sym)

0 commit comments

Comments
 (0)