Skip to content

Commit 45a15c7

Browse files
committed
Remove Include.renamingImport
1 parent 560b6c0 commit 45a15c7

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`,
@@ -577,35 +576,4 @@ object Interactive {
577576
}
578577
}
579578

580-
/**
581-
* In `enclosing`, find all the references to any of `syms` that have been renamed to `toName`.
582-
*
583-
* If `enclosing` is empty, it means the renaming import was top-level and the whole source file
584-
* should be considered. Otherwise, we can restrict the search to this tree because renaming
585-
* imports are local.
586-
*
587-
* @param toName The name that is set by the renaming.
588-
* @param enclosing The tree that encloses the renaming import, if it exists.
589-
* @param syms The symbols to which we want to find renamed references.
590-
* @param allTrees All the trees in this source file, in case we can't find `enclosing`.
591-
* @param source The sourcefile that where to look for references.
592-
* @return All the references to the symbol under the cursor that are using `toName`.
593-
*/
594-
def findTreesMatchingRenaming(toName: Name,
595-
syms: List[Symbol],
596-
trees: List[SourceTree]
597-
)(implicit ctx: Context): List[SourceNamedTree] = {
598-
599-
val includes =
600-
Include.references | Include.imports | Include.renamingImports
601-
602-
syms.flatMap { sym =>
603-
Interactive.namedTrees(trees,
604-
includes,
605-
tree =>
606-
Interactive.sameName(tree.name, toName) &&
607-
(Interactive.matchSymbol(tree, sym, includes) || Interactive.matchSymbol(tree, sym.linkedClass, includes)))
608-
}
609-
}
610-
611579
}

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

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

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

316315
val uriTrees = driver.openedTrees(uri)
@@ -358,19 +357,25 @@ class DottyLanguageServer extends LanguageServer
358357
path match {
359358
// Selected a renaming in an import node
360359
case Thicket(_ :: (rename: Ident) :: Nil) :: (_: Import) :: rest if rename.pos.contains(pos.pos) =>
361-
Interactive.findTreesMatchingRenaming(rename.name, syms, uriTrees)
360+
val includes = Include.references | Include.linkedClass | Include.imports
361+
syms.flatMap { sym =>
362+
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, rename.name))
363+
}
362364

363365
// Selected a reference that has been renamed
364366
case (nameTree: NameTree) :: rest if Interactive.isRenamed(nameTree) =>
365-
Interactive.findTreesMatchingRenaming(nameTree.name, syms, uriTrees)
367+
val includes = Include.references | Include.linkedClass | Include.imports
368+
syms.flatMap { sym =>
369+
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, nameTree.name))
370+
}
366371

367372
case _ =>
368373
val includes =
369374
Include.references | Include.definitions | Include.linkedClass | Include.overriding | Include.imports
370375

371376
syms.flatMap { sym =>
372377
val trees = driver.allTreesContaining(sym.name.sourceModuleName.toString)
373-
Interactive.findTreesMatching(trees, includes, sym)
378+
Interactive.findTreesMatching(trees, includes, sym, t => Interactive.sameName(t.name, sym.name))
374379
}
375380
}
376381

@@ -393,7 +398,7 @@ class DottyLanguageServer extends LanguageServer
393398
val uriTrees = driver.openedTrees(uri)
394399
val path = Interactive.pathTo(uriTrees, pos)
395400
val syms = Interactive.enclosingSourceSymbols(path, pos)
396-
val includes = Include.definitions | Include.references | Include.imports | Include.renamingImports
401+
val includes = Include.definitions | Include.references | Include.imports
397402

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

0 commit comments

Comments
 (0)