Skip to content

Commit a7da42c

Browse files
authored
chore: Improve completions when a lot of exports are present (#23414)
It seems .sourceSymbol would end up traversing a lot of trees in that case, which is highly inefficient I also added a try for cases such as scalameta/metals#7573 Fixes scalameta/metals#7573
2 parents 5f50490 + b148260 commit a7da42c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ object Completion:
324324
* 8. symbol is not a constructor proxy module when in type completion mode
325325
* 9. have same term/type kind as name prefix given so far
326326
*/
327-
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean =
328-
327+
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean = try
329328
lazy val isEnum = sym.is(Enum) ||
330329
(sym.companionClass.exists && sym.companionClass.is(Enum))
331330

332331
sym.exists &&
333332
!sym.isAbsent(canForce = false) &&
334333
!sym.isPrimaryConstructor &&
335-
sym.sourceSymbol.exists &&
334+
// running sourceSymbol on ExportedTerm will force a lot of computation from collectSubTrees
335+
(sym.is(ExportedTerm) || sym.sourceSymbol.exists) &&
336336
(!sym.is(Package) || sym.is(ModuleClass)) &&
337337
!sym.isAllOf(Mutable | Accessor) &&
338338
!sym.isPackageObject &&
@@ -343,6 +343,9 @@ object Completion:
343343
(completionMode.is(Mode.Term) && (sym.isTerm || sym.is(ModuleClass))
344344
|| (completionMode.is(Mode.Type) && (sym.isType || sym.isStableMember)))
345345
)
346+
catch
347+
case NonFatal(ex) =>
348+
false
346349
end isValidCompletionSymbol
347350

348351
given ScopeOrdering(using Context): Ordering[Seq[SingleDenotation]] with

0 commit comments

Comments
 (0)