Skip to content

Commit a486832

Browse files
committed
Fix namedTrees with substring search
This functin used to produce a string representation of the whole tree and then look whether this contains the substring we're looking for. When we're not including references in the search, we can limit the search to the trees names rather than their whole representation.
1 parent 397cbf6 commit a486832

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ object Interactive {
269269
* @param includeReferences If true, include references and not just definitions
270270
*/
271271
def namedTrees(trees: List[SourceTree], includeReferences: Boolean, nameSubstring: String)
272-
(implicit ctx: Context): List[SourceTree] =
273-
namedTrees(trees, includeReferences, _.show.toString.contains(nameSubstring))
272+
(implicit ctx: Context): List[SourceTree] = {
273+
val predicate: NameTree => Boolean =
274+
if (includeReferences) _.show.contains(nameSubstring)
275+
else _.name.toString.contains(nameSubstring)
276+
namedTrees(trees, includeReferences, predicate)
277+
}
274278

275279
/** Find named trees with a non-empty position satisfying `treePredicate` in `trees`.
276280
*

0 commit comments

Comments
 (0)